Skip to content

Commit

Permalink
feat(shorebird_cli): add flutterRevision setter to ShorebirdEnv (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored Aug 8, 2023
1 parent 65f15f4 commit b5002aa
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/shorebird_cli/lib/src/shorebird_env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
60 changes: 60 additions & 0 deletions packages/shorebird_cli/test/src/shorebird_env_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down

0 comments on commit b5002aa

Please sign in to comment.