fix: cache clear command was breaking (#2235)
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}
|
||||
@@ -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>(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));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -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>(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);
|
||||
|
||||
@@ -118,11 +118,9 @@ class Cache {
|
||||
|
||||
Future<void> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user