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
b1ca7f41
Unverified
Commit
b1ca7f41
authored
Nov 15, 2019
by
Kate Lovett
Committed by
GitHub
Nov 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Gold to fallback on skipping comparator when offline (#44619)
parent
e3ae7fab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
14 deletions
+52
-14
flutter_goldens.dart
packages/flutter_goldens/lib/flutter_goldens.dart
+36
-14
flutter_goldens_test.dart
packages/flutter_goldens/test/flutter_goldens_test.dart
+16
-0
No files found.
packages/flutter_goldens/lib/flutter_goldens.dart
View file @
b1ca7f41
...
...
@@ -3,6 +3,7 @@
// found in the LICENSE file.
import
'dart:async'
;
import
'dart:io'
as
io
;
import
'dart:typed_data'
;
import
'package:file/file.dart'
;
...
...
@@ -30,11 +31,14 @@ Future<void> main(FutureOr<void> testMain()) async {
goldenFileComparator
=
await
FlutterSkiaGoldFileComparator
.
fromDefaultComparator
(
platform
);
}
else
if
(
FlutterPreSubmitFileComparator
.
isAvailableForEnvironment
(
platform
))
{
goldenFileComparator
=
await
FlutterPreSubmitFileComparator
.
fromDefaultComparator
(
platform
);
}
else
if
(
FlutterSkippingGoldenFileComparator
.
isAvailableForEnvironment
(
platform
)){
goldenFileComparator
=
FlutterSkippingGoldenFileComparator
.
fromDefaultComparator
();
}
else
if
(
FlutterSkippingGoldenFileComparator
.
isAvailableForEnvironment
(
platform
))
{
goldenFileComparator
=
FlutterSkippingGoldenFileComparator
.
fromDefaultComparator
(
'Golden file testing is unavailable on LUCI and some Cirrus shards.'
);
}
else
{
goldenFileComparator
=
await
FlutterLocalFileComparator
.
fromDefaultComparator
(
platform
);
}
await
testMain
();
}
...
...
@@ -74,7 +78,8 @@ Future<void> main(FutureOr<void> testMain()) async {
/// The [FlutterSkippingGoldenFileComparator] is utilized to skip tests outside
/// of the appropriate environments. Currently, tests executing in post-submit
/// on the LUCI build environment are skipped, as post-submit checks are done
/// on Cirrus.
/// on Cirrus. This comparator is also used when an internet connection is
/// unavailable.
abstract
class
FlutterGoldenFileComparator
extends
GoldenFileComparator
{
/// Creates a [FlutterGoldenFileComparator] that will resolve golden file
/// URIs relative to the specified [basedir], and retrieve golden baselines
...
...
@@ -349,7 +354,8 @@ class FlutterPreSubmitFileComparator extends FlutterGoldenFileComparator {
/// conditions that do not execute golden file tests.
///
/// Currently, this comparator is used in post-submit checks on LUCI and with
/// some Cirrus shards that do not run framework tests.
/// some Cirrus shards that do not run framework tests. This comparator is also
/// used when an internet connection is not available for contacting Gold.
///
/// See also:
///
...
...
@@ -370,25 +376,32 @@ class FlutterSkippingGoldenFileComparator extends FlutterGoldenFileComparator {
FlutterSkippingGoldenFileComparator
(
final
Uri
basedir
,
final
SkiaGoldClient
skiaClient
,
)
:
super
(
basedir
,
skiaClient
);
this
.
reason
,
)
:
assert
(
reason
!=
null
),
super
(
basedir
,
skiaClient
);
/// Describes the reason for using the [FlutterSkippingGoldenFileComparator].
///
/// Cannot be null.
final
String
reason
;
/// Creates a new [FlutterSkippingGoldenFileComparator] that mirrors the
/// relative path resolution of the default [goldenFileComparator].
static
FlutterSkippingGoldenFileComparator
fromDefaultComparator
({
static
FlutterSkippingGoldenFileComparator
fromDefaultComparator
(
String
reason
,
{
LocalFileComparator
defaultComparator
,
})
{
defaultComparator
??=
goldenFileComparator
;
const
FileSystem
fs
=
LocalFileSystem
();
final
Uri
basedir
=
defaultComparator
.
basedir
;
final
SkiaGoldClient
skiaClient
=
SkiaGoldClient
(
fs
.
directory
(
basedir
));
return
FlutterSkippingGoldenFileComparator
(
basedir
,
skiaClient
);
return
FlutterSkippingGoldenFileComparator
(
basedir
,
skiaClient
,
reason
);
}
@override
Future
<
bool
>
compare
(
Uint8List
imageBytes
,
Uri
golden
)
async
{
print
(
'Skipping "
$golden
" test : Golden file testing is unavailable on LUCI and '
'some Cirrus shards.'
'Skipping "
$golden
" test :
$reason
'
);
return
true
;
}
...
...
@@ -451,16 +464,16 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
/// Creates a new [FlutterLocalFileComparator] that mirrors the
/// relative path resolution of the default [goldenFileComparator].
///
/// The [goldens]
and [defaultComparator] parameters are visible for testing
/// purposes only.
/// The [goldens]
, [defaultComparator], and [baseDirectory] parameters are
///
visible for testing
purposes only.
static
Future
<
FlutterGoldenFileComparator
>
fromDefaultComparator
(
final
Platform
platform
,
{
SkiaGoldClient
goldens
,
LocalFileComparator
defaultComparator
,
Directory
baseDirectory
,
})
async
{
defaultComparator
??=
goldenFileComparator
;
final
Directory
baseDirectory
=
FlutterGoldenFileComparator
.
getBaseDirectory
(
baseDirectory
??
=
FlutterGoldenFileComparator
.
getBaseDirectory
(
defaultComparator
,
platform
,
);
...
...
@@ -470,7 +483,16 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
}
goldens
??=
SkiaGoldClient
(
baseDirectory
);
await
goldens
.
getExpectations
();
try
{
await
goldens
.
getExpectations
();
}
on
io
.
OSError
catch
(
_
)
{
return
FlutterSkippingGoldenFileComparator
(
baseDirectory
.
uri
,
goldens
,
'No network connection available for contacting Gold.'
,
);
}
return
FlutterLocalFileComparator
(
baseDirectory
.
uri
,
goldens
);
}
...
...
packages/flutter_goldens/test/flutter_goldens_test.dart
View file @
b1ca7f41
...
...
@@ -762,6 +762,20 @@ void main() {
shouldThrow
=
false
;
completer
.
complete
(
Future
<
bool
>.
value
(
false
));
});
test
(
'returns FlutterSkippingGoldenFileComparator when network connection is unavailable'
,
()
async
{
final
MockDirectory
mockDirectory
=
MockDirectory
();
when
(
mockDirectory
.
existsSync
()).
thenReturn
(
true
);
when
(
mockDirectory
.
uri
).
thenReturn
(
Uri
.
parse
(
'/flutter'
));
when
(
mockSkiaClient
.
getExpectations
())
.
thenAnswer
((
_
)
=>
throw
const
OSError
());
final
FlutterGoldenFileComparator
comparator
=
await
FlutterLocalFileComparator
.
fromDefaultComparator
(
platform
,
goldens:
mockSkiaClient
,
baseDirectory:
mockDirectory
,
);
expect
(
comparator
.
runtimeType
,
FlutterSkippingGoldenFileComparator
);
});
});
});
}
...
...
@@ -772,6 +786,8 @@ class MockSkiaGoldClient extends Mock implements SkiaGoldClient {}
class
MockLocalFileComparator
extends
Mock
implements
LocalFileComparator
{}
class
MockDirectory
extends
Mock
implements
Directory
{}
class
MockHttpClient
extends
Mock
implements
HttpClient
{}
class
MockHttpClientRequest
extends
Mock
implements
HttpClientRequest
{}
...
...
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