From b5002aa5f2a13de86abbdd83602b4173600a5f67 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Tue, 8 Aug 2023 16:00:26 -0500 Subject: [PATCH] feat(shorebird_cli): add `flutterRevision` setter to `ShorebirdEnv` (#1066) --- .../shorebird_cli/lib/src/shorebird_env.dart | 11 ++++ .../test/src/shorebird_env_test.dart | 60 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/packages/shorebird_cli/lib/src/shorebird_env.dart b/packages/shorebird_cli/lib/src/shorebird_env.dart index 5c7d28594..709f38c90 100644 --- a/packages/shorebird_cli/lib/src/shorebird_env.dart +++ b/packages/shorebird_cli/lib/src/shorebird_env.dart @@ -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( diff --git a/packages/shorebird_cli/test/src/shorebird_env_test.dart b/packages/shorebird_cli/test/src/shorebird_env_test.dart index 9f88f26d8..ed9e41826 100644 --- a/packages/shorebird_cli/test/src/shorebird_env_test.dart +++ b/packages/shorebird_cli/test/src/shorebird_env_test.dart @@ -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', () {