[devicelab] Add results path flag to test runner (#72765)
This commit is contained in:
@@ -48,7 +48,7 @@ void main() {
|
||||
_processResult = ProcessResult(1, 0, commitSha, '');
|
||||
cocoon = Cocoon(
|
||||
serviceAccountTokenPath: serviceAccountTokenPath,
|
||||
filesystem: fs,
|
||||
fs: fs,
|
||||
httpClient: mockClient,
|
||||
processRunSync: runSyncStub,
|
||||
);
|
||||
@@ -60,7 +60,7 @@ void main() {
|
||||
_processResult = ProcessResult(1, 1, '', '');
|
||||
cocoon = Cocoon(
|
||||
serviceAccountTokenPath: serviceAccountTokenPath,
|
||||
filesystem: fs,
|
||||
fs: fs,
|
||||
httpClient: mockClient,
|
||||
processRunSync: runSyncStub,
|
||||
);
|
||||
@@ -68,12 +68,69 @@ void main() {
|
||||
expect(() => cocoon.commitSha, throwsA(isA<CocoonException>()));
|
||||
});
|
||||
|
||||
test('writes expected update task json', () async {
|
||||
_processResult = ProcessResult(1, 0, commitSha, '');
|
||||
final TaskResult result = TaskResult.fromJson(<String, dynamic>{
|
||||
'success': true,
|
||||
'data': <String, dynamic>{
|
||||
'i': 0,
|
||||
'j': 0,
|
||||
'not_a_metric': 'something',
|
||||
},
|
||||
'benchmarkScoreKeys': <String>['i', 'j'],
|
||||
});
|
||||
|
||||
cocoon = Cocoon(
|
||||
fs: fs,
|
||||
processRunSync: runSyncStub,
|
||||
);
|
||||
|
||||
const String resultsPath = 'results.json';
|
||||
await cocoon.writeTaskResultToFile(
|
||||
builderName: 'builderAbc',
|
||||
gitBranch: 'master',
|
||||
result: result,
|
||||
resultsPath: resultsPath,
|
||||
);
|
||||
|
||||
final String resultJson = fs.file(resultsPath).readAsStringSync();
|
||||
const String expectedJson = '{'
|
||||
'"CommitBranch":"master",'
|
||||
'"CommitSha":"$commitSha",'
|
||||
'"BuilderName":"builderAbc",'
|
||||
'"NewStatus":"Succeeded",'
|
||||
'"ResultData":{"i":0.0,"j":0.0,"not_a_metric":"something"},'
|
||||
'"BenchmarkScoreKeys":["i","j"]}';
|
||||
expect(resultJson, expectedJson);
|
||||
});
|
||||
|
||||
test('uploads expected update task payload from results file', () async {
|
||||
_processResult = ProcessResult(1, 0, commitSha, '');
|
||||
cocoon = Cocoon(
|
||||
fs: fs,
|
||||
httpClient: mockClient,
|
||||
processRunSync: runSyncStub,
|
||||
serviceAccountTokenPath: serviceAccountTokenPath,
|
||||
);
|
||||
|
||||
const String resultsPath = 'results.json';
|
||||
const String updateTaskJson = '{'
|
||||
'"CommitBranch":"master",'
|
||||
'"CommitSha":"$commitSha",'
|
||||
'"BuilderName":"builderAbc",'
|
||||
'"NewStatus":"Succeeded",'
|
||||
'"ResultData":{"i":0.0,"j":0.0,"not_a_metric":"something"},'
|
||||
'"BenchmarkScoreKeys":["i","j"]}';
|
||||
fs.file(resultsPath).writeAsStringSync(updateTaskJson);
|
||||
await cocoon.sendResultsPath(resultsPath);
|
||||
});
|
||||
|
||||
test('sends expected request from successful task', () async {
|
||||
mockClient = MockClient((Request request) async => Response('{}', 200));
|
||||
|
||||
cocoon = Cocoon(
|
||||
serviceAccountTokenPath: serviceAccountTokenPath,
|
||||
filesystem: fs,
|
||||
fs: fs,
|
||||
httpClient: mockClient,
|
||||
);
|
||||
|
||||
@@ -87,12 +144,13 @@ void main() {
|
||||
|
||||
cocoon = Cocoon(
|
||||
serviceAccountTokenPath: serviceAccountTokenPath,
|
||||
filesystem: fs,
|
||||
fs: fs,
|
||||
httpClient: mockClient,
|
||||
);
|
||||
|
||||
final TaskResult result = TaskResult.success(<String, dynamic>{});
|
||||
expect(() => cocoon.sendTaskResult(builderName: 'builderAbc', gitBranch: 'branchAbc', result: result), throwsA(isA<ClientException>()));
|
||||
expect(() => cocoon.sendTaskResult(builderName: 'builderAbc', gitBranch: 'branchAbc', result: result),
|
||||
throwsA(isA<ClientException>()));
|
||||
});
|
||||
|
||||
test('null git branch throws error', () async {
|
||||
@@ -100,12 +158,13 @@ void main() {
|
||||
|
||||
cocoon = Cocoon(
|
||||
serviceAccountTokenPath: serviceAccountTokenPath,
|
||||
filesystem: fs,
|
||||
fs: fs,
|
||||
httpClient: mockClient,
|
||||
);
|
||||
|
||||
final TaskResult result = TaskResult.success(<String, dynamic>{});
|
||||
expect(() => cocoon.sendTaskResult(builderName: 'builderAbc', gitBranch: null, result: result), throwsA(isA<AssertionError>()));
|
||||
expect(() => cocoon.sendTaskResult(builderName: 'builderAbc', gitBranch: null, result: result),
|
||||
throwsA(isA<AssertionError>()));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user