diff options
-rw-r--r-- | UnitTests/SPTableCopyTest.m | 70 | ||||
-rw-r--r-- | sequel-pro.xcodeproj/project.pbxproj | 2 |
2 files changed, 42 insertions, 30 deletions
diff --git a/UnitTests/SPTableCopyTest.m b/UnitTests/SPTableCopyTest.m index 76a2fe45..05ab4a76 100644 --- a/UnitTests/SPTableCopyTest.m +++ b/UnitTests/SPTableCopyTest.m @@ -39,52 +39,62 @@ @interface SPTableCopyTest : SenTestCase - (void)testCopyTableFromToWithData; +- (void)testCopyTableFromTo_NoPermissions; @end @implementation SPTableCopyTest -- (id)mockConnection -{ - return [[OCMockObject niceMockForClass:[SPMySQLConnection class]] autorelease]; -} - -- (id)mockResult -{ - return [[OCMockObject niceMockForClass:[SPMySQLResult class]] autorelease]; -} - - (void)testCopyTableFromToWithData { - id mockResult = [self mockResult]; + id mockResult = OCMClassMock([SPMySQLResult class]); - unsigned long long varOne = 1; - NSValue *valueOne = [NSValue value:&varOne withObjCType:@encode(__typeof__(varOne))]; - BOOL varNo = NO; - - NSValue *valueNo = [NSValue value:&varNo withObjCType:@encode(BOOL)]; NSArray *resultArray = [[NSArray alloc] initWithObjects:@"", @"CREATE TABLE `table_name` ()", nil]; - id mockConnection = [self mockConnection]; + id mockConnection = OCMClassMock([SPMySQLConnection class]); - [(SPMySQLResult *)[[mockResult expect] andReturn:valueOne] numberOfRows]; - [[[mockResult expect] andReturn:resultArray] getRowAsArray]; + OCMExpect([mockResult numberOfRows]).andReturn(1); + OCMExpect([mockResult getRowAsArray]).andReturn(resultArray); - [[[mockConnection expect] andReturn:mockResult] queryString:@"SHOW CREATE TABLE `source_db`.`table_name`"]; - [[mockConnection expect] queryString:@"CREATE TABLE `target_db`.`table_name` ()"]; - [[mockConnection expect] queryString:@"INSERT INTO `target_db`.`table_name` SELECT * FROM `source_db`.`table_name`"]; - [[[mockConnection stub] andReturnValue:valueNo] queryErrored]; + OCMExpect([mockConnection queryString:@"SHOW CREATE TABLE `source_db`.`table_name`"]).andReturn(mockResult); + OCMExpect([mockConnection queryString:@"CREATE TABLE `target_db`.`table_name` ()"]); + OCMExpect([mockConnection queryString:@"INSERT INTO `target_db`.`table_name` SELECT * FROM `source_db`.`table_name`"]); + OCMStub([mockConnection queryErrored]).andReturn(NO); - SPTableCopy *tableCopy = [[SPTableCopy alloc] init]; - - [tableCopy setConnection:mockConnection]; - [tableCopy copyTable:@"table_name" from:@"source_db" to:@"target_db" withContent:YES]; + { + SPTableCopy *tableCopy = [[SPTableCopy alloc] init]; + + [tableCopy setConnection:mockConnection]; + [tableCopy copyTable:@"table_name" from:@"source_db" to:@"target_db" withContent:YES]; + + [tableCopy release]; + } - [mockResult verify]; - [mockConnection verify]; + OCMVerifyAll(mockResult); + OCMVerifyAll(mockConnection); - [tableCopy release]; [resultArray release]; } +- (void)testCopyTableFromTo_NoPermissions +{ + id mockConnection = OCMStrictClassMock([SPMySQLConnection class]); + + OCMExpect([mockConnection queryString:@"SHOW CREATE TABLE `source_db`.`table_name`"]).andReturn(nil); + OCMStub([mockConnection queryErrored]).andReturn(YES); + OCMStub([mockConnection lastErrorMessage]).andReturn(@"SHOW command denied to user 'alice'@'localhost' for table 'table_name'"); + OCMStub([mockConnection lastErrorID]).andReturn(1142); + OCMStub([mockConnection lastSqlstate]).andReturn(@"42000"); + + { + SPTableCopy *tableCopy = [[SPTableCopy alloc] init]; + + STAssertFalse([tableCopy copyTable:@"table_name" from:@"source_db" to:@"target_db"],@"copy operation must fail."); + + [tableCopy release]; + } + + [mockConnection verify]; +} + @end diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index 1dddeaca..bdd39761 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -190,6 +190,7 @@ 503CDBB21ACDC204004F8A2F /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 503CDBB11ACDC204004F8A2F /* Quartz.framework */; }; 506CE9311A311C6C0039F736 /* SPTableContentFilterController.m in Sources */ = {isa = PBXBuildFile; fileRef = 506CE9301A311C6C0039F736 /* SPTableContentFilterController.m */; }; 507FF1121BBCC57600104523 /* SPFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = 507FF1111BBCC57600104523 /* SPFunctions.m */; }; + 507FF1621BBF0D5000104523 /* SPTableCopyTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 112730551180788A000737FD /* SPTableCopyTest.m */; }; 50A9F8B119EAD4B90053E571 /* SPGotoDatabaseController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50A9F8B019EAD4B90053E571 /* SPGotoDatabaseController.m */; }; 50D3C3491A75B8A800B5429C /* GotoDatabaseDialog.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50D3C34B1A75B8A800B5429C /* GotoDatabaseDialog.xib */; }; 50D3C3521A77135F00B5429C /* SPParserUtils.c in Sources */ = {isa = PBXBuildFile; fileRef = 50D3C3501A77135F00B5429C /* SPParserUtils.c */; }; @@ -3075,6 +3076,7 @@ 503B02D11AE95DD40060CAB1 /* SPTableFilterParser.m in Sources */, 503B02CF1AE95C2C0060CAB1 /* SPTableFilterParserTest.m in Sources */, 50EA92681AB23EFC008D3C4F /* SPTableCopy.m in Sources */, + 507FF1621BBF0D5000104523 /* SPTableCopyTest.m in Sources */, 50EA926A1AB246B8008D3C4F /* SPDatabaseActionTest.m in Sources */, 50EA92651AB23EC8008D3C4F /* SPDatabaseAction.m in Sources */, 50EA92641AB23EAD008D3C4F /* SPDatabaseCopy.m in Sources */, |