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
9805df89
Unverified
Commit
9805df89
authored
May 15, 2021
by
Jonah Williams
Committed by
GitHub
May 15, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove more mocks (#82592)
parent
a34713fb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
68 deletions
+87
-68
cache_test.dart
packages/flutter_tools/test/general.shard/cache_test.dart
+82
-67
fakes.dart
packages/flutter_tools/test/src/fakes.dart
+5
-1
No files found.
packages/flutter_tools/test/general.shard/cache_test.dart
View file @
9805df89
...
...
@@ -22,6 +22,7 @@ import 'package:mockito/mockito.dart';
import
'../src/common.dart'
;
import
'../src/context.dart'
;
import
'../src/fakes.dart'
;
const
FakeCommand
unameCommandForX64
=
FakeCommand
(
command:
<
String
>[
...
...
@@ -126,7 +127,7 @@ void main() {
throw
const
FileSystemException
(
'stamp write failed'
);
});
final
FakeSimpleArtifact
artifact
=
FakeSimpleArtifact
(
mockCache
);
await
artifact
.
update
(
MockArtifactUpdater
(),
logger
,
fileSystem
,
Mock
OperatingSystemUtils
());
await
artifact
.
update
(
FakeArtifactUpdater
(),
logger
,
fileSystem
,
Fake
OperatingSystemUtils
());
expect
(
logger
.
errorText
,
contains
(
'stamp write failed'
));
});
...
...
@@ -142,7 +143,7 @@ void main() {
when
(
mockCache
.
getArtifactDirectory
(
any
)).
thenReturn
(
artifactDir
);
when
(
mockCache
.
getDownloadDir
()).
thenReturn
(
downloadDir
);
final
FakeSimpleArtifact
artifact
=
FakeSimpleArtifact
(
mockCache
);
await
artifact
.
update
(
MockArtifactUpdater
(),
logger
,
fileSystem
,
Mock
OperatingSystemUtils
());
await
artifact
.
update
(
FakeArtifactUpdater
(),
logger
,
fileSystem
,
Fake
OperatingSystemUtils
());
expect
(
logger
.
errorText
,
contains
(
'No known version for the artifact name "fake"'
));
});
...
...
@@ -276,8 +277,7 @@ void main() {
final
CachedArtifact
artifact2
=
MockCachedArtifact
();
when
(
artifact1
.
isUpToDate
(
any
)).
thenAnswer
((
Invocation
_
)
=>
Future
<
bool
>.
value
(
false
));
when
(
artifact2
.
isUpToDate
(
any
)).
thenAnswer
((
Invocation
_
)
=>
Future
<
bool
>.
value
(
false
));
final
MockInternetAddress
address
=
MockInternetAddress
();
when
(
address
.
host
).
thenReturn
(
'storage.googleapis.com'
);
final
InternetAddress
address
=
(
await
InternetAddress
.
lookup
(
'storage.googleapis.com'
)).
first
;
when
(
artifact1
.
update
(
any
,
any
,
any
,
any
)).
thenThrow
(
SocketException
(
'Connection reset by peer'
,
address:
address
,
...
...
@@ -320,7 +320,7 @@ void main() {
});
testWithoutContext
(
'EngineCachedArtifact makes binary dirs readable and executable by all'
,
()
async
{
final
OperatingSystemUtils
operatingSystemUtils
=
Mock
OperatingSystemUtils
();
final
FakeOperatingSystemUtils
operatingSystemUtils
=
Fake
OperatingSystemUtils
();
final
MockCache
cache
=
MockCache
();
final
FileSystem
fileSystem
=
MemoryFileSystem
.
test
();
final
Directory
artifactDir
=
fileSystem
.
systemTempDirectory
.
createTempSync
(
'flutter_cache_test_artifact.'
);
...
...
@@ -338,7 +338,7 @@ void main() {
],
requiredArtifacts:
DevelopmentArtifact
.
universal
,
);
await
artifact
.
updateInner
(
Mock
ArtifactUpdater
(),
fileSystem
,
operatingSystemUtils
);
await
artifact
.
updateInner
(
Fake
ArtifactUpdater
(),
fileSystem
,
operatingSystemUtils
);
final
Directory
dir
=
fileSystem
.
systemTempDirectory
.
listSync
(
recursive:
true
)
.
whereType
<
Directory
>()
...
...
@@ -346,11 +346,11 @@ void main() {
expect
(
dir
,
isNotNull
);
expect
(
dir
.
path
,
artifactDir
.
childDirectory
(
'bin_dir'
).
path
);
verify
(
operatingSystemUtils
.
chmod
(
argThat
(
hasPath
(
dir
.
path
)),
'a+r,a+x'
)
);
expect
(
operatingSystemUtils
.
chmods
,
<
List
<
String
>>[<
String
>[
'/.tmp_rand0/flutter_cache_test_artifact.rand0/bin_dir'
,
'a+r,a+x'
]]
);
});
testWithoutContext
(
'EngineCachedArtifact removes unzipped FlutterMacOS.framework before replacing'
,
()
async
{
final
OperatingSystemUtils
operatingSystemUtils
=
Mock
OperatingSystemUtils
();
final
OperatingSystemUtils
operatingSystemUtils
=
Fake
OperatingSystemUtils
();
final
MockCache
cache
=
MockCache
();
final
FileSystem
fileSystem
=
MemoryFileSystem
.
test
();
final
Directory
artifactDir
=
fileSystem
.
systemTempDirectory
.
createTempSync
(
'flutter_cache_test_artifact.'
);
...
...
@@ -371,7 +371,7 @@ void main() {
],
requiredArtifacts:
DevelopmentArtifact
.
universal
,
);
await
artifact
.
updateInner
(
Mock
ArtifactUpdater
(),
fileSystem
,
operatingSystemUtils
);
await
artifact
.
updateInner
(
Fake
ArtifactUpdater
(),
fileSystem
,
operatingSystemUtils
);
expect
(
unzippedFramework
,
exists
);
expect
(
staleFile
,
isNot
(
exists
));
});
...
...
@@ -438,19 +438,18 @@ void main() {
fileSystem:
fileSystem
,
processManager:
FakeProcessManager
.
any
(),
);
final
MockVersionedPackageResolver
mockPackageResolver
=
Mock
VersionedPackageResolver
();
final
FakeVersionedPackageResolver
packageResolver
=
Fake
VersionedPackageResolver
();
final
FlutterRunnerDebugSymbols
flutterRunnerDebugSymbols
=
FlutterRunnerDebugSymbols
(
cache
,
packageResolver:
mockP
ackageResolver
,
packageResolver:
p
ackageResolver
,
platform:
FakePlatform
(
operatingSystem:
'linux'
),
);
when
(
mockPackageResolver
.
resolveUrl
(
any
,
any
)).
thenReturn
(
''
);
await
flutterRunnerDebugSymbols
.
updateInner
(
MockArtifactUpdater
(),
fileSystem
,
Mock
OperatingSystemUtils
());
await
flutterRunnerDebugSymbols
.
updateInner
(
FakeArtifactUpdater
(),
fileSystem
,
Fake
OperatingSystemUtils
());
verifyInOrder
(<
void
>[
mockPackageResolver
.
resolveUrl
(
'fuchsia-debug-symbols-x64'
,
any
)
,
mockPackageResolver
.
resolveUrl
(
'fuchsia-debug-symbols-arm64'
,
any
)
,
expect
(
packageResolver
.
resolved
,
<
List
<
String
>
>[
<
String
>[
'fuchsia-debug-symbols-x64'
,
null
]
,
<
String
>[
'fuchsia-debug-symbols-arm64'
,
null
]
,
]);
});
...
...
@@ -659,7 +658,7 @@ void main() {
logger:
logger
,
fileSystem:
fileSystem
,
platform:
FakePlatform
(),
osUtils:
Mock
OperatingSystemUtils
(),
osUtils:
Fake
OperatingSystemUtils
(),
rootOverride:
fileSystem
.
currentDirectory
,
);
final
File
toolStampFile
=
fileSystem
.
file
(
'bin/cache/flutter_tools.stamp'
);
...
...
@@ -687,7 +686,7 @@ void main() {
logger:
logger
,
fileSystem:
fileSystem
,
platform:
FakePlatform
(),
osUtils:
Mock
OperatingSystemUtils
(),
osUtils:
Fake
OperatingSystemUtils
(),
rootOverride:
fileSystem
.
currentDirectory
,
);
final
File
toolStampFile
=
fileSystem
.
file
(
'bin/cache/flutter_tools.stamp'
);
...
...
@@ -714,7 +713,7 @@ void main() {
logger:
logger
,
fileSystem:
fileSystem
,
platform:
FakePlatform
(),
osUtils:
Mock
OperatingSystemUtils
(),
osUtils:
Fake
OperatingSystemUtils
(),
rootOverride:
fileSystem
.
currentDirectory
,
);
...
...
@@ -725,46 +724,40 @@ void main() {
testWithoutContext
(
'FlutterWebSdk deletes previous directory contents'
,
()
{
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
();
final
Directory
webStuff
=
fileSystem
.
directory
(
'web-stuff'
);
final
MockCache
cache
=
MockCache
();
final
MockArtifactUpdater
artifactUpdater
=
Mock
ArtifactUpdater
();
final
Cache
cache
=
Cache
.
test
(
processManager:
FakeProcessManager
.
any
(),
fileSystem:
fileSystem
);
final
Directory
webCacheDirectory
=
cache
.
getWebSdkDirectory
();
final
FakeArtifactUpdater
artifactUpdater
=
Fake
ArtifactUpdater
();
final
FlutterWebSdk
webSdk
=
FlutterWebSdk
(
cache
,
platform:
FakePlatform
(
operatingSystem:
'linux'
));
when
(
cache
.
getWebSdkDirectory
()).
thenReturn
(
webStuff
);
when
(
artifactUpdater
.
downloadZipArchive
(
'Downloading Web SDK...'
,
any
,
any
))
.
thenAnswer
((
Invocation
invocation
)
async
{
final
Directory
location
=
invocation
.
positionalArguments
[
2
]
as
Directory
;
artifactUpdater
.
onDownloadZipArchive
=
(
String
message
,
Uri
uri
,
Directory
location
)
{
location
.
createSync
(
recursive:
true
);
location
.
childFile
(
'foo'
).
createSync
();
})
;
web
Stuff
.
childFile
(
'bar'
).
createSync
(
recursive:
true
);
}
;
web
CacheDirectory
.
childFile
(
'bar'
).
createSync
(
recursive:
true
);
webSdk
.
updateInner
(
artifactUpdater
,
fileSystem
,
Mock
OperatingSystemUtils
());
webSdk
.
updateInner
(
artifactUpdater
,
fileSystem
,
Fake
OperatingSystemUtils
());
expect
(
web
Stuff
.
childFile
(
'foo'
),
exists
);
expect
(
web
Stuff
.
childFile
(
'bar'
),
isNot
(
exists
));
expect
(
web
CacheDirectory
.
childFile
(
'foo'
),
exists
);
expect
(
web
CacheDirectory
.
childFile
(
'bar'
),
isNot
(
exists
));
});
testWithoutContext
(
'FlutterWebSdk uses tryToDelete to handle directory edge cases'
,
()
async
{
final
FileExceptionHandler
handler
=
FileExceptionHandler
();
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
(
opHandle:
handler
.
opHandle
);
final
Directory
webStuff
=
fileSystem
.
directory
(
'web-stuff'
);
final
MockCache
cache
=
MockCache
();
final
MockArtifactUpdater
artifactUpdater
=
Mock
ArtifactUpdater
();
final
Cache
cache
=
Cache
.
test
(
processManager:
FakeProcessManager
.
any
(),
fileSystem:
fileSystem
);
final
Directory
webCacheDirectory
=
cache
.
getWebSdkDirectory
();
final
FakeArtifactUpdater
artifactUpdater
=
Fake
ArtifactUpdater
();
final
FlutterWebSdk
webSdk
=
FlutterWebSdk
(
cache
,
platform:
FakePlatform
(
operatingSystem:
'linux'
));
when
(
cache
.
getWebSdkDirectory
()).
thenReturn
(
webStuff
);
when
(
artifactUpdater
.
downloadZipArchive
(
'Downloading Web SDK...'
,
any
,
any
))
.
thenAnswer
((
Invocation
invocation
)
async
{
final
Directory
location
=
invocation
.
positionalArguments
[
2
]
as
Directory
;
artifactUpdater
.
onDownloadZipArchive
=
(
String
message
,
Uri
uri
,
Directory
location
)
{
location
.
createSync
(
recursive:
true
);
location
.
childFile
(
'foo'
).
createSync
();
})
;
web
Stuff
.
childFile
(
'bar'
).
createSync
(
recursive:
true
);
handler
.
addError
(
web
Stuff
,
FileSystemOp
.
delete
,
const
FileSystemException
(
''
,
''
,
OSError
(
''
,
2
)));
}
;
web
CacheDirectory
.
childFile
(
'bar'
).
createSync
(
recursive:
true
);
handler
.
addError
(
web
CacheDirectory
,
FileSystemOp
.
delete
,
const
FileSystemException
(
''
,
''
,
OSError
(
''
,
2
)));
await
expectLater
(()
=>
webSdk
.
updateInner
(
artifactUpdater
,
fileSystem
,
Mock
OperatingSystemUtils
()),
throwsToolExit
(
message:
RegExp
(
'The Flutter tool tried to delete the file or directory
web-stuff
but was unable to'
),
await
expectLater
(()
=>
webSdk
.
updateInner
(
artifactUpdater
,
fileSystem
,
Fake
OperatingSystemUtils
()),
throwsToolExit
(
message:
RegExp
(
'The Flutter tool tried to delete the file or directory
cache/bin/cache/flutter_web_sdk
but was unable to'
),
));
});
...
...
@@ -776,7 +769,7 @@ void main() {
fileSystem:
fileSystem
,
logger:
logger
,
platform:
FakePlatform
(),
osUtils:
Mock
OperatingSystemUtils
()
osUtils:
Fake
OperatingSystemUtils
()
);
final
File
file
=
fileSystem
.
file
(
'stamp'
);
cache
.
stampFile
=
file
;
...
...
@@ -800,7 +793,7 @@ void main() {
fileSystem:
fileSystem
,
logger:
logger
,
platform:
FakePlatform
(),
osUtils:
Mock
OperatingSystemUtils
()
osUtils:
Fake
OperatingSystemUtils
()
);
final
File
file
=
fileSystem
.
file
(
'stamp'
)..
writeAsStringSync
(
'ABC '
);
...
...
@@ -816,7 +809,7 @@ void main() {
final
PubDependencies
pubDependencies
=
PubDependencies
(
flutterRoot:
()
=>
''
,
logger:
logger
,
pub:
()
=>
Mock
Pub
(),
pub:
()
=>
Fake
Pub
(),
);
expect
(
await
pubDependencies
.
isUpToDate
(
fileSystem
),
false
);
// no package config
...
...
@@ -854,19 +847,16 @@ void main() {
testWithoutContext
(
'PubDependencies updates via pub get'
,
()
async
{
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
();
final
MockPub
pub
=
Mock
Pub
();
final
FakePub
pub
=
Fake
Pub
();
final
PubDependencies
pubDependencies
=
PubDependencies
(
flutterRoot:
()
=>
''
,
logger:
logger
,
pub:
()
=>
pub
,
);
await
pubDependencies
.
update
(
MockArtifactUpdater
(),
logger
,
fileSystem
,
Mock
OperatingSystemUtils
());
await
pubDependencies
.
update
(
FakeArtifactUpdater
(),
logger
,
fileSystem
,
Fake
OperatingSystemUtils
());
verify
(
pub
.
get
(
context:
PubContext
.
pubGet
,
directory:
'packages/flutter_tools'
,
)).
called
(
1
);
expect
(
pub
.
calledGet
,
1
);
});
group
(
'AndroidMavenArtifacts'
,
()
{
...
...
@@ -897,7 +887,7 @@ void main() {
gradleWrapperDir
.
childFile
(
'gradlew'
).
writeAsStringSync
(
'irrelevant'
);
gradleWrapperDir
.
childFile
(
'gradlew.bat'
).
writeAsStringSync
(
'irrelevant'
);
await
mavenArtifacts
.
update
(
MockArtifactUpdater
(),
BufferLogger
.
test
(),
memoryFileSystem
,
Mock
OperatingSystemUtils
());
await
mavenArtifacts
.
update
(
FakeArtifactUpdater
(),
BufferLogger
.
test
(),
memoryFileSystem
,
Fake
OperatingSystemUtils
());
expect
(
await
mavenArtifacts
.
isUpToDate
(
memoryFileSystem
),
isFalse
);
expect
(
fakeAndroidSdk
.
reinitialized
,
true
);
...
...
@@ -922,7 +912,7 @@ void main() {
final
AndroidMavenArtifacts
mavenArtifacts
=
AndroidMavenArtifacts
(
cache
,
platform:
FakePlatform
(
operatingSystem:
'linux'
));
expect
(
await
mavenArtifacts
.
isUpToDate
(
memoryFileSystem
),
isFalse
);
await
mavenArtifacts
.
update
(
MockArtifactUpdater
(),
BufferLogger
.
test
(),
memoryFileSystem
,
Mock
OperatingSystemUtils
());
await
mavenArtifacts
.
update
(
FakeArtifactUpdater
(),
BufferLogger
.
test
(),
memoryFileSystem
,
Fake
OperatingSystemUtils
());
expect
(
await
mavenArtifacts
.
isUpToDate
(
memoryFileSystem
),
isFalse
);
},
overrides:
<
Type
,
Generator
>{
...
...
@@ -982,14 +972,28 @@ class FakeDownloadedArtifact extends CachedArtifact {
Future
<
void
>
updateInner
(
ArtifactUpdater
artifactUpdater
,
FileSystem
fileSystem
,
OperatingSystemUtils
operatingSystemUtils
)
async
{
}
}
class
MockArtifactUpdater
extends
Mock
implements
ArtifactUpdater
{}
class
MockCachedArtifact
extends
Mock
implements
CachedArtifact
{}
class
MockIosUsbArtifacts
extends
Mock
implements
IosUsbArtifacts
{}
class
MockInternetAddress
extends
Mock
implements
InternetAddress
{}
class
MockCache
extends
Mock
implements
Cache
{}
class
MockOperatingSystemUtils
extends
Mock
implements
OperatingSystemUtils
{}
class
MockVersionedPackageResolver
extends
Mock
implements
VersionedPackageResolver
{}
class
MockPub
extends
Mock
implements
Pub
{}
class
FakeVersionedPackageResolver
extends
Fake
implements
VersionedPackageResolver
{
final
List
<
List
<
String
>>
resolved
=
<
List
<
String
>>[];
@override
String
resolveUrl
(
String
packageName
,
String
version
)
{
resolved
.
add
(<
String
>[
packageName
,
version
]);
return
''
;
}
}
class
FakePub
extends
Fake
implements
Pub
{
int
calledGet
=
0
;
@override
Future
<
void
>
get
({
PubContext
context
,
String
directory
,
bool
skipIfAbsent
=
false
,
bool
upgrade
=
false
,
bool
offline
=
false
,
bool
generateSyntheticPackage
=
false
,
String
flutterRootOverride
,
bool
checkUpToDate
=
false
})
async
{
calledGet
+=
1
;
}
}
class
FakeCache
extends
Cache
{
FakeCache
({
...
...
@@ -1022,8 +1026,19 @@ class FakeAndroidSdk extends Fake implements AndroidSdk {
}
class
FakeArtifactUpdater
extends
Fake
implements
ArtifactUpdater
{
void
Function
(
String
,
Uri
,
Directory
)
onDownloadZipArchive
;
void
Function
(
String
,
Uri
,
Directory
)
onDownloadZipTarball
;
@override
Future
<
void
>
downloadZippedTarball
(
String
message
,
Uri
url
,
Directory
location
)
async
{
return
;
onDownloadZipTarball
?.
call
(
message
,
url
,
location
)
;
}
@override
Future
<
void
>
downloadZipArchive
(
String
message
,
Uri
url
,
Directory
location
)
async
{
onDownloadZipArchive
?.
call
(
message
,
url
,
location
);
}
@override
void
removeDownloadedFiles
()
{
}
}
packages/flutter_tools/test/src/fakes.dart
View file @
9805df89
...
...
@@ -498,6 +498,8 @@ class FakeStatusLogger extends DelegatingLogger {
class
FakeOperatingSystemUtils
extends
Fake
implements
OperatingSystemUtils
{
FakeOperatingSystemUtils
({
this
.
hostPlatform
=
HostPlatform
.
linux_x64
});
final
List
<
List
<
String
>>
chmods
=
<
List
<
String
>>[];
@override
void
makeExecutable
(
File
file
)
{
}
...
...
@@ -505,7 +507,9 @@ class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
HostPlatform
hostPlatform
=
HostPlatform
.
linux_x64
;
@override
void
chmod
(
FileSystemEntity
entity
,
String
mode
)
{
}
void
chmod
(
FileSystemEntity
entity
,
String
mode
)
{
chmods
.
add
(<
String
>[
entity
.
path
,
mode
]);
}
@override
File
?
which
(
String
execName
)
=>
null
;
...
...
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