From 89d72a1208145a775c7489a0f02a8dff11bd9582 Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Mon, 16 Dec 2019 12:18:03 -0800 Subject: [PATCH] Throwing when goldctl cannot authorize/initialize (#45925) --- .../test/flutter_goldens_test.dart | 100 +++++++++++++++--- .../lib/skia_client.dart | 14 ++- 2 files changed, 96 insertions(+), 18 deletions(-) diff --git a/packages/flutter_goldens/test/flutter_goldens_test.dart b/packages/flutter_goldens/test/flutter_goldens_test.dart index 1bf7ead215..0a54a0aa39 100644 --- a/packages/flutter_goldens/test/flutter_goldens_test.dart +++ b/packages/flutter_goldens/test/flutter_goldens_test.dart @@ -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 - .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 + .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: { + '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 + .value(ProcessResult(123, 1, 'fail', 'fail'))); + final Future test = skiaClient.auth(); + + expect( + test, + throwsException, + ); + }); + + test(' throws for error state from init', () { + platform = FakePlatform( + environment: { + 'FLUTTER_ROOT': _kFlutterRoot, + 'GOLDCTL' : 'goldctl', + }, + operatingSystem: 'macos' + ); + + skiaClient = SkiaGoldClient( + workDirectory, + fs: fs, + process: process, + platform: platform, + httpClient: mockHttpClient, + ); + + when(process.run( + ['git', 'rev-parse', 'HEAD'], + workingDirectory: '/flutter', + )).thenAnswer((_) => Future + .value(ProcessResult(12345678, 0, '12345678', ''))); + + when(process.run( + [ + 'goldctl', + 'imgtest', 'init', + '--instance', 'flutter', + '--work-dir', '/workDirectory/temp', + '--commit', '12345678', + '--keys-file', '/workDirectory/keys.json', + '--failure-file', '/workDirectory/failures.json', + '--passfail', + ], + )).thenAnswer((_) => Future + .value(ProcessResult(123, 1, 'fail', 'fail'))); + final Future test = skiaClient.imgtestInit(); + + expect( + test, + throwsException, + ); }); group('Request Handling', () { diff --git a/packages/flutter_goldens_client/lib/skia_client.dart b/packages/flutter_goldens_client/lib/skia_client.dart index 50a832e575..f930fb91ce 100644 --- a/packages/flutter_goldens_client/lib/skia_client.dart +++ b/packages/flutter_goldens_client/lib/skia_client.dart @@ -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()); } }