Throwing when goldctl cannot authorize/initialize (#45925)

This commit is contained in:
Kate Lovett
2019-12-16 12:18:03 -08:00
committed by Flutter GitHub Bot
parent fba96809f4
commit 89d72a1208
2 changed files with 96 additions and 18 deletions

View File

@@ -53,9 +53,10 @@ void main() {
group('SkiaGoldClient', () {
SkiaGoldClient skiaClient;
Directory workDirectory;
setUp(() {
final Directory workDirectory = fs.directory('/workDirectory')
workDirectory = fs.directory('/workDirectory')
..createSync(recursive: true);
skiaClient = SkiaGoldClient(
workDirectory,
@@ -66,20 +67,91 @@ void main() {
);
});
group('auth', () {
test('performs minimal work if already authorized', () async {
fs.file('/workDirectory/temp/auth_opt.json')
..createSync(recursive: true);
when(process.run(any))
.thenAnswer((_) => Future<ProcessResult>
.value(ProcessResult(123, 0, '', '')));
await skiaClient.auth();
test('auth performs minimal work if already authorized', () async {
fs.file('/workDirectory/temp/auth_opt.json')
..createSync(recursive: true);
when(process.run(any))
.thenAnswer((_) => Future<ProcessResult>
.value(ProcessResult(123, 0, '', '')));
await skiaClient.auth();
verifyNever(process.run(
captureAny,
workingDirectory: captureAnyNamed('workingDirectory'),
));
});
verifyNever(process.run(
captureAny,
workingDirectory: captureAnyNamed('workingDirectory'),
));
});
test('throws for error state from auth', () async {
platform = FakePlatform(
environment: <String, String>{
'FLUTTER_ROOT': _kFlutterRoot,
'GOLD_SERVICE_ACCOUNT' : 'Service Account',
'GOLDCTL' : 'goldctl',
},
operatingSystem: 'macos'
);
skiaClient = SkiaGoldClient(
workDirectory,
fs: fs,
process: process,
platform: platform,
httpClient: mockHttpClient,
);
when(process.run(any))
.thenAnswer((_) => Future<ProcessResult>
.value(ProcessResult(123, 1, 'fail', 'fail')));
final Future<void> test = skiaClient.auth();
expect(
test,
throwsException,
);
});
test(' throws for error state from init', () {
platform = FakePlatform(
environment: <String, String>{
'FLUTTER_ROOT': _kFlutterRoot,
'GOLDCTL' : 'goldctl',
},
operatingSystem: 'macos'
);
skiaClient = SkiaGoldClient(
workDirectory,
fs: fs,
process: process,
platform: platform,
httpClient: mockHttpClient,
);
when(process.run(
<String>['git', 'rev-parse', 'HEAD'],
workingDirectory: '/flutter',
)).thenAnswer((_) => Future<ProcessResult>
.value(ProcessResult(12345678, 0, '12345678', '')));
when(process.run(
<String>[
'goldctl',
'imgtest', 'init',
'--instance', 'flutter',
'--work-dir', '/workDirectory/temp',
'--commit', '12345678',
'--keys-file', '/workDirectory/keys.json',
'--failure-file', '/workDirectory/failures.json',
'--passfail',
],
)).thenAnswer((_) => Future<ProcessResult>
.value(ProcessResult(123, 1, 'fail', 'fail')));
final Future<void> test = skiaClient.imgtestInit();
expect(
test,
throwsException,
);
});
group('Request Handling', () {

View File

@@ -128,8 +128,11 @@ class SkiaGoldClient {
);
if (result.exitCode != 0) {
print('goldctl auth stdout: ${result.stdout}');
print('goldctl auth stderr: ${result.stderr}');
final StringBuffer buf = StringBuffer()
..writeln('Skia Gold auth failed.')
..writeln('stdout: ${result.stdout}')
..writeln('stderr: ${result.stderr}');
throw NonZeroExitCode(1, buf.toString());
}
}
@@ -170,8 +173,11 @@ class SkiaGoldClient {
);
if (result.exitCode != 0) {
print('goldctl imgtest init stdout: ${result.stdout}');
print('goldctl imgtest init stderr: ${result.stderr}');
final StringBuffer buf = StringBuffer()
..writeln('Skia Gold imgtest init failed.')
..writeln('stdout: ${result.stdout}')
..writeln('stderr: ${result.stderr}');
throw NonZeroExitCode(1, buf.toString());
}
}