diff options
author | Max <post@wickenrode.com> | 2015-10-02 21:17:49 +0200 |
---|---|---|
committer | Max <post@wickenrode.com> | 2015-10-02 21:39:43 +0200 |
commit | b72ee56b6cdb5c54ba67107da61b8f0228d36edc (patch) | |
tree | e5b625e239206aba132228057ddf4de1d5e9c48a /UnitTests | |
parent | f38ffcb95896ddf3774d30d0c64d8a57139b4ec6 (diff) | |
download | sequelpro-b72ee56b6cdb5c54ba67107da61b8f0228d36edc.tar.gz sequelpro-b72ee56b6cdb5c54ba67107da61b8f0228d36edc.tar.bz2 sequelpro-b72ee56b6cdb5c54ba67107da61b8f0228d36edc.zip |
Add a unit test someone forgot and clean it up
(Also add a test that will currently fail)
Diffstat (limited to 'UnitTests')
-rw-r--r-- | UnitTests/SPTableCopyTest.m | 70 |
1 files changed, 40 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 |