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
6b92a93c
Unverified
Commit
6b92a93c
authored
May 27, 2021
by
Jenn Magder
Committed by
GitHub
May 27, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove more mocks from error_handling_io and attach_test (#83504)
parent
5c92c5f2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
56 deletions
+74
-56
attach_test.dart
...utter_tools/test/commands.shard/hermetic/attach_test.dart
+59
-36
error_handling_io_test.dart
...tools/test/general.shard/base/error_handling_io_test.dart
+15
-20
No files found.
packages/flutter_tools/test/commands.shard/hermetic/attach_test.dart
View file @
6b92a93c
...
...
@@ -9,6 +9,7 @@ import 'dart:io';
import
'package:file/memory.dart'
;
import
'package:flutter_tools/src/android/android_device.dart'
;
import
'package:flutter_tools/src/artifacts.dart'
;
import
'package:flutter_tools/src/base/common.dart'
;
import
'package:flutter_tools/src/base/dds.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
...
...
@@ -20,6 +21,7 @@ import 'package:flutter_tools/src/commands/attach.dart';
import
'package:flutter_tools/src/device.dart'
;
import
'package:flutter_tools/src/device_port_forwarder.dart'
;
import
'package:flutter_tools/src/globals_null_migrated.dart'
as
globals
;
import
'package:flutter_tools/src/ios/application_package.dart'
;
import
'package:flutter_tools/src/ios/devices.dart'
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:flutter_tools/src/resident_runner.dart'
;
...
...
@@ -77,14 +79,14 @@ void main() {
FakeDeviceLogReader
fakeLogReader
;
MockPortForwarder
portForwarder
;
MockDartDevelopmentService
mock
Dds
;
FakeDartDevelopmentService
fake
Dds
;
MockAndroidDevice
device
;
setUp
(()
{
fakeLogReader
=
FakeDeviceLogReader
();
portForwarder
=
MockPortForwarder
();
device
=
MockAndroidDevice
();
mockDds
=
Mock
DartDevelopmentService
();
fakeDds
=
Fake
DartDevelopmentService
();
when
(
device
.
portForwarder
)
.
thenReturn
(
portForwarder
);
when
(
portForwarder
.
forward
(
devicePort
,
hostPort:
anyNamed
(
'hostPort'
)))
...
...
@@ -93,12 +95,7 @@ void main() {
.
thenReturn
(<
ForwardedPort
>[
ForwardedPort
(
hostPort
,
devicePort
)]);
when
(
portForwarder
.
unforward
(
any
))
.
thenAnswer
((
_
)
async
{});
when
(
device
.
dds
).
thenReturn
(
mockDds
);
final
Completer
<
void
>
noopCompleter
=
Completer
<
void
>();
when
(
mockDds
.
startDartDevelopmentService
(
any
,
any
,
false
,
any
,
logger:
anyNamed
(
'logger'
))).
thenReturn
(
null
);
when
(
mockDds
.
uri
).
thenReturn
(
Uri
.
parse
(
'http://localhost:8181'
));
when
(
mockDds
.
done
).
thenAnswer
((
_
)
=>
noopCompleter
.
future
);
when
(
device
.
dds
).
thenReturn
(
fakeDds
);
// We cannot add the device to a device manager because that is
// only enabled by the context of each testUsingContext call.
//
...
...
@@ -293,16 +290,14 @@ void main() {
const
int
hostPort
=
42
;
final
FakeDeviceLogReader
fakeLogReader
=
FakeDeviceLogReader
();
final
MockPortForwarder
portForwarder
=
MockPortForwarder
();
final
MockDartDevelopmentService
mockDds
=
Mock
DartDevelopmentService
();
final
FakeDartDevelopmentService
fakeDds
=
Fake
DartDevelopmentService
();
final
MockAndroidDevice
device
=
MockAndroidDevice
();
final
MockHotRunner
mockHotRunner
=
MockHotRunner
();
final
MockHotRunnerFactory
mockHotRunnerFactory
=
MockHotRunnerFactory
();
when
(
device
.
portForwarder
)
.
thenReturn
(
portForwarder
);
when
(
device
.
dds
)
.
thenReturn
(
mockDds
);
final
Completer
<
void
>
noopCompleter
=
Completer
<
void
>();
when
(
mockDds
.
done
).
thenAnswer
((
_
)
=>
noopCompleter
.
future
);
.
thenReturn
(
fakeDds
);
when
(
portForwarder
.
forward
(
devicePort
,
hostPort:
anyNamed
(
'hostPort'
)))
.
thenAnswer
((
_
)
async
=>
hostPort
);
when
(
portForwarder
.
forwardedPorts
)
...
...
@@ -324,8 +319,6 @@ void main() {
)).
thenReturn
(
mockHotRunner
);
when
(
mockHotRunner
.
exited
).
thenReturn
(
false
);
when
(
mockHotRunner
.
isWaitingForObservatory
).
thenReturn
(
false
);
when
(
mockDds
.
startDartDevelopmentService
(
any
,
any
,
false
,
any
,
logger:
anyNamed
(
'logger'
))).
thenReturn
(
null
);
when
(
mockDds
.
uri
).
thenReturn
(
Uri
.
parse
(
'http://localhost:8181'
));
testDeviceManager
.
addDevice
(
device
);
when
(
device
.
getLogReader
(
includePastLogs:
anyNamed
(
'includePastLogs'
)))
...
...
@@ -378,18 +371,10 @@ void main() {
const
int
hostPort
=
42
;
final
FakeDeviceLogReader
fakeLogReader
=
FakeDeviceLogReader
();
final
MockPortForwarder
portForwarder
=
MockPortForwarder
();
final
MockDartDevelopmentService
mockDds
=
Mock
DartDevelopmentService
();
final
MockIOSDevice
device
=
MockIOSDevice
(
);
final
FakeDartDevelopmentService
mockDds
=
Fake
DartDevelopmentService
();
final
FakeIOSDevice
device
=
FakeIOSDevice
(
dds:
mockDds
,
portForwarder:
portForwarder
,
logReader:
fakeLogReader
);
final
MockHotRunner
mockHotRunner
=
MockHotRunner
();
final
MockHotRunnerFactory
mockHotRunnerFactory
=
MockHotRunnerFactory
();
when
(
device
.
portForwarder
)
.
thenReturn
(
portForwarder
);
when
(
device
.
dds
)
.
thenReturn
(
mockDds
);
final
Completer
<
void
>
noopCompleter
=
Completer
<
void
>();
when
(
mockDds
.
done
).
thenAnswer
((
_
)
=>
noopCompleter
.
future
);
when
(
device
.
getLogReader
(
includePastLogs:
anyNamed
(
'includePastLogs'
)))
.
thenAnswer
((
_
)
=>
fakeLogReader
);
when
(
portForwarder
.
forward
(
devicePort
,
hostPort:
anyNamed
(
'hostPort'
)))
.
thenAnswer
((
_
)
async
=>
hostPort
);
when
(
portForwarder
.
forwardedPorts
)
...
...
@@ -411,8 +396,6 @@ void main() {
)).
thenReturn
(
mockHotRunner
);
when
(
mockHotRunner
.
exited
).
thenReturn
(
false
);
when
(
mockHotRunner
.
isWaitingForObservatory
).
thenReturn
(
false
);
when
(
mockDds
.
startDartDevelopmentService
(
any
,
any
,
false
,
any
,
logger:
anyNamed
(
'logger'
))).
thenReturn
(
null
);
when
(
mockDds
.
uri
).
thenReturn
(
Uri
.
parse
(
'http://localhost:8181'
));
testDeviceManager
.
addDevice
(
device
);
...
...
@@ -445,7 +428,7 @@ void main() {
setUp
(()
{
portForwarder
=
MockPortForwarder
();
final
MockDartDevelopmentService
mockDds
=
Mock
DartDevelopmentService
();
final
FakeDartDevelopmentService
fakeDds
=
Fake
DartDevelopmentService
();
device
=
MockAndroidDevice
();
when
(
device
.
portForwarder
)
...
...
@@ -457,12 +440,7 @@ void main() {
when
(
portForwarder
.
unforward
(
any
))
.
thenAnswer
((
_
)
async
{});
when
(
device
.
dds
)
.
thenReturn
(
mockDds
);
when
(
mockDds
.
startDartDevelopmentService
(
any
,
any
,
any
,
any
,
logger:
anyNamed
(
'logger'
)))
.
thenReturn
(
null
);
when
(
mockDds
.
uri
).
thenReturn
(
Uri
.
parse
(
'http://localhost:8181'
));
final
Completer
<
void
>
noopCompleter
=
Completer
<
void
>();
when
(
mockDds
.
done
).
thenAnswer
((
_
)
=>
noopCompleter
.
future
);
.
thenReturn
(
fakeDds
);
});
testUsingContext
(
'succeeds in ipv4 mode'
,
()
async
{
...
...
@@ -596,7 +574,7 @@ void main() {
});
testUsingContext
(
'fails when targeted device is not Android with --device-user'
,
()
async
{
final
MockIOSDevice
device
=
Mock
IOSDevice
();
final
FakeIOSDevice
device
=
Fake
IOSDevice
();
testDeviceManager
.
addDevice
(
device
);
expect
(
createTestCommandRunner
(
AttachCommand
()).
run
(<
String
>[
'attach'
,
...
...
@@ -718,7 +696,6 @@ void main() {
class
MockHotRunner
extends
Mock
implements
HotRunner
{}
class
MockHotRunnerFactory
extends
Mock
implements
HotRunnerFactory
{}
class
MockIOSDevice
extends
Mock
implements
IOSDevice
{}
class
MockPortForwarder
extends
Mock
implements
DevicePortForwarder
{}
class
StreamLogger
extends
Logger
{
...
...
@@ -927,7 +904,23 @@ class TestHotRunnerFactory extends HotRunnerFactory {
}
}
class
MockDartDevelopmentService
extends
Mock
implements
DartDevelopmentService
{}
class
FakeDartDevelopmentService
extends
Fake
implements
DartDevelopmentService
{
@override
Future
<
void
>
get
done
=>
noopCompleter
.
future
;
final
Completer
<
void
>
noopCompleter
=
Completer
<
void
>();
@override
Future
<
void
>
startDartDevelopmentService
(
Uri
observatoryUri
,
int
hostPort
,
bool
ipv6
,
bool
disableServiceAuthCodes
,
{
@required
Logger
logger
,
})
async
{}
@override
Uri
get
uri
=>
Uri
.
parse
(
'http://localhost:8181'
);
}
class
MockAndroidDevice
extends
Mock
implements
AndroidDevice
{
@override
...
...
@@ -945,3 +938,33 @@ class MockAndroidDevice extends Mock implements AndroidDevice {
@override
bool
isSupportedForProject
(
FlutterProject
flutterProject
)
=>
true
;
}
class
FakeIOSDevice
extends
Fake
implements
IOSDevice
{
FakeIOSDevice
({
this
.
dds
,
this
.
portForwarder
,
this
.
logReader
});
@override
final
DevicePortForwarder
portForwarder
;
@override
final
DartDevelopmentService
dds
;
final
DeviceLogReader
logReader
;
@override
DeviceLogReader
getLogReader
({
IOSApp
app
,
bool
includePastLogs
=
false
,
})
=>
logReader
;
@override
OverrideArtifacts
get
artifactOverrides
=>
null
;
@override
final
String
name
=
'name'
;
@override
Future
<
TargetPlatform
>
get
targetPlatform
async
=>
TargetPlatform
.
ios
;
@override
final
PlatformType
platformType
=
PlatformType
.
ios
;
}
packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart
View file @
6b92a93c
...
...
@@ -798,44 +798,39 @@ void main() {
group
(
'toString() gives toString() of delegate'
,
()
{
testWithoutContext
(
'ErrorHandlingFileSystem'
,
()
{
final
M
ockFileSystem
mockFileSystem
=
MockFileSystem
();
final
M
emoryFileSystem
delegate
=
MemoryFileSystem
.
test
();
final
FileSystem
fs
=
ErrorHandlingFileSystem
(
delegate:
mockFileSystem
,
delegate:
delegate
,
platform:
const
LocalPlatform
(),
);
expect
(
mockFileSystem
.
toString
(),
isNotNull
);
expect
(
fs
.
toString
(),
equals
(
mockFileSystem
.
toString
()
));
expect
(
delegate
.
toString
(),
isNotNull
);
expect
(
fs
.
toString
(),
delegate
.
toString
(
));
});
testWithoutContext
(
'ErrorHandlingFile'
,
()
{
final
M
ockFileSystem
mockFileSystem
=
MockFileSystem
();
final
M
emoryFileSystem
delegate
=
MemoryFileSystem
.
test
();
final
FileSystem
fs
=
ErrorHandlingFileSystem
(
delegate:
mockFileSystem
,
delegate:
delegate
,
platform:
const
LocalPlatform
(),
);
final
MockFile
mockFile
=
MockFile
();
when
(
mockFileSystem
.
file
(
any
)).
thenReturn
(
mockFile
);
final
File
file
=
delegate
.
file
(
'file'
);
expect
(
mockF
ile
.
toString
(),
isNotNull
);
expect
(
fs
.
file
(
'file'
).
toString
(),
equals
(
mockFile
.
toString
()
));
expect
(
f
ile
.
toString
(),
isNotNull
);
expect
(
fs
.
file
(
'file'
).
toString
(),
file
.
toString
(
));
});
testWithoutContext
(
'ErrorHandlingDirectory'
,
()
{
final
M
ockFileSystem
mockFileSystem
=
MockFileSystem
();
final
M
emoryFileSystem
delegate
=
MemoryFileSystem
.
test
();
final
FileSystem
fs
=
ErrorHandlingFileSystem
(
delegate:
mockFileSystem
,
delegate:
delegate
,
platform:
const
LocalPlatform
(),
);
final
MockDirectory
mockDirectory
=
MockDirectory
();
when
(
mockFileSystem
.
directory
(
any
)).
thenReturn
(
mockDirectory
);
expect
(
mockDirectory
.
toString
(),
isNotNull
);
expect
(
fs
.
directory
(
'directory'
).
toString
(),
equals
(
mockDirectory
.
toString
()));
when
(
mockFileSystem
.
currentDirectory
).
thenReturn
(
mockDirectory
);
final
Directory
directory
=
delegate
.
directory
(
'directory'
)..
createSync
();
expect
(
fs
.
directory
(
'directory'
).
toString
(),
directory
.
toString
());
delegate
.
currentDirectory
=
directory
;
expect
(
fs
.
currentDirectory
.
toString
(),
equals
(
mockDirectory
.
toString
()
));
expect
(
fs
.
currentDirectory
.
toString
(),
delegate
.
currentDirectory
.
toString
(
));
expect
(
fs
.
currentDirectory
,
isA
<
ErrorHandlingDirectory
>());
});
});
...
...
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