feat(shorebird_cli): add flutterRevision setter to ShorebirdEnv (#1066)

This commit is contained in:
Felix Angelov
2023-08-08 16:00:26 -05:00
committed by GitHub
parent 65f15f4a62
commit b5002aa5f2
2 changed files with 71 additions and 0 deletions
@@ -43,6 +43,17 @@ class ShorebirdEnv {
).readAsStringSync().trim();
}
set flutterRevision(String revision) {
if (revision == flutterRevision) return;
File(
p.join(shorebirdRoot.path, 'bin', 'internal', 'flutter.version'),
).writeAsStringSync(revision);
final snapshot = File(
p.join(shorebirdRoot.path, 'bin', 'cache', 'shorebird.snapshot'),
);
if (snapshot.existsSync()) snapshot.deleteSync();
}
String get flutterRevision {
return _flutterRevisionOverride ??
File(
@@ -384,6 +384,66 @@ test-revision
equals(override),
);
});
test('can be set', () {
const newRevision = 'new-revision';
const revision = '''
test-revision
\r\n
''';
final version = File(
p.join(shorebirdRoot.path, 'bin', 'internal', 'flutter.version'),
)
..createSync(recursive: true)
..writeAsStringSync(revision, flush: true);
final snapshot = File(
p.join(shorebirdRoot.path, 'bin', 'cache', 'shorebird.snapshot'))
..createSync(recursive: true);
expect(
runWithOverrides(() => shorebirdEnv.flutterRevision),
'test-revision',
);
runWithOverrides(() => shorebirdEnv.flutterRevision = newRevision);
expect(snapshot.existsSync(), isFalse);
expect(version.readAsStringSync(), equals(newRevision));
expect(
runWithOverrides(() => shorebirdEnv.flutterRevision),
newRevision,
);
});
test('setting to the same value does nothing', () {
const newRevision = 'test-revision';
const revision = '''
test-revision
\r\n
''';
final version = File(
p.join(shorebirdRoot.path, 'bin', 'internal', 'flutter.version'),
)
..createSync(recursive: true)
..writeAsStringSync(revision, flush: true);
final snapshot = File(
p.join(shorebirdRoot.path, 'bin', 'cache', 'shorebird.snapshot'))
..createSync(recursive: true);
expect(
runWithOverrides(() => shorebirdEnv.flutterRevision),
'test-revision',
);
runWithOverrides(() => shorebirdEnv.flutterRevision = newRevision);
expect(snapshot.existsSync(), isTrue);
expect(version.readAsStringSync(), equals(revision));
expect(
runWithOverrides(() => shorebirdEnv.flutterRevision),
newRevision,
);
});
});
group('shorebirdEngineRevision', () {