Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
97e03104
Unverified
Commit
97e03104
authored
Nov 13, 2018
by
Greg Spencer
Committed by
GitHub
Nov 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make the 'time to update' message depend up on the channel. (#24173)
Fixes #24158
parent
72b6a706
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
382 additions
and
329 deletions
+382
-329
version.dart
packages/flutter_tools/lib/src/version.dart
+29
-15
channel_test.dart
packages/flutter_tools/test/channel_test.dart
+1
-1
version_test.dart
packages/flutter_tools/test/version_test.dart
+352
-313
No files found.
packages/flutter_tools/lib/src/version.dart
View file @
97e03104
...
@@ -207,20 +207,34 @@ class FlutterVersion {
...
@@ -207,20 +207,34 @@ class FlutterVersion {
/// The amount of time we wait before pinging the server to check for the
/// The amount of time we wait before pinging the server to check for the
/// availability of a newer version of Flutter.
/// availability of a newer version of Flutter.
@visibleForTesting
@visibleForTesting
static
const
Duration
kC
heckAgeConsideredUpToDate
=
Duration
(
days:
3
);
static
const
Duration
c
heckAgeConsideredUpToDate
=
Duration
(
days:
3
);
/// We warn the user if the age of their Flutter installation is greater than
/// We warn the user if the age of their Flutter installation is greater than
/// this duration.
/// this duration. The durations are slightly longer than the expected release
/// cadence for each channel, to give the user a grace period before they get
/// notified.
///
///
/// This is set to 5 weeks because releases are currently around every 4 weeks.
/// For example, for the beta channel, this is set to five weeks because
/// beta releases happen approximately every month.
@visibleForTesting
@visibleForTesting
static
const
Duration
kVersionAgeConsideredUpToDate
=
Duration
(
days:
35
);
static
Duration
versionAgeConsideredUpToDate
(
String
channel
)
{
switch
(
channel
)
{
case
'stable'
:
return
const
Duration
(
days:
365
~/
2
);
// Six months
case
'beta'
:
return
const
Duration
(
days:
7
*
8
);
// Eight weeks
case
'dev'
:
return
const
Duration
(
days:
7
*
4
);
// Four weeks
default
:
return
const
Duration
(
days:
7
*
3
);
// Three weeks
}
}
/// The amount of time we wait between issuing a warning.
/// The amount of time we wait between issuing a warning.
///
///
/// This is to avoid annoying users who are unable to upgrade right away.
/// This is to avoid annoying users who are unable to upgrade right away.
@visibleForTesting
@visibleForTesting
static
const
Duration
kM
axTimeSinceLastWarning
=
Duration
(
days:
1
);
static
const
Duration
m
axTimeSinceLastWarning
=
Duration
(
days:
1
);
/// The amount of time we pause for to let the user read the message about
/// The amount of time we pause for to let the user read the message about
/// outdated Flutter installation.
/// outdated Flutter installation.
...
@@ -238,7 +252,7 @@ class FlutterVersion {
...
@@ -238,7 +252,7 @@ class FlutterVersion {
static
Future
<
void
>
resetFlutterVersionFreshnessCheck
()
async
{
static
Future
<
void
>
resetFlutterVersionFreshnessCheck
()
async
{
try
{
try
{
await
Cache
.
instance
.
getStampFileFor
(
await
Cache
.
instance
.
getStampFileFor
(
VersionCheckStamp
.
kF
lutterVersionCheckStampFile
,
VersionCheckStamp
.
f
lutterVersionCheckStampFile
,
).
delete
();
).
delete
();
}
on
FileSystemException
{
}
on
FileSystemException
{
// Ignore, since we don't mind if the file didn't exist in the first place.
// Ignore, since we don't mind if the file didn't exist in the first place.
...
@@ -258,7 +272,7 @@ class FlutterVersion {
...
@@ -258,7 +272,7 @@ class FlutterVersion {
final
DateTime
localFrameworkCommitDate
=
DateTime
.
parse
(
frameworkCommitDate
);
final
DateTime
localFrameworkCommitDate
=
DateTime
.
parse
(
frameworkCommitDate
);
final
Duration
frameworkAge
=
_clock
.
now
().
difference
(
localFrameworkCommitDate
);
final
Duration
frameworkAge
=
_clock
.
now
().
difference
(
localFrameworkCommitDate
);
final
bool
installationSeemsOutdated
=
frameworkAge
>
kVersionAgeConsideredUpToDate
;
final
bool
installationSeemsOutdated
=
frameworkAge
>
versionAgeConsideredUpToDate
(
channel
)
;
// Get whether there's a newer version on the remote. This only goes
// Get whether there's a newer version on the remote. This only goes
// to the server if we haven't checked recently so won't happen on every
// to the server if we haven't checked recently so won't happen on every
...
@@ -273,8 +287,8 @@ class FlutterVersion {
...
@@ -273,8 +287,8 @@ class FlutterVersion {
// Do not load the stamp before the above server check as it may modify the stamp file.
// Do not load the stamp before the above server check as it may modify the stamp file.
final
VersionCheckStamp
stamp
=
await
VersionCheckStamp
.
load
();
final
VersionCheckStamp
stamp
=
await
VersionCheckStamp
.
load
();
final
DateTime
lastTimeWarningWasPrinted
=
stamp
.
lastTimeWarningWasPrinted
??
_clock
.
ago
(
kM
axTimeSinceLastWarning
*
2
);
final
DateTime
lastTimeWarningWasPrinted
=
stamp
.
lastTimeWarningWasPrinted
??
_clock
.
ago
(
m
axTimeSinceLastWarning
*
2
);
final
bool
beenAWhileSinceWarningWasPrinted
=
_clock
.
now
().
difference
(
lastTimeWarningWasPrinted
)
>
kM
axTimeSinceLastWarning
;
final
bool
beenAWhileSinceWarningWasPrinted
=
_clock
.
now
().
difference
(
lastTimeWarningWasPrinted
)
>
m
axTimeSinceLastWarning
;
// We show a warning if either we know there is a new remote version, or we couldn't tell but the local
// We show a warning if either we know there is a new remote version, or we couldn't tell but the local
// version is outdated.
// version is outdated.
...
@@ -327,7 +341,7 @@ class FlutterVersion {
...
@@ -327,7 +341,7 @@ class FlutterVersion {
/// Gets the release date of the latest available Flutter version.
/// Gets the release date of the latest available Flutter version.
///
///
/// This method sends a server request if it's been more than
/// This method sends a server request if it's been more than
/// [
kC
heckAgeConsideredUpToDate] since the last version check.
/// [
c
heckAgeConsideredUpToDate] since the last version check.
///
///
/// Returns null if the cached version is out-of-date or missing, and we are
/// Returns null if the cached version is out-of-date or missing, and we are
/// unable to reach the server to get the latest version.
/// unable to reach the server to get the latest version.
...
@@ -339,7 +353,7 @@ class FlutterVersion {
...
@@ -339,7 +353,7 @@ class FlutterVersion {
final
Duration
timeSinceLastCheck
=
_clock
.
now
().
difference
(
versionCheckStamp
.
lastTimeVersionWasChecked
);
final
Duration
timeSinceLastCheck
=
_clock
.
now
().
difference
(
versionCheckStamp
.
lastTimeVersionWasChecked
);
// Don't ping the server too often. Return cached value if it's fresh.
// Don't ping the server too often. Return cached value if it's fresh.
if
(
timeSinceLastCheck
<
kC
heckAgeConsideredUpToDate
)
if
(
timeSinceLastCheck
<
c
heckAgeConsideredUpToDate
)
return
versionCheckStamp
.
lastKnownRemoteVersion
;
return
versionCheckStamp
.
lastKnownRemoteVersion
;
}
}
...
@@ -381,10 +395,10 @@ class VersionCheckStamp {
...
@@ -381,10 +395,10 @@ class VersionCheckStamp {
/// The prefix of the stamp file where we cache Flutter version check data.
/// The prefix of the stamp file where we cache Flutter version check data.
@visibleForTesting
@visibleForTesting
static
const
String
kF
lutterVersionCheckStampFile
=
'flutter_version_check'
;
static
const
String
f
lutterVersionCheckStampFile
=
'flutter_version_check'
;
static
Future
<
VersionCheckStamp
>
load
()
async
{
static
Future
<
VersionCheckStamp
>
load
()
async
{
final
String
versionCheckStamp
=
Cache
.
instance
.
getStampFor
(
kF
lutterVersionCheckStampFile
);
final
String
versionCheckStamp
=
Cache
.
instance
.
getStampFor
(
f
lutterVersionCheckStampFile
);
if
(
versionCheckStamp
!=
null
)
{
if
(
versionCheckStamp
!=
null
)
{
// Attempt to parse stamp JSON.
// Attempt to parse stamp JSON.
...
@@ -435,8 +449,8 @@ class VersionCheckStamp {
...
@@ -435,8 +449,8 @@ class VersionCheckStamp {
if
(
newTimeWarningWasPrinted
!=
null
)
if
(
newTimeWarningWasPrinted
!=
null
)
jsonData
[
'lastTimeWarningWasPrinted'
]
=
'
$newTimeWarningWasPrinted
'
;
jsonData
[
'lastTimeWarningWasPrinted'
]
=
'
$newTimeWarningWasPrinted
'
;
const
JsonEncoder
kP
rettyJsonEncoder
=
JsonEncoder
.
withIndent
(
' '
);
const
JsonEncoder
p
rettyJsonEncoder
=
JsonEncoder
.
withIndent
(
' '
);
Cache
.
instance
.
setStampFor
(
kFlutterVersionCheckStampFile
,
kP
rettyJsonEncoder
.
convert
(
jsonData
));
Cache
.
instance
.
setStampFor
(
flutterVersionCheckStampFile
,
p
rettyJsonEncoder
.
convert
(
jsonData
));
}
}
Map
<
String
,
String
>
toJson
({
Map
<
String
,
String
>
toJson
({
...
...
packages/flutter_tools/test/channel_test.dart
View file @
97e03104
...
@@ -188,7 +188,7 @@ void main() {
...
@@ -188,7 +188,7 @@ void main() {
)).
thenAnswer
((
_
)
=>
Future
<
Process
>.
value
(
createMockProcess
()));
)).
thenAnswer
((
_
)
=>
Future
<
Process
>.
value
(
createMockProcess
()));
final
File
versionCheckFile
=
Cache
.
instance
.
getStampFileFor
(
final
File
versionCheckFile
=
Cache
.
instance
.
getStampFileFor
(
VersionCheckStamp
.
kF
lutterVersionCheckStampFile
,
VersionCheckStamp
.
f
lutterVersionCheckStampFile
,
);
);
/// Create a bogus "leftover" version check file to make sure it gets
/// Create a bogus "leftover" version check file to make sure it gets
...
...
packages/flutter_tools/test/version_test.dart
View file @
97e03104
...
@@ -19,10 +19,8 @@ import 'src/common.dart';
...
@@ -19,10 +19,8 @@ import 'src/common.dart';
import
'src/context.dart'
;
import
'src/context.dart'
;
final
SystemClock
_testClock
=
SystemClock
.
fixed
(
DateTime
(
2015
,
1
,
1
));
final
SystemClock
_testClock
=
SystemClock
.
fixed
(
DateTime
(
2015
,
1
,
1
));
final
DateTime
_upToDateVersion
=
_testClock
.
ago
(
FlutterVersion
.
kVersionAgeConsideredUpToDate
~/
2
);
final
DateTime
_stampUpToDate
=
_testClock
.
ago
(
FlutterVersion
.
checkAgeConsideredUpToDate
~/
2
);
final
DateTime
_outOfDateVersion
=
_testClock
.
ago
(
FlutterVersion
.
kVersionAgeConsideredUpToDate
*
2
);
final
DateTime
_stampOutOfDate
=
_testClock
.
ago
(
FlutterVersion
.
checkAgeConsideredUpToDate
*
2
);
final
DateTime
_stampUpToDate
=
_testClock
.
ago
(
FlutterVersion
.
kCheckAgeConsideredUpToDate
~/
2
);
final
DateTime
_stampOutOfDate
=
_testClock
.
ago
(
FlutterVersion
.
kCheckAgeConsideredUpToDate
*
2
);
void
main
(
)
{
void
main
(
)
{
MockProcessManager
mockProcessManager
;
MockProcessManager
mockProcessManager
;
...
@@ -33,7 +31,16 @@ void main() {
...
@@ -33,7 +31,16 @@ void main() {
mockCache
=
MockCache
();
mockCache
=
MockCache
();
});
});
group
(
'
$FlutterVersion
'
,
()
{
for
(
String
channel
in
FlutterVersion
.
officialChannels
)
{
DateTime
getChannelUpToDateVersion
()
{
return
_testClock
.
ago
(
FlutterVersion
.
versionAgeConsideredUpToDate
(
channel
)
~/
2
);
}
DateTime
getChannelOutOfDateVersion
()
{
return
_testClock
.
ago
(
FlutterVersion
.
versionAgeConsideredUpToDate
(
channel
)
*
2
);
}
group
(
'
$FlutterVersion
for
$channel
'
,
()
{
setUpAll
(()
{
setUpAll
(()
{
Cache
.
disableLocking
();
Cache
.
disableLocking
();
FlutterVersion
.
timeToPauseToLetUserReadTheMessage
=
Duration
.
zero
;
FlutterVersion
.
timeToPauseToLetUserReadTheMessage
=
Duration
.
zero
;
...
@@ -43,11 +50,13 @@ void main() {
...
@@ -43,11 +50,13 @@ void main() {
fakeData
(
fakeData
(
mockProcessManager
,
mockProcessManager
,
mockCache
,
mockCache
,
localCommitDate:
_upToDateVersion
,
localCommitDate:
getChannelUpToDateVersion
()
,
// Server will be pinged because we haven't pinged within last x days
// Server will be pinged because we haven't pinged within last x days
expectServerPing:
true
,
expectServerPing:
true
,
remoteCommitDate:
_outOfDateVersion
,
remoteCommitDate:
getChannelOutOfDateVersion
(),
expectSetStamp:
true
);
expectSetStamp:
true
,
channel:
channel
,
);
await
FlutterVersion
.
instance
.
checkFlutterVersionFreshness
();
await
FlutterVersion
.
instance
.
checkFlutterVersionFreshness
();
_expectVersionMessage
(
''
);
_expectVersionMessage
(
''
);
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
...
@@ -56,18 +65,19 @@ void main() {
...
@@ -56,18 +65,19 @@ void main() {
Cache:
()
=>
mockCache
,
Cache:
()
=>
mockCache
,
});
});
testUsingContext
(
'prints nothing when Flutter installation looks out-of-date by
is actually up-to-date'
,
()
async
{
testUsingContext
(
'prints nothing when Flutter installation looks out-of-date but
is actually up-to-date'
,
()
async
{
fakeData
(
fakeData
(
mockProcessManager
,
mockProcessManager
,
mockCache
,
mockCache
,
localCommitDate:
_outOfDateVersion
,
localCommitDate:
getChannelOutOfDateVersion
()
,
stamp:
VersionCheckStamp
(
stamp:
VersionCheckStamp
(
lastTimeVersionWasChecked:
_stampOutOfDate
,
lastTimeVersionWasChecked:
_stampOutOfDate
,
lastKnownRemoteVersion:
_outOfDateVersion
,
lastKnownRemoteVersion:
getChannelOutOfDateVersion
()
,
),
),
remoteCommitDate:
_outOfDateVersion
,
remoteCommitDate:
getChannelOutOfDateVersion
()
,
expectSetStamp:
true
,
expectSetStamp:
true
,
expectServerPing:
true
,
expectServerPing:
true
,
channel:
channel
,
);
);
final
FlutterVersion
version
=
FlutterVersion
.
instance
;
final
FlutterVersion
version
=
FlutterVersion
.
instance
;
...
@@ -83,12 +93,13 @@ void main() {
...
@@ -83,12 +93,13 @@ void main() {
fakeData
(
fakeData
(
mockProcessManager
,
mockProcessManager
,
mockCache
,
mockCache
,
localCommitDate:
_outOfDateVersion
,
localCommitDate:
getChannelOutOfDateVersion
()
,
stamp:
VersionCheckStamp
(
stamp:
VersionCheckStamp
(
lastTimeVersionWasChecked:
_stampUpToDate
,
lastTimeVersionWasChecked:
_stampUpToDate
,
lastKnownRemoteVersion:
_upToDateVersion
,
lastKnownRemoteVersion:
getChannelUpToDateVersion
()
,
),
),
expectSetStamp:
true
,
expectSetStamp:
true
,
channel:
channel
,
);
);
final
FlutterVersion
version
=
FlutterVersion
.
instance
;
final
FlutterVersion
version
=
FlutterVersion
.
instance
;
...
@@ -104,12 +115,13 @@ void main() {
...
@@ -104,12 +115,13 @@ void main() {
fakeData
(
fakeData
(
mockProcessManager
,
mockProcessManager
,
mockCache
,
mockCache
,
localCommitDate:
_outOfDateVersion
,
localCommitDate:
getChannelOutOfDateVersion
()
,
stamp:
VersionCheckStamp
(
stamp:
VersionCheckStamp
(
lastTimeVersionWasChecked:
_stampUpToDate
,
lastTimeVersionWasChecked:
_stampUpToDate
,
lastKnownRemoteVersion:
_upToDateVersion
,
lastKnownRemoteVersion:
getChannelUpToDateVersion
()
,
),
),
expectSetStamp:
true
,
expectSetStamp:
true
,
channel:
channel
,
);
);
final
FlutterVersion
version
=
FlutterVersion
.
instance
;
final
FlutterVersion
version
=
FlutterVersion
.
instance
;
...
@@ -129,10 +141,11 @@ void main() {
...
@@ -129,10 +141,11 @@ void main() {
fakeData
(
fakeData
(
mockProcessManager
,
mockProcessManager
,
mockCache
,
mockCache
,
localCommitDate:
_outOfDateVersion
,
localCommitDate:
getChannelOutOfDateVersion
()
,
remoteCommitDate:
_upToDateVersion
,
remoteCommitDate:
getChannelUpToDateVersion
()
,
expectSetStamp:
true
,
expectSetStamp:
true
,
expectServerPing:
true
,
expectServerPing:
true
,
channel:
channel
,
);
);
final
FlutterVersion
version
=
FlutterVersion
.
instance
;
final
FlutterVersion
version
=
FlutterVersion
.
instance
;
...
@@ -143,8 +156,9 @@ void main() {
...
@@ -143,8 +156,9 @@ void main() {
fakeData
(
fakeData
(
mockProcessManager
,
mockProcessManager
,
mockCache
,
mockCache
,
localCommitDate:
_outOfDateVersion
,
localCommitDate:
getChannelOutOfDateVersion
()
,
stamp:
await
VersionCheckStamp
.
load
(),
stamp:
await
VersionCheckStamp
.
load
(),
channel:
channel
,
);
);
await
version
.
checkFlutterVersionFreshness
();
await
version
.
checkFlutterVersionFreshness
();
_expectVersionMessage
(
''
);
_expectVersionMessage
(
''
);
...
@@ -158,14 +172,15 @@ void main() {
...
@@ -158,14 +172,15 @@ void main() {
fakeData
(
fakeData
(
mockProcessManager
,
mockProcessManager
,
mockCache
,
mockCache
,
localCommitDate:
_outOfDateVersion
,
localCommitDate:
getChannelOutOfDateVersion
()
,
stamp:
VersionCheckStamp
(
stamp:
VersionCheckStamp
(
lastTimeVersionWasChecked:
_stampOutOfDate
,
lastTimeVersionWasChecked:
_stampOutOfDate
,
lastKnownRemoteVersion:
_testClock
.
ago
(
const
Duration
(
days:
2
)),
lastKnownRemoteVersion:
_testClock
.
ago
(
const
Duration
(
days:
2
)),
),
),
remoteCommitDate:
_upToDateVersion
,
remoteCommitDate:
getChannelUpToDateVersion
()
,
expectSetStamp:
true
,
expectSetStamp:
true
,
expectServerPing:
true
,
expectServerPing:
true
,
channel:
channel
,
);
);
final
FlutterVersion
version
=
FlutterVersion
.
instance
;
final
FlutterVersion
version
=
FlutterVersion
.
instance
;
...
@@ -181,10 +196,11 @@ void main() {
...
@@ -181,10 +196,11 @@ void main() {
fakeData
(
fakeData
(
mockProcessManager
,
mockProcessManager
,
mockCache
,
mockCache
,
localCommitDate:
_upToDateVersion
,
localCommitDate:
getChannelUpToDateVersion
()
,
errorOnFetch:
true
,
errorOnFetch:
true
,
expectServerPing:
true
,
expectServerPing:
true
,
expectSetStamp:
true
,
expectSetStamp:
true
,
channel:
channel
,
);
);
final
FlutterVersion
version
=
FlutterVersion
.
instance
;
final
FlutterVersion
version
=
FlutterVersion
.
instance
;
...
@@ -200,15 +216,16 @@ void main() {
...
@@ -200,15 +216,16 @@ void main() {
fakeData
(
fakeData
(
mockProcessManager
,
mockProcessManager
,
mockCache
,
mockCache
,
localCommitDate:
_outOfDateVersion
,
localCommitDate:
getChannelOutOfDateVersion
()
,
errorOnFetch:
true
,
errorOnFetch:
true
,
expectServerPing:
true
,
expectServerPing:
true
,
expectSetStamp:
true
expectSetStamp:
true
,
channel:
channel
,
);
);
final
FlutterVersion
version
=
FlutterVersion
.
instance
;
final
FlutterVersion
version
=
FlutterVersion
.
instance
;
await
version
.
checkFlutterVersionFreshness
();
await
version
.
checkFlutterVersionFreshness
();
_expectVersionMessage
(
FlutterVersion
.
versionOutOfDateMessage
(
_testClock
.
now
().
difference
(
_outOfDateVersion
)));
_expectVersionMessage
(
FlutterVersion
.
versionOutOfDateMessage
(
_testClock
.
now
().
difference
(
getChannelOutOfDateVersion
()
)));
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
FlutterVersion:
()
=>
FlutterVersion
(
_testClock
),
FlutterVersion:
()
=>
FlutterVersion
(
_testClock
),
ProcessManager:
()
=>
mockProcessManager
,
ProcessManager:
()
=>
mockProcessManager
,
...
@@ -219,10 +236,11 @@ void main() {
...
@@ -219,10 +236,11 @@ void main() {
fakeData
(
fakeData
(
mockProcessManager
,
mockProcessManager
,
mockCache
,
mockCache
,
localCommitDate:
_outOfDateVersion
,
localCommitDate:
getChannelOutOfDateVersion
()
,
errorOnFetch:
true
,
errorOnFetch:
true
,
expectServerPing:
true
,
expectServerPing:
true
,
expectSetStamp:
true
expectSetStamp:
true
,
channel:
channel
,
);
);
final
FlutterVersion
version
=
FlutterVersion
.
instance
;
final
FlutterVersion
version
=
FlutterVersion
.
instance
;
...
@@ -236,21 +254,19 @@ void main() {
...
@@ -236,21 +254,19 @@ void main() {
tentativeDescendantRevision:
'123456'
,
tentativeDescendantRevision:
'123456'
,
tentativeAncestorRevision:
'abcdef'
,
tentativeAncestorRevision:
'abcdef'
,
),
),
true
true
);
);
verify
(
mockProcessManager
.
runSync
(
verify
(
mockProcessManager
.
runSync
(
<
String
>[
'git'
,
'merge-base'
,
'--is-ancestor'
,
'abcdef'
,
'123456'
],
<
String
>[
'git'
,
'merge-base'
,
'--is-ancestor'
,
'abcdef'
,
'123456'
],
workingDirectory:
anyNamed
(
'workingDirectory'
),
workingDirectory:
anyNamed
(
'workingDirectory'
),
));
));
},
},
overrides:
<
Type
,
Generator
>{
overrides:
<
Type
,
Generator
>{
FlutterVersion:
()
=>
FlutterVersion
(
_testClock
),
FlutterVersion:
()
=>
FlutterVersion
(
_testClock
),
ProcessManager:
()
=>
mockProcessManager
,
ProcessManager:
()
=>
mockProcessManager
,
});
});
});
});
group
(
'
$VersionCheckStamp
'
,
()
{
group
(
'
$VersionCheckStamp
for
$channel
'
,
()
{
void
_expectDefault
(
VersionCheckStamp
stamp
)
{
void
_expectDefault
(
VersionCheckStamp
stamp
)
{
expect
(
stamp
.
lastKnownRemoteVersion
,
isNull
);
expect
(
stamp
.
lastKnownRemoteVersion
,
isNull
);
expect
(
stamp
.
lastTimeVersionWasChecked
,
isNull
);
expect
(
stamp
.
lastTimeVersionWasChecked
,
isNull
);
...
@@ -258,7 +274,7 @@ void main() {
...
@@ -258,7 +274,7 @@ void main() {
}
}
testUsingContext
(
'loads blank when stamp file missing'
,
()
async
{
testUsingContext
(
'loads blank when stamp file missing'
,
()
async
{
fakeData
(
mockProcessManager
,
mockCache
);
fakeData
(
mockProcessManager
,
mockCache
,
channel:
channel
);
_expectDefault
(
await
VersionCheckStamp
.
load
());
_expectDefault
(
await
VersionCheckStamp
.
load
());
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
FlutterVersion:
()
=>
FlutterVersion
(
_testClock
),
FlutterVersion:
()
=>
FlutterVersion
(
_testClock
),
...
@@ -267,7 +283,7 @@ void main() {
...
@@ -267,7 +283,7 @@ void main() {
});
});
testUsingContext
(
'loads blank when stamp file is malformed JSON'
,
()
async
{
testUsingContext
(
'loads blank when stamp file is malformed JSON'
,
()
async
{
fakeData
(
mockProcessManager
,
mockCache
,
stampJson:
'<'
);
fakeData
(
mockProcessManager
,
mockCache
,
stampJson:
'<'
,
channel:
channel
);
_expectDefault
(
await
VersionCheckStamp
.
load
());
_expectDefault
(
await
VersionCheckStamp
.
load
());
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
FlutterVersion:
()
=>
FlutterVersion
(
_testClock
),
FlutterVersion:
()
=>
FlutterVersion
(
_testClock
),
...
@@ -276,7 +292,12 @@ void main() {
...
@@ -276,7 +292,12 @@ void main() {
});
});
testUsingContext
(
'loads blank when stamp file is well-formed but invalid JSON'
,
()
async
{
testUsingContext
(
'loads blank when stamp file is well-formed but invalid JSON'
,
()
async
{
fakeData
(
mockProcessManager
,
mockCache
,
stampJson:
'[]'
);
fakeData
(
mockProcessManager
,
mockCache
,
stampJson:
'[]'
,
channel:
channel
,
);
_expectDefault
(
await
VersionCheckStamp
.
load
());
_expectDefault
(
await
VersionCheckStamp
.
load
());
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
FlutterVersion:
()
=>
FlutterVersion
(
_testClock
),
FlutterVersion:
()
=>
FlutterVersion
(
_testClock
),
...
@@ -285,13 +306,18 @@ void main() {
...
@@ -285,13 +306,18 @@ void main() {
});
});
testUsingContext
(
'loads valid JSON'
,
()
async
{
testUsingContext
(
'loads valid JSON'
,
()
async
{
fakeData
(
mockProcessManager
,
mockCache
,
stampJson:
'''
fakeData
(
mockProcessManager
,
mockCache
,
stampJson:
'''
{
{
"lastKnownRemoteVersion": "
${_testClock.ago(const Duration(days: 1))}
",
"lastKnownRemoteVersion": "
${_testClock.ago(const Duration(days: 1))}
",
"lastTimeVersionWasChecked": "
${_testClock.ago(const Duration(days: 2))}
",
"lastTimeVersionWasChecked": "
${_testClock.ago(const Duration(days: 2))}
",
"lastTimeWarningWasPrinted": "
${_testClock.now()}
"
"lastTimeWarningWasPrinted": "
${_testClock.now()}
"
}
}
'''
);
'''
,
channel:
channel
,
);
final
VersionCheckStamp
stamp
=
await
VersionCheckStamp
.
load
();
final
VersionCheckStamp
stamp
=
await
VersionCheckStamp
.
load
();
expect
(
stamp
.
lastKnownRemoteVersion
,
_testClock
.
ago
(
const
Duration
(
days:
1
)));
expect
(
stamp
.
lastKnownRemoteVersion
,
_testClock
.
ago
(
const
Duration
(
days:
1
)));
...
@@ -304,7 +330,12 @@ void main() {
...
@@ -304,7 +330,12 @@ void main() {
});
});
testUsingContext
(
'stores version stamp'
,
()
async
{
testUsingContext
(
'stores version stamp'
,
()
async
{
fakeData
(
mockProcessManager
,
mockCache
,
expectSetStamp:
true
);
fakeData
(
mockProcessManager
,
mockCache
,
expectSetStamp:
true
,
channel:
channel
,
);
_expectDefault
(
await
VersionCheckStamp
.
load
());
_expectDefault
(
await
VersionCheckStamp
.
load
());
...
@@ -326,7 +357,12 @@ void main() {
...
@@ -326,7 +357,12 @@ void main() {
});
});
testUsingContext
(
'overwrites individual fields'
,
()
async
{
testUsingContext
(
'overwrites individual fields'
,
()
async
{
fakeData
(
mockProcessManager
,
mockCache
,
expectSetStamp:
true
);
fakeData
(
mockProcessManager
,
mockCache
,
expectSetStamp:
true
,
channel:
channel
,
);
_expectDefault
(
await
VersionCheckStamp
.
load
());
_expectDefault
(
await
VersionCheckStamp
.
load
());
...
@@ -351,6 +387,7 @@ void main() {
...
@@ -351,6 +387,7 @@ void main() {
Cache:
()
=>
mockCache
,
Cache:
()
=>
mockCache
,
});
});
});
});
}
}
}
void
_expectVersionMessage
(
String
message
)
{
void
_expectVersionMessage
(
String
message
)
{
...
@@ -369,6 +406,7 @@ void fakeData(
...
@@ -369,6 +406,7 @@ void fakeData(
bool
errorOnFetch
=
false
,
bool
errorOnFetch
=
false
,
bool
expectSetStamp
=
false
,
bool
expectSetStamp
=
false
,
bool
expectServerPing
=
false
,
bool
expectServerPing
=
false
,
String
channel
=
'master'
,
})
{
})
{
ProcessResult
success
(
String
standardOutput
)
{
ProcessResult
success
(
String
standardOutput
)
{
return
ProcessResult
(
1
,
0
,
standardOutput
,
''
);
return
ProcessResult
(
1
,
0
,
standardOutput
,
''
);
...
@@ -379,19 +417,21 @@ void fakeData(
...
@@ -379,19 +417,21 @@ void fakeData(
}
}
when
(
cache
.
getStampFor
(
any
)).
thenAnswer
((
Invocation
invocation
)
{
when
(
cache
.
getStampFor
(
any
)).
thenAnswer
((
Invocation
invocation
)
{
expect
(
invocation
.
positionalArguments
.
single
,
VersionCheckStamp
.
kF
lutterVersionCheckStampFile
);
expect
(
invocation
.
positionalArguments
.
single
,
VersionCheckStamp
.
f
lutterVersionCheckStampFile
);
if
(
stampJson
!=
null
)
if
(
stampJson
!=
null
)
{
return
stampJson
;
return
stampJson
;
}
if
(
stamp
!=
null
)
if
(
stamp
!=
null
)
{
return
json
.
encode
(
stamp
.
toJson
());
return
json
.
encode
(
stamp
.
toJson
());
}
return
null
;
return
null
;
});
});
when
(
cache
.
setStampFor
(
any
,
any
)).
thenAnswer
((
Invocation
invocation
)
{
when
(
cache
.
setStampFor
(
any
,
any
)).
thenAnswer
((
Invocation
invocation
)
{
expect
(
invocation
.
positionalArguments
.
first
,
VersionCheckStamp
.
kF
lutterVersionCheckStampFile
);
expect
(
invocation
.
positionalArguments
.
first
,
VersionCheckStamp
.
f
lutterVersionCheckStampFile
);
if
(
expectSetStamp
)
{
if
(
expectSetStamp
)
{
stamp
=
VersionCheckStamp
.
fromJson
(
json
.
decode
(
invocation
.
positionalArguments
[
1
]));
stamp
=
VersionCheckStamp
.
fromJson
(
json
.
decode
(
invocation
.
positionalArguments
[
1
]));
...
@@ -405,10 +445,7 @@ void fakeData(
...
@@ -405,10 +445,7 @@ void fakeData(
bool
argsAre
(
String
a1
,
[
String
a2
,
String
a3
,
String
a4
,
String
a5
,
String
a6
,
String
a7
,
String
a8
])
{
bool
argsAre
(
String
a1
,
[
String
a2
,
String
a3
,
String
a4
,
String
a5
,
String
a6
,
String
a7
,
String
a8
])
{
const
ListEquality
<
String
>
equality
=
ListEquality
<
String
>();
const
ListEquality
<
String
>
equality
=
ListEquality
<
String
>();
final
List
<
String
>
args
=
invocation
.
positionalArguments
.
single
;
final
List
<
String
>
args
=
invocation
.
positionalArguments
.
single
;
final
List
<
String
>
expectedArgs
=
final
List
<
String
>
expectedArgs
=
<
String
>[
a1
,
a2
,
a3
,
a4
,
a5
,
a6
,
a7
,
a8
].
where
((
String
arg
)
=>
arg
!=
null
).
toList
();
<
String
>[
a1
,
a2
,
a3
,
a4
,
a5
,
a6
,
a7
,
a8
]
.
where
((
String
arg
)
=>
arg
!=
null
)
.
toList
();
return
equality
.
equals
(
args
,
expectedArgs
);
return
equality
.
equals
(
args
,
expectedArgs
);
}
}
...
@@ -418,11 +455,12 @@ void fakeData(
...
@@ -418,11 +455,12 @@ void fakeData(
return
success
(
''
);
return
success
(
''
);
}
else
if
(
argsAre
(
'git'
,
'remote'
,
'add'
,
'__flutter_version_check__'
,
'https://github.com/flutter/flutter.git'
))
{
}
else
if
(
argsAre
(
'git'
,
'remote'
,
'add'
,
'__flutter_version_check__'
,
'https://github.com/flutter/flutter.git'
))
{
return
success
(
''
);
return
success
(
''
);
}
else
if
(
argsAre
(
'git'
,
'fetch'
,
'__flutter_version_check__'
,
'master'
))
{
}
else
if
(
argsAre
(
'git'
,
'fetch'
,
'__flutter_version_check__'
,
channel
))
{
if
(!
expectServerPing
)
if
(!
expectServerPing
)
{
fail
(
'Did not expect server ping'
);
fail
(
'Did not expect server ping'
);
}
return
errorOnFetch
?
failure
(
128
)
:
success
(
''
);
return
errorOnFetch
?
failure
(
128
)
:
success
(
''
);
}
else
if
(
remoteCommitDate
!=
null
&&
argsAre
(
'git'
,
'log'
,
'__flutter_version_check__/
master
'
,
'-n'
,
'1'
,
'--pretty=format:%ad'
,
'--date=iso'
))
{
}
else
if
(
remoteCommitDate
!=
null
&&
argsAre
(
'git'
,
'log'
,
'__flutter_version_check__/
$channel
'
,
'-n'
,
'1'
,
'--pretty=format:%ad'
,
'--date=iso'
))
{
return
success
(
remoteCommitDate
.
toString
());
return
success
(
remoteCommitDate
.
toString
());
}
}
...
@@ -438,7 +476,7 @@ void fakeData(
...
@@ -438,7 +476,7 @@ void fakeData(
<
String
>[
'git'
,
'rev-parse'
,
'--abbrev-ref'
,
'--symbolic'
,
'@{u}'
],
<
String
>[
'git'
,
'rev-parse'
,
'--abbrev-ref'
,
'--symbolic'
,
'@{u}'
],
workingDirectory:
anyNamed
(
'workingDirectory'
),
workingDirectory:
anyNamed
(
'workingDirectory'
),
environment:
anyNamed
(
'environment'
),
environment:
anyNamed
(
'environment'
),
)).
thenReturn
(
ProcessResult
(
101
,
0
,
'master'
,
''
));
)).
thenReturn
(
ProcessResult
(
101
,
0
,
channel
,
''
));
when
(
pm
.
runSync
(
when
(
pm
.
runSync
(
<
String
>[
'git'
,
'rev-parse'
,
'--abbrev-ref'
,
'HEAD'
],
<
String
>[
'git'
,
'rev-parse'
,
'--abbrev-ref'
,
'HEAD'
],
workingDirectory:
anyNamed
(
'workingDirectory'
),
workingDirectory:
anyNamed
(
'workingDirectory'
),
...
@@ -462,4 +500,5 @@ void fakeData(
...
@@ -462,4 +500,5 @@ void fakeData(
}
}
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
class
MockCache
extends
Mock
implements
Cache
{}
class
MockCache
extends
Mock
implements
Cache
{}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment