Fix mocks to return correct expected results.
Reviewed By: lblasa Differential Revision: D48315430 fbshipit-source-id: 3a9210b6c4ce8192ff5489d2616e6a37264309b2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d9b34e7880
commit
d102ae263c
@@ -6,6 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#import "MockDatabaseDriver.h"
|
#import "MockDatabaseDriver.h"
|
||||||
|
#include <Foundation/Foundation.h>
|
||||||
|
#include <objc/NSObjCRuntime.h>
|
||||||
#import "DatabaseExecuteSql.h"
|
#import "DatabaseExecuteSql.h"
|
||||||
#import "DatabaseGetTableData.h"
|
#import "DatabaseGetTableData.h"
|
||||||
#import "DatabaseGetTableInfo.h"
|
#import "DatabaseGetTableInfo.h"
|
||||||
@@ -67,42 +69,55 @@
|
|||||||
count:(NSInteger)count {
|
count:(NSInteger)count {
|
||||||
NSMutableArray* columns = [NSMutableArray array];
|
NSMutableArray* columns = [NSMutableArray array];
|
||||||
NSMutableArray* values = [NSMutableArray array];
|
NSMutableArray* values = [NSMutableArray array];
|
||||||
for (int i = 0; i < 100; i++) {
|
NSUInteger numColums = 10;
|
||||||
|
NSUInteger numRows = 100;
|
||||||
|
for (int i = 0; i < numColums; i++) {
|
||||||
NSString* columnName = [NSString stringWithFormat:@"column%d", i + 1];
|
NSString* columnName = [NSString stringWithFormat:@"column%d", i + 1];
|
||||||
[columns addObject:columnName];
|
[columns addObject:columnName];
|
||||||
NSArray* valueRow = @[ @"value1", @"value2", @"value3" ];
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < numRows; i++) {
|
||||||
|
NSMutableArray* valueRow = [NSMutableArray array];
|
||||||
|
for (int j = 0; j < numColums; j++) {
|
||||||
|
[valueRow addObject:[NSString stringWithFormat:@"value%d", j]];
|
||||||
|
}
|
||||||
[values addObject:valueRow];
|
[values addObject:valueRow];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [[DatabaseGetTableDataResponse alloc] initWithColumns:[columns copy]
|
return [[DatabaseGetTableDataResponse alloc] initWithColumns:[columns copy]
|
||||||
values:[values copy]
|
values:[values copy]
|
||||||
start:0
|
start:0
|
||||||
count:100
|
count:numRows
|
||||||
total:100];
|
total:numRows];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (DatabaseExecuteSqlResponse*)executeSQL:(NSString*)sql {
|
- (DatabaseExecuteSqlResponse*)executeSQL:(NSString*)sql {
|
||||||
// Generate a mock response with a random type
|
// Generate a mock response with a random type
|
||||||
NSString* type;
|
NSString* type;
|
||||||
NSArray* columns = @[ @"id", @"name" ];
|
NSArray* columns = @[ @"id", @"name", @"age" ];
|
||||||
NSMutableArray* values = [NSMutableArray array];
|
NSMutableArray* values = [NSMutableArray array];
|
||||||
for (int i = 0; i < 100; i++) {
|
NSUInteger numRows = 100;
|
||||||
[values addObject:@[ @(i), [NSString stringWithFormat:@"Name %d", i] ]];
|
for (int i = 0; i < numRows; i++) {
|
||||||
|
NSUInteger randomAge = arc4random_uniform(40);
|
||||||
|
[values addObject:@[
|
||||||
|
@(i),
|
||||||
|
[NSString stringWithFormat:@"Name %d", i],
|
||||||
|
@(randomAge)
|
||||||
|
]];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Randomly select a type
|
// Randomly select a type
|
||||||
NSArray<NSString*>* types = @[ @"SELECT", @"INSERT", @"UPDATE", @"DELETE" ];
|
NSArray<NSString*>* types = @[ @"select", @"insert", @"update_delete" ];
|
||||||
int index = arc4random_uniform((u_int32_t)types.count);
|
int index = arc4random_uniform((u_int32_t)types.count);
|
||||||
type = types[index];
|
type = types[index];
|
||||||
|
|
||||||
// Set affectedCount and insertedId based on type
|
// Set affectedCount and insertedId based on type
|
||||||
NSInteger affectedCount = 0;
|
NSInteger affectedCount = 0;
|
||||||
NSNumber* insertedId = nil;
|
NSNumber* insertedId = nil;
|
||||||
if ([type isEqualToString:@"INSERT"]) {
|
if ([type isEqualToString:@"insert"]) {
|
||||||
affectedCount = 1;
|
affectedCount = 1;
|
||||||
insertedId = @(15);
|
insertedId = @(15);
|
||||||
} else if (
|
} else if ([type isEqualToString:@"update_delete"]) {
|
||||||
[type isEqualToString:@"UPDATE"] || [type isEqualToString:@"DELETE"]) {
|
|
||||||
affectedCount = values.count;
|
affectedCount = values.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user