added cleanContext (#93264)
* added cleanContext * using async * added one more test
This commit is contained in:
parent
550281e581
commit
9c1a87e627
@ -49,12 +49,11 @@ class CleanCommand extends Command<void> {
|
|||||||
'This will abort a work in progress release.';
|
'This will abort a work in progress release.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
Future<void> run() {
|
||||||
final ArgResults argumentResults = argResults!;
|
final ArgResults argumentResults = argResults!;
|
||||||
final File stateFile = checkouts.fileSystem.file(argumentResults[kStateOption]);
|
final File stateFile = checkouts.fileSystem.file(argumentResults[kStateOption]);
|
||||||
if (!stateFile.existsSync()) {
|
if (!stateFile.existsSync()) {
|
||||||
throw ConductorException(
|
throw ConductorException('No persistent state file found at ${stateFile.path}!');
|
||||||
'No persistent state file found at ${stateFile.path}!');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(argumentResults[kYesFlag] as bool)) {
|
if (!(argumentResults[kYesFlag] as bool)) {
|
||||||
@ -67,10 +66,28 @@ class CleanCommand extends Command<void> {
|
|||||||
// Only proceed if the first character of stdin is 'y' or 'Y'
|
// Only proceed if the first character of stdin is 'y' or 'Y'
|
||||||
if (response.isEmpty || response[0].toLowerCase() != 'y') {
|
if (response.isEmpty || response[0].toLowerCase() != 'y') {
|
||||||
stdio.printStatus('Aborting clean operation.');
|
stdio.printStatus('Aborting clean operation.');
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stdio.printStatus('Deleting persistent state file ${stateFile.path}...');
|
stdio.printStatus('Deleting persistent state file ${stateFile.path}...');
|
||||||
stateFile.deleteSync();
|
|
||||||
|
final RunContext context = RunContext(
|
||||||
|
stateFile: stateFile,
|
||||||
|
);
|
||||||
|
return context.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Context for cleaning up persistent state file.
|
||||||
|
///
|
||||||
|
/// This is a frontend-agnostic implementation.
|
||||||
|
class RunContext {
|
||||||
|
RunContext({
|
||||||
|
required this.stateFile,
|
||||||
|
});
|
||||||
|
|
||||||
|
final File stateFile;
|
||||||
|
|
||||||
|
Future<void> run() {
|
||||||
|
return stateFile.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ void main() {
|
|||||||
group('clean command', () {
|
group('clean command', () {
|
||||||
const String flutterRoot = '/flutter';
|
const String flutterRoot = '/flutter';
|
||||||
const String checkoutsParentDirectory = '$flutterRoot/dev/tools/';
|
const String checkoutsParentDirectory = '$flutterRoot/dev/tools/';
|
||||||
|
const String stateFilePath = '/state-file.json';
|
||||||
|
|
||||||
late MemoryFileSystem fileSystem;
|
late MemoryFileSystem fileSystem;
|
||||||
late FakePlatform platform;
|
late FakePlatform platform;
|
||||||
@ -47,24 +48,36 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('throws if no state file found', () async {
|
test('throws if no state file found', () async {
|
||||||
const String stateFile = '/state-file.json';
|
|
||||||
|
|
||||||
await expectLater(
|
await expectLater(
|
||||||
() async => runner.run(<String>[
|
() async => runner.run(<String>[
|
||||||
'clean',
|
'clean',
|
||||||
'--$kStateOption',
|
'--$kStateOption',
|
||||||
stateFile,
|
stateFilePath,
|
||||||
'--$kYesFlag',
|
'--$kYesFlag',
|
||||||
]),
|
]),
|
||||||
throwsExceptionWith(
|
throwsExceptionWith(
|
||||||
'No persistent state file found at $stateFile',
|
'No persistent state file found at $stateFilePath',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('deletes state file', () async {
|
test('deletes an empty state file', () async {
|
||||||
final File stateFile = fileSystem.file('/state-file.json');
|
final File stateFile = fileSystem.file(stateFilePath);
|
||||||
stateFile.writeAsStringSync('{}');
|
stateFile.writeAsStringSync('');
|
||||||
|
|
||||||
|
await runner.run(<String>[
|
||||||
|
'clean',
|
||||||
|
'--$kStateOption',
|
||||||
|
stateFile.path,
|
||||||
|
'--$kYesFlag',
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(stateFile.existsSync(), false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('deletes a state file with content', () async {
|
||||||
|
final File stateFile = fileSystem.file(stateFilePath);
|
||||||
|
stateFile.writeAsStringSync('{status: pending}');
|
||||||
|
|
||||||
await runner.run(<String>[
|
await runner.run(<String>[
|
||||||
'clean',
|
'clean',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user