Unverified Commit 98cf0185 authored by Dan Field's avatar Dan Field Committed by GitHub

Fetch tags for version command (#52212)

parent bbc5b9d9
...@@ -41,6 +41,7 @@ class VersionCommand extends FlutterCommand { ...@@ -41,6 +41,7 @@ class VersionCommand extends FlutterCommand {
Version minSupportedVersion = Version.parse('1.2.1'); Version minSupportedVersion = Version.parse('1.2.1');
Future<List<String>> getTags() async { Future<List<String>> getTags() async {
globals.flutterVersion.fetchTagsAndUpdate();
RunResult runResult; RunResult runResult;
try { try {
runResult = await processUtils.run( runResult = await processUtils.run(
......
...@@ -23,6 +23,7 @@ import '../../src/mocks.dart' show MockProcess; ...@@ -23,6 +23,7 @@ import '../../src/mocks.dart' show MockProcess;
void main() { void main() {
group('version', () { group('version', () {
MockStdio mockStdio; MockStdio mockStdio;
MockVersion mockVersion;
setUpAll(() { setUpAll(() {
Cache.disableLocking(); Cache.disableLocking();
...@@ -30,6 +31,7 @@ void main() { ...@@ -30,6 +31,7 @@ void main() {
setUp(() { setUp(() {
mockStdio = MockStdio(); mockStdio = MockStdio();
mockVersion = MockVersion();
when(mockStdio.stdinHasTerminal).thenReturn(false); when(mockStdio.stdinHasTerminal).thenReturn(false);
when(mockStdio.hasTerminal).thenReturn(false); when(mockStdio.hasTerminal).thenReturn(false);
}); });
...@@ -44,6 +46,7 @@ void main() { ...@@ -44,6 +46,7 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => MockProcessManager(), ProcessManager: () => MockProcessManager(),
Stdio: () => mockStdio, Stdio: () => mockStdio,
FlutterVersion: () => mockVersion,
}); });
testUsingContext('version switch prompt is accepted', () async { testUsingContext('version switch prompt is accepted', () async {
...@@ -65,6 +68,7 @@ void main() { ...@@ -65,6 +68,7 @@ void main() {
ProcessManager: () => MockProcessManager(), ProcessManager: () => MockProcessManager(),
Stdio: () => mockStdio, Stdio: () => mockStdio,
AnsiTerminal: () => MockTerminal(), AnsiTerminal: () => MockTerminal(),
FlutterVersion: () => mockVersion,
}); });
testUsingContext('version switch prompt is declined', () async { testUsingContext('version switch prompt is declined', () async {
...@@ -86,6 +90,7 @@ void main() { ...@@ -86,6 +90,7 @@ void main() {
ProcessManager: () => MockProcessManager(), ProcessManager: () => MockProcessManager(),
Stdio: () => mockStdio, Stdio: () => mockStdio,
AnsiTerminal: () => MockTerminal(), AnsiTerminal: () => MockTerminal(),
FlutterVersion: () => mockVersion,
}); });
testUsingContext('version switch, latest commit query fails', () async { testUsingContext('version switch, latest commit query fails', () async {
...@@ -100,6 +105,7 @@ void main() { ...@@ -100,6 +105,7 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => MockProcessManager(latestCommitFails: true), ProcessManager: () => MockProcessManager(latestCommitFails: true),
Stdio: () => mockStdio, Stdio: () => mockStdio,
FlutterVersion: () => mockVersion,
}); });
testUsingContext('latest commit is parsable when query fails', () { testUsingContext('latest commit is parsable when query fails', () {
...@@ -111,6 +117,7 @@ void main() { ...@@ -111,6 +117,7 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => MockProcessManager(latestCommitFails: true), ProcessManager: () => MockProcessManager(latestCommitFails: true),
Stdio: () => mockStdio, Stdio: () => mockStdio,
FlutterVersion: () => mockVersion,
}); });
testUsingContext('switch to not supported version without force', () async { testUsingContext('switch to not supported version without force', () async {
...@@ -125,6 +132,7 @@ void main() { ...@@ -125,6 +132,7 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => MockProcessManager(), ProcessManager: () => MockProcessManager(),
Stdio: () => mockStdio, Stdio: () => mockStdio,
FlutterVersion: () => mockVersion,
}); });
testUsingContext('switch to not supported version with force', () async { testUsingContext('switch to not supported version with force', () async {
...@@ -140,6 +148,7 @@ void main() { ...@@ -140,6 +148,7 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => MockProcessManager(), ProcessManager: () => MockProcessManager(),
Stdio: () => mockStdio, Stdio: () => mockStdio,
FlutterVersion: () => mockVersion,
}); });
testUsingContext('tool exit on confusing version', () async { testUsingContext('tool exit on confusing version', () async {
...@@ -156,6 +165,7 @@ void main() { ...@@ -156,6 +165,7 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => MockProcessManager(), ProcessManager: () => MockProcessManager(),
Stdio: () => mockStdio, Stdio: () => mockStdio,
FlutterVersion: () => mockVersion,
}); });
testUsingContext("exit tool if can't get the tags", () async { testUsingContext("exit tool if can't get the tags", () async {
...@@ -169,6 +179,7 @@ void main() { ...@@ -169,6 +179,7 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => MockProcessManager(failGitTag: true), ProcessManager: () => MockProcessManager(failGitTag: true),
Stdio: () => mockStdio, Stdio: () => mockStdio,
FlutterVersion: () => mockVersion,
}); });
testUsingContext('Does not run pub when outside a project', () async { testUsingContext('Does not run pub when outside a project', () async {
...@@ -180,10 +191,24 @@ void main() { ...@@ -180,10 +191,24 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => MockProcessManager(), ProcessManager: () => MockProcessManager(),
Stdio: () => mockStdio, Stdio: () => mockStdio,
FlutterVersion: () => mockVersion,
});
testUsingContext('Fetches upstream tags', () async {
final VersionCommand command = VersionCommand();
await createTestCommandRunner(command).run(<String>[
'version',
]);
verify(mockVersion.fetchTagsAndUpdate()).called(1);
}, overrides: <Type, Generator>{
ProcessManager: () => MockProcessManager(),
Stdio: () => mockStdio,
FlutterVersion: () => mockVersion,
}); });
}); });
} }
class MockVersion extends Mock implements FlutterVersion {}
class MockTerminal extends Mock implements AnsiTerminal {} class MockTerminal extends Mock implements AnsiTerminal {}
class MockStdio extends Mock implements Stdio {} class MockStdio extends Mock implements Stdio {}
class MockProcessManager extends Mock implements ProcessManager { class MockProcessManager extends Mock implements ProcessManager {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment