diff --git a/packages/shorebird_cli/integration_test/helpers.dart b/packages/shorebird_cli/integration_test/helpers.dart new file mode 100644 index 00000000..04140220 --- /dev/null +++ b/packages/shorebird_cli/integration_test/helpers.dart @@ -0,0 +1,24 @@ +import 'dart:io'; + +import 'package:mason_logger/mason_logger.dart'; + +/// Helper function to run a command in the shell, meant to be used in tests. +/// +/// It will take a command string, like `shorebird --version`, run it in the +/// shell, and return the result. +ProcessResult runCommand( + String command, { + required String workingDirectory, + Logger? logger, +}) { + final parts = command.split(' '); + final executable = parts.first; + final arguments = parts.skip(1).toList(); + (logger ?? Logger()).info('running $command in $workingDirectory'); + return Process.runSync( + executable, + arguments, + runInShell: true, + workingDirectory: workingDirectory, + ); +} diff --git a/packages/shorebird_cli/integration_test/shorebird_cli_cache_test.dart b/packages/shorebird_cli/integration_test/shorebird_cli_cache_test.dart new file mode 100644 index 00000000..1e0d0738 --- /dev/null +++ b/packages/shorebird_cli/integration_test/shorebird_cli_cache_test.dart @@ -0,0 +1,36 @@ +import 'package:mason_logger/mason_logger.dart'; +import 'package:scoped_deps/scoped_deps.dart'; +import 'package:shorebird_cli/src/auth/auth.dart'; +import 'package:shorebird_cli/src/http_client/http_client.dart'; +import 'package:shorebird_cli/src/logger.dart'; +import 'package:shorebird_cli/src/platform.dart'; +import 'package:shorebird_cli/src/shorebird_env.dart'; +import 'package:test/test.dart'; + +import 'helpers.dart'; + +R runWithOverrides(R Function() body) { + return runScoped( + body, + values: { + authRef, + httpClientRef, + loggerRef, + platformRef, + shorebirdEnvRef, + }, + ); +} + +void main() { + group('shorebird cache', () { + test('can clear the cache', () { + final result = runCommand( + 'shorebird cache clear', + workingDirectory: '.', + ); + + expect(result.exitCode, equals(ExitCode.success.code)); + }); + }); +} diff --git a/packages/shorebird_cli/integration_test/shorebird_cli_integration_test.dart b/packages/shorebird_cli/integration_test/shorebird_cli_integration_test.dart index 6d9ee24c..fb2c6b0f 100644 --- a/packages/shorebird_cli/integration_test/shorebird_cli_integration_test.dart +++ b/packages/shorebird_cli/integration_test/shorebird_cli_integration_test.dart @@ -16,6 +16,8 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; import 'package:test/test.dart'; import 'package:uuid/uuid.dart'; +import 'helpers.dart'; + R runWithOverrides(R Function() body) { return runScoped( body, @@ -38,22 +40,6 @@ void main() { ), ); - ProcessResult runCommand( - String command, { - required String workingDirectory, - }) { - final parts = command.split(' '); - final executable = parts.first; - final arguments = parts.skip(1).toList(); - logger.info('running $command in $workingDirectory'); - return Process.runSync( - executable, - arguments, - runInShell: true, - workingDirectory: workingDirectory, - ); - } - test('--version', () { final result = runCommand('shorebird --version', workingDirectory: '.'); expect(result.stderr, isEmpty); diff --git a/packages/shorebird_cli/lib/src/cache.dart b/packages/shorebird_cli/lib/src/cache.dart index bee8d80f..a1fb713c 100644 --- a/packages/shorebird_cli/lib/src/cache.dart +++ b/packages/shorebird_cli/lib/src/cache.dart @@ -118,11 +118,9 @@ class Cache { Future clear() async { final cacheDir = shorebirdCacheDirectory; - final logsDirectory = shorebirdEnv.logsDirectory; - await Future.wait([ - if (cacheDir.existsSync()) cacheDir.delete(recursive: true), - if (logsDirectory.existsSync()) logsDirectory.delete(recursive: true), - ]); + if (cacheDir.existsSync()) { + await cacheDir.delete(recursive: true); + } } } diff --git a/packages/shorebird_cli/test/src/cache_test.dart b/packages/shorebird_cli/test/src/cache_test.dart index 37553644..3e60c59e 100644 --- a/packages/shorebird_cli/test/src/cache_test.dart +++ b/packages/shorebird_cli/test/src/cache_test.dart @@ -28,7 +28,6 @@ void main() { late Cache cache; late ChecksumChecker checksumChecker; late Directory shorebirdRoot; - late Directory logsDirectory; late http.Client httpClient; late ShorebirdLogger logger; late Platform platform; @@ -82,7 +81,6 @@ void main() { shorebirdProcess = MockShorebirdProcess(); shorebirdRoot = Directory.systemTemp.createTempSync(); - logsDirectory = Directory.systemTemp.createTempSync(); when( () => artifactManager.extractZip( zipFile: any(named: 'zipFile'), @@ -96,7 +94,6 @@ void main() { () => shorebirdEnv.shorebirdEngineRevision, ).thenReturn(shorebirdEngineRevision); when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot); - when(() => shorebirdEnv.logsDirectory).thenReturn(logsDirectory); when(() => platform.environment).thenReturn({}); setMockPlatform(Platform.macOS); @@ -171,28 +168,18 @@ void main() { final shorebirdCacheDirectory = runWithOverrides( () => Cache.shorebirdCacheDirectory, )..createSync(recursive: true); - final logsDirectory = runWithOverrides( - () => shorebirdEnv.logsDirectory, - )..createSync(recursive: true); expect(shorebirdCacheDirectory.existsSync(), isTrue); - expect(logsDirectory.existsSync(), isTrue); await runWithOverrides(cache.clear); expect(shorebirdCacheDirectory.existsSync(), isFalse); - expect(logsDirectory.existsSync(), isFalse); }); test('does nothing if directory does not exist', () { final shorebirdCacheDirectory = runWithOverrides( () => Cache.shorebirdCacheDirectory, ); - final logsDirectory = runWithOverrides( - () => shorebirdEnv.logsDirectory, - )..deleteSync(recursive: true); expect(shorebirdCacheDirectory.existsSync(), isFalse); - expect(logsDirectory.existsSync(), isFalse); runWithOverrides(cache.clear); expect(shorebirdCacheDirectory.existsSync(), isFalse); - expect(logsDirectory.existsSync(), isFalse); }); });