Skip to content

Commit

Permalink
feat(shorebird_cli): add getVersions to ShorebirdFlutter (#1063)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored Aug 8, 2023
1 parent 9e745ed commit a6fb9fc
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/shorebird_cli/lib/src/shorebird_flutter.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:io';

import 'package:path/path.dart' as p;
Expand Down Expand Up @@ -60,4 +61,15 @@ class ShorebirdFlutter {
);
return status.isEmpty;
}

Future<List<String>> getVersions({String? revision}) async {
final result = await git.forEachRef(
format: '%(refname:short)',
pattern: 'refs/remotes/origin/flutter_release/*',
directory: _workingDirectory(revision: revision),
);
return LineSplitter.split(result)
.map((e) => e.replaceFirst('origin/flutter_release/', ''))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,79 @@ void main() {
when(() => shorebirdEnv.flutterRevision).thenReturn(flutterRevision);
});

group('getVersions', () {
const format = '%(refname:short)';
const pattern = 'refs/remotes/origin/flutter_release/*';
test('returns a list of versions', () async {
const versions = [
'3.10.0',
'3.10.1',
'3.10.2',
'3.10.3',
'3.10.4',
'3.10.5',
'3.10.6',
];
const output = '''
origin/flutter_release/3.10.0
origin/flutter_release/3.10.1
origin/flutter_release/3.10.2
origin/flutter_release/3.10.3
origin/flutter_release/3.10.4
origin/flutter_release/3.10.5
origin/flutter_release/3.10.6''';
when(
() => git.forEachRef(
directory: any(named: 'directory'),
format: any(named: 'format'),
pattern: any(named: 'pattern'),
),
).thenAnswer((_) async => output);

await expectLater(
runWithOverrides(shorebirdFlutterManager.getVersions),
completion(equals(versions)),
);
verify(
() => git.forEachRef(
directory: p.join(flutterDirectory.parent.path, flutterRevision),
format: format,
pattern: pattern,
),
).called(1);
});

test('throws ProcessException when git command exits non-zero code',
() async {
const errorMessage = 'oh no!';
when(
() => git.forEachRef(
directory: any(named: 'directory'),
format: any(named: 'format'),
pattern: any(named: 'pattern'),
),
).thenThrow(
ProcessException(
'git',
['for-each-ref', '--format', format, pattern],
errorMessage,
ExitCode.software.code,
),
);

expect(
runWithOverrides(shorebirdFlutterManager.getVersions),
throwsA(
isA<ProcessException>().having(
(e) => e.message,
'message',
errorMessage,
),
),
);
});
});

group('installRevision', () {
const revision = 'test-revision';
test('does nothing if the revision is already installed', () async {
Expand Down

0 comments on commit a6fb9fc

Please sign in to comment.