Unverified Commit 2d2cd1f5 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] Refactor checkVersionFreshness (#95056)

parent 7addb913
......@@ -278,3 +278,6 @@ FlutterProjectFactory get projectFactory {
CustomDevicesConfig get customDevicesConfig => context.get<CustomDevicesConfig>()!;
PreRunValidator get preRunValidator => context.get<PreRunValidator>() ?? const NoOpPreRunValidator();
// TODO(fujino): Migrate to 'main' https://github.com/flutter/flutter/issues/95041
const String kDefaultFrameworkChannel = 'master';
This diff is collapsed.
......@@ -20,8 +20,8 @@ import '../src/context.dart';
import '../src/fake_process_manager.dart';
final SystemClock _testClock = SystemClock.fixed(DateTime(2015));
final DateTime _stampUpToDate = _testClock.ago(checkAgeConsideredUpToDate ~/ 2);
final DateTime _stampOutOfDate = _testClock.ago(checkAgeConsideredUpToDate * 2);
final DateTime _stampUpToDate = _testClock.ago(VersionFreshnessValidator.checkAgeConsideredUpToDate ~/ 2);
final DateTime _stampOutOfDate = _testClock.ago(VersionFreshnessValidator.checkAgeConsideredUpToDate * 2);
void main() {
FakeCache cache;
......@@ -42,17 +42,17 @@ void main() {
for (final String channel in kOfficialChannels) {
DateTime getChannelUpToDateVersion() {
return _testClock.ago(versionAgeConsideredUpToDate(channel) ~/ 2);
return _testClock.ago(VersionFreshnessValidator.versionAgeConsideredUpToDate(channel) ~/ 2);
}
DateTime getChannelOutOfDateVersion() {
return _testClock.ago(versionAgeConsideredUpToDate(channel) * 2);
return _testClock.ago(VersionFreshnessValidator.versionAgeConsideredUpToDate(channel) * 2);
}
group('$FlutterVersion for $channel', () {
setUpAll(() {
Cache.disableLocking();
timeToPauseToLetUserReadTheMessage = Duration.zero;
VersionFreshnessValidator.timeToPauseToLetUserReadTheMessage = Duration.zero;
});
testUsingContext('prints nothing when Flutter installation looks fresh', () async {
......@@ -151,14 +151,14 @@ void main() {
);
cache.versionStamp = json.encode(stamp);
await checkVersionFreshness(
flutterVersion,
await VersionFreshnessValidator(
version: flutterVersion,
cache: cache,
clock: _testClock,
logger: logger,
localFrameworkCommitDate: getChannelOutOfDateVersion(),
latestFlutterCommitDate: getChannelOutOfDateVersion(),
);
).run();
_expectVersionMessage('', logger);
});
......@@ -172,14 +172,14 @@ void main() {
);
cache.versionStamp = json.encode(stamp);
await checkVersionFreshness(
flutterVersion,
await VersionFreshnessValidator(
version: flutterVersion,
cache: cache,
clock: _testClock,
logger: logger,
localFrameworkCommitDate: getChannelOutOfDateVersion(),
latestFlutterCommitDate: getChannelUpToDateVersion(),
);
).run();
_expectVersionMessage(newVersionAvailableMessage(), logger);
expect(cache.setVersionStamp, true);
......@@ -195,14 +195,14 @@ void main() {
);
cache.versionStamp = json.encode(stamp);
await checkVersionFreshness(
flutterVersion,
await VersionFreshnessValidator(
version: flutterVersion,
cache: cache,
clock: _testClock,
logger: logger,
localFrameworkCommitDate: getChannelOutOfDateVersion(),
latestFlutterCommitDate: getChannelUpToDateVersion(),
);
).run();
_expectVersionMessage('', logger);
});
......@@ -212,14 +212,14 @@ void main() {
final BufferLogger logger = BufferLogger.test();
cache.versionStamp = '{}';
await checkVersionFreshness(
flutterVersion,
await VersionFreshnessValidator(
version: flutterVersion,
cache: cache,
clock: _testClock,
logger: logger,
localFrameworkCommitDate: getChannelOutOfDateVersion(),
latestFlutterCommitDate: getChannelUpToDateVersion(),
);
).run();
_expectVersionMessage(newVersionAvailableMessage(), logger);
expect(cache.setVersionStamp, true);
......@@ -234,14 +234,14 @@ void main() {
);
cache.versionStamp = json.encode(stamp);
await checkVersionFreshness(
flutterVersion,
await VersionFreshnessValidator(
version: flutterVersion,
cache: cache,
clock: _testClock,
logger: logger,
localFrameworkCommitDate: getChannelOutOfDateVersion(),
latestFlutterCommitDate: getChannelUpToDateVersion(),
);
).run();
_expectVersionMessage(newVersionAvailableMessage(), logger);
});
......@@ -251,14 +251,14 @@ void main() {
final BufferLogger logger = BufferLogger.test();
cache.versionStamp = '{}';
await checkVersionFreshness(
flutterVersion,
await VersionFreshnessValidator(
version: flutterVersion,
cache: cache,
clock: _testClock,
logger: logger,
localFrameworkCommitDate: getChannelUpToDateVersion(),
latestFlutterCommitDate: null, // Failed to get remote version
);
// latestFlutterCommitDate defaults to null because we failed to get remote version
).run();
_expectVersionMessage('', logger);
});
......@@ -272,14 +272,14 @@ void main() {
);
cache.versionStamp = json.encode(stamp);
await checkVersionFreshness(
flutterVersion,
await VersionFreshnessValidator(
version: flutterVersion,
cache: cache,
clock: _testClock,
logger: logger,
localFrameworkCommitDate: getChannelOutOfDateVersion(),
latestFlutterCommitDate: null, // Failed to get remote version
);
// latestFlutterCommitDate defaults to null because we failed to get remote version
).run();
_expectVersionMessage(versionOutOfDateMessage(_testClock.now().difference(getChannelOutOfDateVersion())), logger);
});
......
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