Add boxes around version freshness alerts (#96152)

This commit is contained in:
Jenn Magder 2022-01-18 17:28:32 -08:00 committed by GitHub
parent 5d5958f358
commit 3c0f3f4ee1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 35 deletions

View file

@ -879,7 +879,7 @@ class VersionFreshnessValidator {
final String updateMessage;
switch (remoteVersionStatus) {
case VersionCheckResult.newVersionAvailable:
updateMessage = newVersionAvailableMessage();
updateMessage = _newVersionAvailableMessage;
break;
case VersionCheckResult.versionIsCurrent:
case VersionCheckResult.unknown:
@ -887,7 +887,7 @@ class VersionFreshnessValidator {
break;
}
logger.printStatus(updateMessage, emphasis: true);
logger.printBox(updateMessage);
await Future.wait<void>(<Future<void>>[
stamp.store(
newTimeWarningWasPrinted: now,
@ -900,26 +900,13 @@ class VersionFreshnessValidator {
@visibleForTesting
String versionOutOfDateMessage(Duration frameworkAge) {
String warning = 'WARNING: your installation of Flutter is ${frameworkAge.inDays} days old.';
// Append enough spaces to match the message box width.
warning += ' ' * (74 - warning.length);
return '''
$warning
To update to the latest version, run "flutter upgrade".
''';
WARNING: your installation of Flutter is ${frameworkAge.inDays} days old.
To update to the latest version, run "flutter upgrade".''';
}
@visibleForTesting
String newVersionAvailableMessage() {
return '''
A new version of Flutter is available!
To update to the latest version, run "flutter upgrade".
''';
}
const String _newVersionAvailableMessage = '''
A new version of Flutter is available!
To update to the latest version, run "flutter upgrade".''';

View file

@ -134,7 +134,7 @@ void main() {
expect(flutterVersion.getVersionString(redactUnknownBranches: true), '$channel/1234abcd');
expect(flutterVersion.getBranchName(redactUnknownBranches: true), channel);
_expectVersionMessage('', testLogger);
expect(testLogger.statusText, isEmpty);
expect(processManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(clock: _testClock),
@ -160,7 +160,7 @@ void main() {
latestFlutterCommitDate: getChannelOutOfDateVersion(),
).run();
_expectVersionMessage('', logger);
expect(logger.statusText, isEmpty);
});
testWithoutContext('does not ping server when version stamp is up-to-date', () async {
@ -181,7 +181,7 @@ void main() {
latestFlutterCommitDate: getChannelUpToDateVersion(),
).run();
_expectVersionMessage(newVersionAvailableMessage(), logger);
expect(logger.statusText, contains('A new version of Flutter is available!'));
expect(cache.setVersionStamp, true);
});
@ -204,7 +204,7 @@ void main() {
latestFlutterCommitDate: getChannelUpToDateVersion(),
).run();
_expectVersionMessage('', logger);
expect(logger.statusText, isEmpty);
});
testWithoutContext('pings server when version stamp is missing', () async {
@ -221,7 +221,7 @@ void main() {
latestFlutterCommitDate: getChannelUpToDateVersion(),
).run();
_expectVersionMessage(newVersionAvailableMessage(), logger);
expect(logger.statusText, contains('A new version of Flutter is available!'));
expect(cache.setVersionStamp, true);
});
@ -243,7 +243,7 @@ void main() {
latestFlutterCommitDate: getChannelUpToDateVersion(),
).run();
_expectVersionMessage(newVersionAvailableMessage(), logger);
expect(logger.statusText, contains('A new version of Flutter is available!'));
});
testWithoutContext('does not print warning when unable to connect to server if not out of date', () async {
@ -260,7 +260,7 @@ void main() {
// latestFlutterCommitDate defaults to null because we failed to get remote version
).run();
_expectVersionMessage('', logger);
expect(logger.statusText, isEmpty);
});
testWithoutContext('prints warning when unable to connect to server if really out of date', () async {
@ -281,7 +281,8 @@ void main() {
// latestFlutterCommitDate defaults to null because we failed to get remote version
).run();
_expectVersionMessage(versionOutOfDateMessage(_testClock.now().difference(getChannelOutOfDateVersion())), logger);
final Duration frameworkAge = _testClock.now().difference(getChannelOutOfDateVersion());
expect(logger.statusText, contains('WARNING: your installation of Flutter is ${frameworkAge.inDays} days old.'));
});
group('$VersionCheckStamp for $channel', () {
@ -593,11 +594,6 @@ void main() {
});
}
void _expectVersionMessage(String message, BufferLogger logger) {
expect(logger.statusText.trim(), message.trim());
logger.clear();
}
class FakeCache extends Fake implements Cache {
String versionStamp;
bool setVersionStamp = false;