add --force flag to precache (#31278)

This commit is contained in:
Jonah Williams 2019-04-18 16:04:21 -07:00 committed by GitHub
parent b275e11170
commit f5672b9316
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

@ -13,6 +13,8 @@ class PrecacheCommand extends FlutterCommand {
PrecacheCommand() {
argParser.addFlag('all-platforms', abbr: 'a', negatable: false,
help: 'Precache artifacts for all platforms.');
argParser.addFlag('force', abbr: 'f', negatable: false,
help: 'Force downloading of artifacts.');
argParser.addFlag('android', negatable: true, defaultsTo: true,
help: 'Precache artifacts for Android development');
argParser.addFlag('ios', negatable: true, defaultsTo: true,
@ -55,10 +57,11 @@ class PrecacheCommand extends FlutterCommand {
requiredArtifacts.add(artifact);
}
}
if (cache.isUpToDate()) {
printStatus('Already up-to-date.');
} else {
final bool forceUpdate = argResults['force'];
if (forceUpdate || !cache.isUpToDate()) {
await cache.updateAll(requiredArtifacts);
} else {
printStatus('Already up-to-date.');
}
return null;
}

View File

@ -63,6 +63,23 @@ void main() {
Cache: () => cache,
FlutterVersion: () => flutterVersion,
});
testUsingContext('Downloads artifacts when --force is provided', () async {
when(cache.isUpToDate()).thenReturn(true);
// Release lock between test cases.
Cache.releaseLockEarly();
final PrecacheCommand command = PrecacheCommand();
applyMocksToCommand(command);
await createTestCommandRunner(command).run(const <String>['precache', '--force']);
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal,
DevelopmentArtifact.iOS,
DevelopmentArtifact.android,
}));
}, overrides: <Type, Generator>{
Cache: () => cache,
FlutterVersion: () => flutterVersion,
});
});
}