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
e4c84987
Unverified
Commit
e4c84987
authored
Jan 26, 2021
by
Dan Field
Committed by
GitHub
Jan 26, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no more mockito for fuchsia remote debug protocol (#74755)
parent
fa8bf67c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
239 additions
and
172 deletions
+239
-172
pubspec.yaml
packages/fuchsia_remote_debug_protocol/pubspec.yaml
+1
-2
fuchsia_remote_connection_test.dart
...e_debug_protocol/test/fuchsia_remote_connection_test.dart
+122
-77
dart_vm_test.dart
...sia_remote_debug_protocol/test/src/dart/dart_vm_test.dart
+62
-53
ssh_command_runner_test.dart
...ug_protocol/test/src/runners/ssh_command_runner_test.dart
+54
-40
No files found.
packages/fuchsia_remote_debug_protocol/pubspec.yaml
View file @
e4c84987
...
@@ -17,7 +17,6 @@ dependencies:
...
@@ -17,7 +17,6 @@ dependencies:
platform
:
3.0.0-nullsafety.4
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
platform
:
3.0.0-nullsafety.4
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
dev_dependencies
:
dev_dependencies
:
mockito
:
4.1.1
test
:
1.16.0-nullsafety.16
test
:
1.16.0-nullsafety.16
_fe_analyzer_shared
:
14.0.0
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
_fe_analyzer_shared
:
14.0.0
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
...
@@ -65,4 +64,4 @@ dev_dependencies:
...
@@ -65,4 +64,4 @@ dev_dependencies:
webkit_inspection_protocol
:
0.7.4
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
webkit_inspection_protocol
:
0.7.4
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
yaml
:
2.2.1
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
yaml
:
2.2.1
# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
# PUBSPEC CHECKSUM:
0795
# PUBSPEC CHECKSUM:
384f
packages/fuchsia_remote_debug_protocol/test/fuchsia_remote_connection_test.dart
View file @
e4c84987
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
import
'package:mockito/mockito.dart'
;
import
'package:vm_service/vm_service.dart'
as
vms
;
import
'package:vm_service/vm_service.dart'
as
vms
;
import
'package:test/fake.dart'
;
import
'package:fuchsia_remote_debug_protocol/fuchsia_remote_debug_protocol.dart'
;
import
'package:fuchsia_remote_debug_protocol/fuchsia_remote_debug_protocol.dart'
;
...
@@ -11,8 +11,8 @@ import 'common.dart';
...
@@ -11,8 +11,8 @@ import 'common.dart';
void
main
(
)
{
void
main
(
)
{
group
(
'FuchsiaRemoteConnection.connect'
,
()
{
group
(
'FuchsiaRemoteConnection.connect'
,
()
{
List
<
Mock
PortForwarder
>
forwardedPorts
;
List
<
Fake
PortForwarder
>
forwardedPorts
;
List
<
MockVmService
>
mock
VmServices
;
List
<
FakeVmService
>
fake
VmServices
;
List
<
Uri
>
uriConnections
;
List
<
Uri
>
uriConnections
;
setUp
(()
{
setUp
(()
{
...
@@ -58,31 +58,27 @@ void main() {
...
@@ -58,31 +58,27 @@ void main() {
},
},
];
];
forwardedPorts
=
<
Mock
PortForwarder
>[];
forwardedPorts
=
<
Fake
PortForwarder
>[];
mockVmServices
=
<
Mock
VmService
>[];
fakeVmServices
=
<
Fake
VmService
>[];
uriConnections
=
<
Uri
>[];
uriConnections
=
<
Uri
>[];
Future
<
vms
.
VmService
>
mock
VmConnectionFunction
(
Future
<
vms
.
VmService
>
fake
VmConnectionFunction
(
Uri
uri
,
{
Uri
uri
,
{
Duration
timeout
,
Duration
timeout
,
})
{
})
{
return
Future
<
vms
.
VmService
>(()
async
{
return
Future
<
vms
.
VmService
>(()
async
{
final
MockVmService
service
=
Mock
VmService
();
final
FakeVmService
service
=
Fake
VmService
();
mock
VmServices
.
add
(
service
);
fake
VmServices
.
add
(
service
);
uriConnections
.
add
(
uri
);
uriConnections
.
add
(
uri
);
when
(
service
.
callMethod
(
'_flutter.listViews'
))
service
.
flutterListViews
=
vms
.
Response
.
parse
(
flutterViewCannedResponses
[
uri
.
port
]);
// The local ports match the desired indices for now, so get the
// canned response from the URI port.
.
thenAnswer
((
_
)
=>
Future
<
vms
.
Response
>(
()
=>
vms
.
Response
.
parse
(
flutterViewCannedResponses
[
uri
.
port
])));
return
service
;
return
service
;
});
});
}
}
fuchsiaVmServiceConnectionFunction
=
mock
VmConnectionFunction
;
fuchsiaVmServiceConnectionFunction
=
fake
VmConnectionFunction
;
});
});
tearDown
(()
{
tearDown
(()
{
/// Most tests will
mock
out the port forwarding and connection
/// Most tests will
fake
out the port forwarding and connection
/// functions.
/// functions.
restoreFuchsiaPortForwardingFunction
();
restoreFuchsiaPortForwardingFunction
();
restoreVmServiceConnectionFunction
();
restoreVmServiceConnectionFunction
();
...
@@ -90,37 +86,33 @@ void main() {
...
@@ -90,37 +86,33 @@ void main() {
test
(
'end-to-end with three vm connections and flutter view query'
,
()
async
{
test
(
'end-to-end with three vm connections and flutter view query'
,
()
async
{
int
port
=
0
;
int
port
=
0
;
Future
<
PortForwarder
>
mock
PortForwardingFunction
(
Future
<
PortForwarder
>
fake
PortForwardingFunction
(
String
address
,
String
address
,
int
remotePort
,
[
int
remotePort
,
[
String
interface
=
'',
String
interface
=
'',
String
configFile
,
String
configFile
,
])
{
])
{
return
Future
<
PortForwarder
>(()
{
return
Future
<
PortForwarder
>(()
{
final
MockPortForwarder
pf
=
Mock
PortForwarder
();
final
FakePortForwarder
pf
=
Fake
PortForwarder
();
forwardedPorts
.
add
(
pf
);
forwardedPorts
.
add
(
pf
);
when
(
pf
.
port
).
thenReturn
(
port
++)
;
pf
.
port
=
port
++
;
when
(
pf
.
remotePort
).
thenReturn
(
remotePort
)
;
pf
.
remotePort
=
remotePort
;
return
pf
;
return
pf
;
});
});
}
}
fuchsiaPortForwardingFunction
=
mock
PortForwardingFunction
;
fuchsiaPortForwardingFunction
=
fake
PortForwardingFunction
;
final
MockSshCommandRunner
mockRunner
=
Mock
SshCommandRunner
();
final
FakeSshCommandRunner
fakeRunner
=
Fake
SshCommandRunner
();
// Adds some extra junk to make sure the strings will be cleaned up.
// Adds some extra junk to make sure the strings will be cleaned up.
when
(
mockRunner
.
run
(
argThat
(
startsWith
(
'/bin/find'
)))).
thenAnswer
(
fakeRunner
.
findResponse
=
<
String
>[
'/hub/blah/blah/blah/vmservice-port
\n
'
];
(
_
)
=>
Future
<
List
<
String
>>.
value
(
fakeRunner
.
lsResponse
=
<
String
>[
'123
\n\n\n
'
,
'456 '
,
'789'
];
<
String
>[
'/hub/blah/blah/blah/vmservice-port
\n
'
]));
fakeRunner
.
address
=
'fe80::8eae:4cff:fef4:9247'
;
when
(
mockRunner
.
run
(
argThat
(
startsWith
(
'/bin/ls'
)))).
thenAnswer
(
fakeRunner
.
interface
=
'eno1'
;
(
_
)
=>
Future
<
List
<
String
>>.
value
(
<
String
>[
'123
\n\n\n
'
,
'456 '
,
'789'
]));
when
(
mockRunner
.
address
).
thenReturn
(
'fe80::8eae:4cff:fef4:9247'
);
when
(
mockRunner
.
interface
).
thenReturn
(
'eno1'
);
final
FuchsiaRemoteConnection
connection
=
final
FuchsiaRemoteConnection
connection
=
await
FuchsiaRemoteConnection
.
connectWithSshCommandRunner
(
mock
Runner
);
await
FuchsiaRemoteConnection
.
connectWithSshCommandRunner
(
fake
Runner
);
// [
mock
PortForwardingFunction] will have returned three different
// [
fake
PortForwardingFunction] will have returned three different
// forwarded ports, incrementing the port each time by one. (Just a sanity
// forwarded ports, incrementing the port each time by one. (Just a sanity
// check that the forwarding port was called).
// check that the forwarding port was called).
expect
(
forwardedPorts
.
length
,
3
);
expect
(
forwardedPorts
.
length
,
3
);
...
@@ -132,7 +124,7 @@ void main() {
...
@@ -132,7 +124,7 @@ void main() {
expect
(
forwardedPorts
[
2
].
port
,
2
);
expect
(
forwardedPorts
[
2
].
port
,
2
);
// VMs should be accessed via localhost ports given by
// VMs should be accessed via localhost ports given by
// [
mock
PortForwardingFunction].
// [
fake
PortForwardingFunction].
expect
(
uriConnections
[
0
],
expect
(
uriConnections
[
0
],
Uri
(
scheme:
'ws'
,
host:
'[::1]'
,
port:
0
,
path:
'/ws'
));
Uri
(
scheme:
'ws'
,
host:
'[::1]'
,
port:
0
,
path:
'/ws'
));
expect
(
uriConnections
[
1
],
expect
(
uriConnections
[
1
],
...
@@ -154,44 +146,40 @@ void main() {
...
@@ -154,44 +146,40 @@ void main() {
// Ensure the ports are all closed after stop was called.
// Ensure the ports are all closed after stop was called.
await
connection
.
stop
();
await
connection
.
stop
();
verify
(
forwardedPorts
[
0
].
stop
()
);
expect
(
forwardedPorts
[
0
].
stopped
,
true
);
verify
(
forwardedPorts
[
1
].
stop
()
);
expect
(
forwardedPorts
[
1
].
stopped
,
true
);
verify
(
forwardedPorts
[
2
].
stop
()
);
expect
(
forwardedPorts
[
2
].
stopped
,
true
);
});
});
test
(
'end-to-end with three vms and remote open port'
,
()
async
{
test
(
'end-to-end with three vms and remote open port'
,
()
async
{
int
port
=
0
;
int
port
=
0
;
Future
<
PortForwarder
>
mock
PortForwardingFunction
(
Future
<
PortForwarder
>
fake
PortForwardingFunction
(
String
address
,
String
address
,
int
remotePort
,
[
int
remotePort
,
[
String
interface
=
'',
String
interface
=
'',
String
configFile
,
String
configFile
,
])
{
])
{
return
Future
<
PortForwarder
>(()
{
return
Future
<
PortForwarder
>(()
{
final
MockPortForwarder
pf
=
Mock
PortForwarder
();
final
FakePortForwarder
pf
=
Fake
PortForwarder
();
forwardedPorts
.
add
(
pf
);
forwardedPorts
.
add
(
pf
);
when
(
pf
.
port
).
thenReturn
(
port
++)
;
pf
.
port
=
port
++
;
when
(
pf
.
remotePort
).
thenReturn
(
remotePort
)
;
pf
.
remotePort
=
remotePort
;
when
(
pf
.
openPortAddress
).
thenReturn
(
'fe80::1:2%eno2'
)
;
pf
.
openPortAddress
=
'fe80::1:2%eno2'
;
return
pf
;
return
pf
;
});
});
}
}
fuchsiaPortForwardingFunction
=
mock
PortForwardingFunction
;
fuchsiaPortForwardingFunction
=
fake
PortForwardingFunction
;
final
MockSshCommandRunner
mockRunner
=
Mock
SshCommandRunner
();
final
FakeSshCommandRunner
fakeRunner
=
Fake
SshCommandRunner
();
// Adds some extra junk to make sure the strings will be cleaned up.
// Adds some extra junk to make sure the strings will be cleaned up.
when
(
mockRunner
.
run
(
argThat
(
startsWith
(
'/bin/find'
)))).
thenAnswer
(
fakeRunner
.
findResponse
=
<
String
>[
'/hub/blah/blah/blah/vmservice-port
\n
'
];
(
_
)
=>
Future
<
List
<
String
>>.
value
(
fakeRunner
.
lsResponse
=
<
String
>[
'123
\n\n\n
'
,
'456 '
,
'789'
];
<
String
>[
'/hub/blah/blah/blah/vmservice-port
\n
'
]));
fakeRunner
.
address
=
'fe80::8eae:4cff:fef4:9247'
;
when
(
mockRunner
.
run
(
argThat
(
startsWith
(
'/bin/ls'
)))).
thenAnswer
(
fakeRunner
.
interface
=
'eno1'
;
(
_
)
=>
Future
<
List
<
String
>>.
value
(
<
String
>[
'123
\n\n\n
'
,
'456 '
,
'789'
]));
when
(
mockRunner
.
address
).
thenReturn
(
'fe80::8eae:4cff:fef4:9247'
);
when
(
mockRunner
.
interface
).
thenReturn
(
'eno1'
);
final
FuchsiaRemoteConnection
connection
=
final
FuchsiaRemoteConnection
connection
=
await
FuchsiaRemoteConnection
.
connectWithSshCommandRunner
(
mock
Runner
);
await
FuchsiaRemoteConnection
.
connectWithSshCommandRunner
(
fake
Runner
);
// [
mock
PortForwardingFunction] will have returned three different
// [
fake
PortForwardingFunction] will have returned three different
// forwarded ports, incrementing the port each time by one. (Just a sanity
// forwarded ports, incrementing the port each time by one. (Just a sanity
// check that the forwarding port was called).
// check that the forwarding port was called).
expect
(
forwardedPorts
.
length
,
3
);
expect
(
forwardedPorts
.
length
,
3
);
...
@@ -203,7 +191,7 @@ void main() {
...
@@ -203,7 +191,7 @@ void main() {
expect
(
forwardedPorts
[
2
].
port
,
2
);
expect
(
forwardedPorts
[
2
].
port
,
2
);
// VMs should be accessed via the alternate adddress given by
// VMs should be accessed via the alternate adddress given by
// [
mock
PortForwardingFunction].
// [
fake
PortForwardingFunction].
expect
(
uriConnections
[
0
],
expect
(
uriConnections
[
0
],
Uri
(
scheme:
'ws'
,
host:
'[fe80::1:2%25eno2]'
,
port:
0
,
path:
'/ws'
));
Uri
(
scheme:
'ws'
,
host:
'[fe80::1:2%25eno2]'
,
port:
0
,
path:
'/ws'
));
expect
(
uriConnections
[
1
],
expect
(
uriConnections
[
1
],
...
@@ -225,43 +213,39 @@ void main() {
...
@@ -225,43 +213,39 @@ void main() {
// Ensure the ports are all closed after stop was called.
// Ensure the ports are all closed after stop was called.
await
connection
.
stop
();
await
connection
.
stop
();
verify
(
forwardedPorts
[
0
].
stop
()
);
expect
(
forwardedPorts
[
0
].
stopped
,
true
);
verify
(
forwardedPorts
[
1
].
stop
()
);
expect
(
forwardedPorts
[
1
].
stopped
,
true
);
verify
(
forwardedPorts
[
2
].
stop
()
);
expect
(
forwardedPorts
[
2
].
stopped
,
true
);
});
});
test
(
'end-to-end with three vms and ipv4'
,
()
async
{
test
(
'end-to-end with three vms and ipv4'
,
()
async
{
int
port
=
0
;
int
port
=
0
;
Future
<
PortForwarder
>
mock
PortForwardingFunction
(
Future
<
PortForwarder
>
fake
PortForwardingFunction
(
String
address
,
String
address
,
int
remotePort
,
[
int
remotePort
,
[
String
interface
=
'',
String
interface
=
'',
String
configFile
,
String
configFile
,
])
{
])
{
return
Future
<
PortForwarder
>(()
{
return
Future
<
PortForwarder
>(()
{
final
MockPortForwarder
pf
=
Mock
PortForwarder
();
final
FakePortForwarder
pf
=
Fake
PortForwarder
();
forwardedPorts
.
add
(
pf
);
forwardedPorts
.
add
(
pf
);
when
(
pf
.
port
).
thenReturn
(
port
++)
;
pf
.
port
=
port
++
;
when
(
pf
.
remotePort
).
thenReturn
(
remotePort
)
;
pf
.
remotePort
=
remotePort
;
return
pf
;
return
pf
;
});
});
}
}
fuchsiaPortForwardingFunction
=
mock
PortForwardingFunction
;
fuchsiaPortForwardingFunction
=
fake
PortForwardingFunction
;
final
MockSshCommandRunner
mockRunner
=
Mock
SshCommandRunner
();
final
FakeSshCommandRunner
fakeRunner
=
Fake
SshCommandRunner
();
// Adds some extra junk to make sure the strings will be cleaned up.
// Adds some extra junk to make sure the strings will be cleaned up.
when
(
mockRunner
.
run
(
argThat
(
startsWith
(
'/bin/find'
)))).
thenAnswer
(
fakeRunner
.
findResponse
=
<
String
>[
'/hub/blah/blah/blah/vmservice-port
\n
'
];
(
_
)
=>
Future
<
List
<
String
>>.
value
(
fakeRunner
.
lsResponse
=
<
String
>[
'123
\n\n\n
'
,
'456 '
,
'789'
];
<
String
>[
'/hub/blah/blah/blah/vmservice-port
\n
'
]));
fakeRunner
.
address
=
'196.168.1.4'
;
when
(
mockRunner
.
run
(
argThat
(
startsWith
(
'/bin/ls'
)))).
thenAnswer
(
(
_
)
=>
Future
<
List
<
String
>>.
value
(
<
String
>[
'123
\n\n\n
'
,
'456 '
,
'789'
]));
when
(
mockRunner
.
address
).
thenReturn
(
'196.168.1.4'
);
final
FuchsiaRemoteConnection
connection
=
final
FuchsiaRemoteConnection
connection
=
await
FuchsiaRemoteConnection
.
connectWithSshCommandRunner
(
mock
Runner
);
await
FuchsiaRemoteConnection
.
connectWithSshCommandRunner
(
fake
Runner
);
// [
mock
PortForwardingFunction] will have returned three different
// [
fake
PortForwardingFunction] will have returned three different
// forwarded ports, incrementing the port each time by one. (Just a sanity
// forwarded ports, incrementing the port each time by one. (Just a sanity
// check that the forwarding port was called).
// check that the forwarding port was called).
expect
(
forwardedPorts
.
length
,
3
);
expect
(
forwardedPorts
.
length
,
3
);
...
@@ -294,9 +278,9 @@ void main() {
...
@@ -294,9 +278,9 @@ void main() {
// Ensure the ports are all closed after stop was called.
// Ensure the ports are all closed after stop was called.
await
connection
.
stop
();
await
connection
.
stop
();
verify
(
forwardedPorts
[
0
].
stop
()
);
expect
(
forwardedPorts
[
0
].
stopped
,
true
);
verify
(
forwardedPorts
[
1
].
stop
()
);
expect
(
forwardedPorts
[
1
].
stopped
,
true
);
verify
(
forwardedPorts
[
2
].
stop
()
);
expect
(
forwardedPorts
[
2
].
stopped
,
true
);
});
});
test
(
'env variable test without remote addr'
,
()
async
{
test
(
'env variable test without remote addr'
,
()
async
{
...
@@ -311,8 +295,69 @@ void main() {
...
@@ -311,8 +295,69 @@ void main() {
});
});
}
}
class
MockSshCommandRunner
extends
Mock
implements
SshCommandRunner
{}
class
FakeSshCommandRunner
extends
Fake
implements
SshCommandRunner
{
List
<
String
>
findResponse
;
List
<
String
>
lsResponse
;
@override
Future
<
List
<
String
>>
run
(
String
command
)
async
{
if
(
command
.
startsWith
(
'/bin/find'
))
{
return
findResponse
;
}
if
(
command
.
startsWith
(
'/bin/ls'
))
{
return
lsResponse
;
}
throw
UnimplementedError
(
command
);
}
class
MockPortForwarder
extends
Mock
implements
PortForwarder
{}
@override
String
interface
;
@
override
String
address
;
@override
String
get
sshConfigPath
=>
'~/.ssh'
;
}
class
MockVmService
extends
Mock
implements
vms
.
VmService
{}
class
FakePortForwarder
extends
Fake
implements
PortForwarder
{
@override
int
port
;
@override
int
remotePort
;
@override
String
openPortAddress
;
bool
stopped
=
false
;
@override
Future
<
void
>
stop
()
async
{
stopped
=
true
;
}
}
class
FakeVmService
extends
Fake
implements
vms
.
VmService
{
bool
disposed
=
false
;
vms
.
Response
flutterListViews
;
@override
Future
<
void
>
dispose
()
async
{
disposed
=
true
;
}
@override
Future
<
vms
.
Response
>
callMethod
(
String
method
,
{
String
isolateId
,
Map
<
String
,
dynamic
>
args
})
async
{
if
(
method
==
'_flutter.listViews'
)
{
return
flutterListViews
;
}
throw
UnimplementedError
(
method
);
}
@override
Future
<
void
>
onDone
;
@override
Future
<
vms
.
Version
>
getVersion
()
async
{
return
vms
.
Version
(
major:
-
1
,
minor:
-
1
);
}
}
packages/fuchsia_remote_debug_protocol/test/src/dart/dart_vm_test.dart
View file @
e4c84987
...
@@ -5,8 +5,8 @@
...
@@ -5,8 +5,8 @@
import
'dart:async'
;
import
'dart:async'
;
import
'package:fuchsia_remote_debug_protocol/src/dart/dart_vm.dart'
;
import
'package:fuchsia_remote_debug_protocol/src/dart/dart_vm.dart'
;
import
'package:test/fake.dart'
;
import
'package:vm_service/vm_service.dart'
as
vms
;
import
'package:vm_service/vm_service.dart'
as
vms
;
import
'package:mockito/mockito.dart'
;
import
'../../common.dart'
;
import
'../../common.dart'
;
...
@@ -17,41 +17,40 @@ void main() {
...
@@ -17,41 +17,40 @@ void main() {
});
});
test
(
'null connector'
,
()
async
{
test
(
'null connector'
,
()
async
{
Future
<
vms
.
VmService
>
mock
ServiceFunction
(
Future
<
vms
.
VmService
>
fake
ServiceFunction
(
Uri
uri
,
{
Uri
uri
,
{
Duration
timeout
,
Duration
timeout
,
})
{
})
{
return
Future
<
vms
.
VmService
>(()
=>
null
);
return
Future
<
vms
.
VmService
>(()
=>
null
);
}
}
fuchsiaVmServiceConnectionFunction
=
mock
ServiceFunction
;
fuchsiaVmServiceConnectionFunction
=
fake
ServiceFunction
;
expect
(
await
DartVm
.
connect
(
Uri
.
parse
(
'http://this.whatever/ws'
)),
expect
(
await
DartVm
.
connect
(
Uri
.
parse
(
'http://this.whatever/ws'
)),
equals
(
null
));
equals
(
null
));
});
});
test
(
'disconnect closes peer'
,
()
async
{
test
(
'disconnect closes peer'
,
()
async
{
final
MockVmService
service
=
Mock
VmService
();
final
FakeVmService
service
=
Fake
VmService
();
Future
<
vms
.
VmService
>
mock
ServiceFunction
(
Future
<
vms
.
VmService
>
fake
ServiceFunction
(
Uri
uri
,
{
Uri
uri
,
{
Duration
timeout
,
Duration
timeout
,
})
{
})
{
return
Future
<
vms
.
VmService
>(()
=>
service
);
return
Future
<
vms
.
VmService
>(()
=>
service
);
}
}
fuchsiaVmServiceConnectionFunction
=
mockServiceFunction
;
fuchsiaVmServiceConnectionFunction
=
fakeServiceFunction
;
final
DartVm
vm
=
final
DartVm
vm
=
await
DartVm
.
connect
(
Uri
.
parse
(
'http://this.whatever/ws'
));
await
DartVm
.
connect
(
Uri
.
parse
(
'http://this.whatever/ws'
));
expect
(
vm
,
isNot
(
null
));
expect
(
vm
,
isNot
(
null
));
await
vm
.
stop
();
await
vm
.
stop
();
verify
(
service
.
dispose
()
);
expect
(
service
.
disposed
,
true
);
});
});
});
});
group
(
'DartVm.getAllFlutterViews'
,
()
{
group
(
'DartVm.getAllFlutterViews'
,
()
{
MockVmService
mock
Service
;
FakeVmService
fake
Service
;
setUp
(()
{
setUp
(()
{
mockService
=
Mock
VmService
();
fakeService
=
Fake
VmService
();
});
});
tearDown
(()
{
tearDown
(()
{
...
@@ -90,18 +89,16 @@ void main() {
...
@@ -90,18 +89,16 @@ void main() {
],
],
};
};
Future
<
vms
.
VmService
>
mock
VmConnectionFunction
(
Future
<
vms
.
VmService
>
fake
VmConnectionFunction
(
Uri
uri
,
{
Uri
uri
,
{
Duration
timeout
,
Duration
timeout
,
})
{
})
{
when
(
mockService
.
callMethod
(
'_flutter.listViews'
)).
thenAnswer
((
_
)
async
=>
fakeService
.
flutterListViews
=
vms
.
Response
.
parse
(
flutterViewCannedResponses
);
vms
.
Response
.
parse
(
flutterViewCannedResponses
));
return
Future
<
vms
.
VmService
>(()
=>
fakeService
);
return
Future
<
vms
.
VmService
>(()
=>
mockService
);
}
}
fuchsiaVmServiceConnectionFunction
=
mockVmConnectionFunction
;
fuchsiaVmServiceConnectionFunction
=
fakeVmConnectionFunction
;
final
DartVm
vm
=
final
DartVm
vm
=
await
DartVm
.
connect
(
Uri
.
parse
(
'http://whatever.com/ws'
));
await
DartVm
.
connect
(
Uri
.
parse
(
'http://whatever.com/ws'
));
expect
(
vm
,
isNot
(
null
));
expect
(
vm
,
isNot
(
null
));
final
List
<
FlutterView
>
views
=
await
vm
.
getAllFlutterViews
();
final
List
<
FlutterView
>
views
=
await
vm
.
getAllFlutterViews
();
expect
(
views
.
length
,
3
);
expect
(
views
.
length
,
3
);
...
@@ -148,18 +145,16 @@ void main() {
...
@@ -148,18 +145,16 @@ void main() {
],
],
};
};
Future
<
vms
.
VmService
>
mock
VmConnectionFunction
(
Future
<
vms
.
VmService
>
fake
VmConnectionFunction
(
Uri
uri
,
{
Uri
uri
,
{
Duration
timeout
,
Duration
timeout
,
})
{
})
{
when
(
mockService
.
callMethod
(
'_flutter.listViews'
)).
thenAnswer
((
_
)
async
=>
fakeService
.
flutterListViews
=
vms
.
Response
.
parse
(
flutterViewCannedResponses
);
vms
.
Response
.
parse
(
flutterViewCannedResponses
));
return
Future
<
vms
.
VmService
>(()
=>
fakeService
);
return
Future
<
vms
.
VmService
>(()
=>
mockService
);
}
}
fuchsiaVmServiceConnectionFunction
=
mockVmConnectionFunction
;
fuchsiaVmServiceConnectionFunction
=
fakeVmConnectionFunction
;
final
DartVm
vm
=
final
DartVm
vm
=
await
DartVm
.
connect
(
Uri
.
parse
(
'http://whatever.com/ws'
));
await
DartVm
.
connect
(
Uri
.
parse
(
'http://whatever.com/ws'
));
expect
(
vm
,
isNot
(
null
));
expect
(
vm
,
isNot
(
null
));
final
List
<
FlutterView
>
views
=
await
vm
.
getAllFlutterViews
();
final
List
<
FlutterView
>
views
=
await
vm
.
getAllFlutterViews
();
expect
(
views
.
length
,
3
);
expect
(
views
.
length
,
3
);
...
@@ -175,8 +170,7 @@ void main() {
...
@@ -175,8 +170,7 @@ void main() {
});
});
test
(
'invalid flutter view missing ID'
,
()
async
{
test
(
'invalid flutter view missing ID'
,
()
async
{
final
Map
<
String
,
dynamic
>
flutterViewCannedResponseMissingId
=
final
Map
<
String
,
dynamic
>
flutterViewCannedResponseMissingId
=
<
String
,
dynamic
>{
<
String
,
dynamic
>{
'views'
:
<
Map
<
String
,
dynamic
>>[
'views'
:
<
Map
<
String
,
dynamic
>>[
// Valid flutter view.
// Valid flutter view.
<
String
,
dynamic
>{
<
String
,
dynamic
>{
...
@@ -198,18 +192,16 @@ void main() {
...
@@ -198,18 +192,16 @@ void main() {
],
],
};
};
Future
<
vms
.
VmService
>
mock
VmConnectionFunction
(
Future
<
vms
.
VmService
>
fake
VmConnectionFunction
(
Uri
uri
,
{
Uri
uri
,
{
Duration
timeout
,
Duration
timeout
,
})
{
})
{
when
(
mockService
.
callMethod
(
'_flutter.listViews'
)).
thenAnswer
((
_
)
async
=>
fakeService
.
flutterListViews
=
vms
.
Response
.
parse
(
flutterViewCannedResponseMissingId
);
vms
.
Response
.
parse
(
flutterViewCannedResponseMissingId
));
return
Future
<
vms
.
VmService
>(()
=>
fakeService
);
return
Future
<
vms
.
VmService
>(()
=>
mockService
);
}
}
fuchsiaVmServiceConnectionFunction
=
mockVmConnectionFunction
;
fuchsiaVmServiceConnectionFunction
=
fakeVmConnectionFunction
;
final
DartVm
vm
=
final
DartVm
vm
=
await
DartVm
.
connect
(
Uri
.
parse
(
'http://whatever.com/ws'
));
await
DartVm
.
connect
(
Uri
.
parse
(
'http://whatever.com/ws'
));
expect
(
vm
,
isNot
(
null
));
expect
(
vm
,
isNot
(
null
));
Future
<
void
>
failingFunction
()
async
{
Future
<
void
>
failingFunction
()
async
{
await
vm
.
getAllFlutterViews
();
await
vm
.
getAllFlutterViews
();
...
@@ -251,29 +243,25 @@ void main() {
...
@@ -251,29 +243,25 @@ void main() {
}),
}),
];
];
Future
<
vms
.
VmService
>
mock
VmConnectionFunction
(
Future
<
vms
.
VmService
>
fake
VmConnectionFunction
(
Uri
uri
,
{
Uri
uri
,
{
Duration
timeout
,
Duration
timeout
,
})
{
})
{
when
(
mockService
.
getVM
()).
thenAnswer
((
_
)
async
=>
fakeService
.
vm
=
FakeVM
(
isolates:
isolates
);
FakeVM
(
isolates:
isolates
));
return
Future
<
vms
.
VmService
>(()
=>
fakeService
);
return
Future
<
vms
.
VmService
>(()
=>
mockService
);
}
}
fuchsiaVmServiceConnectionFunction
=
mockVmConnectionFunction
;
fuchsiaVmServiceConnectionFunction
=
fakeVmConnectionFunction
;
final
DartVm
vm
=
final
DartVm
vm
=
await
DartVm
.
connect
(
Uri
.
parse
(
'http://whatever.com/ws'
));
await
DartVm
.
connect
(
Uri
.
parse
(
'http://whatever.com/ws'
));
expect
(
vm
,
isNot
(
null
));
expect
(
vm
,
isNot
(
null
));
final
List
<
IsolateRef
>
matchingFlutterIsolates
=
final
List
<
IsolateRef
>
matchingFlutterIsolates
=
await
vm
.
getMainIsolatesByPattern
(
'flutterBinary.cmx'
);
await
vm
.
getMainIsolatesByPattern
(
'flutterBinary.cmx'
);
expect
(
matchingFlutterIsolates
.
length
,
1
);
expect
(
matchingFlutterIsolates
.
length
,
1
);
final
List
<
IsolateRef
>
allIsolates
=
await
vm
.
getMainIsolatesByPattern
(
''
);
final
List
<
IsolateRef
>
allIsolates
=
await
vm
.
getMainIsolatesByPattern
(
''
);
expect
(
allIsolates
.
length
,
4
);
expect
(
allIsolates
.
length
,
4
);
});
});
test
(
'invalid flutter view missing ID'
,
()
async
{
test
(
'invalid flutter view missing ID'
,
()
async
{
final
Map
<
String
,
dynamic
>
flutterViewCannedResponseMissingIsolateName
=
final
Map
<
String
,
dynamic
>
flutterViewCannedResponseMissingIsolateName
=
<
String
,
dynamic
>{
<
String
,
dynamic
>{
'views'
:
<
Map
<
String
,
dynamic
>>[
'views'
:
<
Map
<
String
,
dynamic
>>[
// Missing isolate name.
// Missing isolate name.
<
String
,
dynamic
>{
<
String
,
dynamic
>{
...
@@ -289,18 +277,16 @@ void main() {
...
@@ -289,18 +277,16 @@ void main() {
],
],
};
};
Future
<
vms
.
VmService
>
mock
VmConnectionFunction
(
Future
<
vms
.
VmService
>
fake
VmConnectionFunction
(
Uri
uri
,
{
Uri
uri
,
{
Duration
timeout
,
Duration
timeout
,
})
{
})
{
when
(
mockService
.
callMethod
(
any
)).
thenAnswer
((
_
)
async
=>
fakeService
.
flutterListViews
=
vms
.
Response
.
parse
(
flutterViewCannedResponseMissingIsolateName
);
vms
.
Response
.
parse
(
flutterViewCannedResponseMissingIsolateName
));
return
Future
<
vms
.
VmService
>(()
=>
fakeService
);
return
Future
<
vms
.
VmService
>(()
=>
mockService
);
}
}
fuchsiaVmServiceConnectionFunction
=
mockVmConnectionFunction
;
fuchsiaVmServiceConnectionFunction
=
fakeVmConnectionFunction
;
final
DartVm
vm
=
final
DartVm
vm
=
await
DartVm
.
connect
(
Uri
.
parse
(
'http://whatever.com/ws'
));
await
DartVm
.
connect
(
Uri
.
parse
(
'http://whatever.com/ws'
));
expect
(
vm
,
isNot
(
null
));
expect
(
vm
,
isNot
(
null
));
Future
<
void
>
failingFunction
()
async
{
Future
<
void
>
failingFunction
()
async
{
await
vm
.
getAllFlutterViews
();
await
vm
.
getAllFlutterViews
();
...
@@ -312,7 +298,30 @@ void main() {
...
@@ -312,7 +298,30 @@ void main() {
});
});
}
}
class
MockVmService
extends
Mock
implements
vms
.
VmService
{}
class
FakeVmService
extends
Fake
implements
vms
.
VmService
{
bool
disposed
=
false
;
vms
.
Response
flutterListViews
;
vms
.
VM
vm
;
@override
Future
<
vms
.
VM
>
getVM
()
async
=>
vm
;
@override
Future
<
void
>
dispose
()
async
{
disposed
=
true
;
}
@override
Future
<
vms
.
Response
>
callMethod
(
String
method
,
{
String
isolateId
,
Map
<
String
,
dynamic
>
args
})
async
{
if
(
method
==
'_flutter.listViews'
)
{
return
flutterListViews
;
}
throw
UnimplementedError
(
method
);
}
@override
Future
<
void
>
onDone
;
}
class
FakeVM
extends
Fake
implements
vms
.
VM
{
class
FakeVM
extends
Fake
implements
vms
.
VM
{
FakeVM
({
FakeVM
({
...
...
packages/fuchsia_remote_debug_protocol/test/src/runners/ssh_command_runner_test.dart
View file @
e4c84987
...
@@ -2,11 +2,12 @@
...
@@ -2,11 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
import
'dart:io'
show
ProcessResult
;
import
'dart:convert'
;
import
'dart:io'
show
ProcessResult
,
systemEncoding
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
import
'package:process/process.dart'
;
import
'package:fuchsia_remote_debug_protocol/src/runners/ssh_command_runner.dart'
;
import
'package:fuchsia_remote_debug_protocol/src/runners/ssh_command_runner.dart'
;
import
'package:test/fake.dart'
;
import
'../../common.dart'
;
import
'../../common.dart'
;
...
@@ -32,68 +33,59 @@ void main() {
...
@@ -32,68 +33,59 @@ void main() {
});
});
group
(
'SshCommandRunner.run'
,
()
{
group
(
'SshCommandRunner.run'
,
()
{
MockProcessManager
mock
ProcessManager
;
FakeProcessManager
fake
ProcessManager
;
MockProcessResult
mock
ProcessResult
;
FakeProcessResult
fake
ProcessResult
;
SshCommandRunner
runner
;
SshCommandRunner
runner
;
setUp
(()
{
setUp
(()
{
mockProcessManager
=
MockProcessManager
();
fakeProcessResult
=
FakeProcessResult
();
mockProcessResult
=
MockProcessResult
();
fakeProcessManager
=
FakeProcessManager
()..
fakeResult
=
fakeProcessResult
;
when
(
mockProcessManager
.
run
(
any
)).
thenAnswer
(
(
_
)
=>
Future
<
MockProcessResult
>.
value
(
mockProcessResult
));
});
});
test
(
'verify interface is appended to ipv6 address'
,
()
async
{
test
(
'verify interface is appended to ipv6 address'
,
()
async
{
const
String
ipV6Addr
=
'fe80::8eae:4cff:fef4:9247'
;
const
String
ipV6Addr
=
'fe80::8eae:4cff:fef4:9247'
;
const
String
interface
=
'
eno1
';
const
String
interface
=
'
eno1
';
runner = SshCommandRunner.withProcessManager(
runner = SshCommandRunner.withProcessManager(
mock
ProcessManager,
fake
ProcessManager,
address: ipV6Addr,
address: ipV6Addr,
interface: interface,
interface: interface,
sshConfigPath: '
/
whatever
',
sshConfigPath: '
/
whatever
',
);
);
when<dynamic>(mockProcessResult.stdout).thenReturn('
somestuff
');
fakeProcessResult.stdout = '
somestuff
';
when(mockProcessResult.exitCode).thenReturn(0);
await runner.run('
ls
/
whatever
');
await runner.run('
ls
/
whatever
');
final List<String> passedCommand =
expect(fakeProcessManager.runCommands.single, contains('
$ipV6Addr
%
$interface
'));
verify(mockProcessManager.run(captureAny)).captured.single as List<String>;
expect(passedCommand, contains('
$ipV6Addr
%
$interface
'));
});
});
test('
verify
no
percentage
symbol
is
added
when
no
ipv6
interface
',
()
async
{
test('
verify
no
percentage
symbol
is
added
when
no
ipv6
interface
',
()
async
{
const
String
ipV6Addr
=
'fe80::8eae:4cff:fef4:9247'
;
const
String
ipV6Addr
=
'fe80::8eae:4cff:fef4:9247'
;
runner
=
SshCommandRunner
.
withProcessManager
(
runner
=
SshCommandRunner
.
withProcessManager
(
mock
ProcessManager
,
fake
ProcessManager
,
address:
ipV6Addr
,
address:
ipV6Addr
,
);
);
when
<
dynamic
>(
mockProcessResult
.
stdout
).
thenReturn
(
'somestuff'
);
fakeProcessResult
.
stdout
=
'somestuff'
;
when
(
mockProcessResult
.
exitCode
).
thenReturn
(
0
);
await
runner
.
run
(
'ls /whatever'
);
await
runner
.
run
(
'ls /whatever'
);
final
List
<
String
>
passedCommand
=
expect
(
fakeProcessManager
.
runCommands
.
single
,
contains
(
ipV6Addr
));
verify
(
mockProcessManager
.
run
(
captureAny
)).
captured
.
single
as
List
<
String
>;
expect
(
passedCommand
,
contains
(
ipV6Addr
));
});
});
test
(
'verify commands are split into multiple lines'
,
()
async
{
test
(
'verify commands are split into multiple lines'
,
()
async
{
const
String
addr
=
'192.168.1.1'
;
const
String
addr
=
'192.168.1.1'
;
runner
=
SshCommandRunner
.
withProcessManager
(
mock
ProcessManager
,
runner
=
SshCommandRunner
.
withProcessManager
(
fake
ProcessManager
,
address:
addr
);
address:
addr
);
when
<
dynamic
>(
mockProcessResult
.
stdout
).
thenReturn
(
'''
fakeProcessResult
.
stdout
=
'''
this
this
has
has
four
four
lines'''
);
lines'''
;
when
(
mockProcessResult
.
exitCode
).
thenReturn
(
0
);
final
List
<
String
>
result
=
await
runner
.
run
(
'oihaw'
);
final
List
<
String
>
result
=
await
runner
.
run
(
'oihaw'
);
expect
(
result
,
hasLength
(
4
));
expect
(
result
,
hasLength
(
4
));
});
});
test
(
'verify exception on nonzero process result exit code'
,
()
async
{
test
(
'verify exception on nonzero process result exit code'
,
()
async
{
const
String
addr
=
'192.168.1.1'
;
const
String
addr
=
'192.168.1.1'
;
runner
=
SshCommandRunner
.
withProcessManager
(
mock
ProcessManager
,
runner
=
SshCommandRunner
.
withProcessManager
(
fake
ProcessManager
,
address:
addr
);
address:
addr
);
when
<
dynamic
>(
mockProcessResult
.
stdout
).
thenReturn
(
'whatever'
)
;
fakeProcessResult
.
stdout
=
'whatever'
;
when
(
mockProcessResult
.
exitCode
).
thenReturn
(
1
)
;
fakeProcessResult
.
exitCode
=
1
;
Future
<
void
>
failingFunction
()
async
{
Future
<
void
>
failingFunction
()
async
{
await
runner
.
run
(
'oihaw'
);
await
runner
.
run
(
'oihaw'
);
}
}
...
@@ -105,15 +97,13 @@ void main() {
...
@@ -105,15 +97,13 @@ void main() {
const
String
addr
=
'fe80::8eae:4cff:fef4:9247'
;
const
String
addr
=
'fe80::8eae:4cff:fef4:9247'
;
const
String
config
=
'/this/that/this/and/uh'
;
const
String
config
=
'/this/that/this/and/uh'
;
runner
=
SshCommandRunner
.
withProcessManager
(
runner
=
SshCommandRunner
.
withProcessManager
(
mock
ProcessManager
,
fake
ProcessManager
,
address:
addr
,
address:
addr
,
sshConfigPath:
config
,
sshConfigPath:
config
,
);
);
when
<
dynamic
>(
mockProcessResult
.
stdout
).
thenReturn
(
'somestuff'
);
fakeProcessResult
.
stdout
=
'somestuff'
;
when
(
mockProcessResult
.
exitCode
).
thenReturn
(
0
);
await
runner
.
run
(
'ls /whatever'
);
await
runner
.
run
(
'ls /whatever'
);
final
List
<
String
>
passedCommand
=
final
List
<
String
>
passedCommand
=
fakeProcessManager
.
runCommands
.
single
as
List
<
String
>;
verify
(
mockProcessManager
.
run
(
captureAny
)).
captured
.
single
as
List
<
String
>;
expect
(
passedCommand
,
contains
(
'-F'
));
expect
(
passedCommand
,
contains
(
'-F'
));
final
int
indexOfFlag
=
passedCommand
.
indexOf
(
'-F'
);
final
int
indexOfFlag
=
passedCommand
.
indexOf
(
'-F'
);
final
String
passedConfig
=
passedCommand
[
indexOfFlag
+
1
];
final
String
passedConfig
=
passedCommand
[
indexOfFlag
+
1
];
...
@@ -123,20 +113,44 @@ void main() {
...
@@ -123,20 +113,44 @@ void main() {
test
(
'verify config is excluded correctly'
,
()
async
{
test
(
'verify config is excluded correctly'
,
()
async
{
const
String
addr
=
'fe80::8eae:4cff:fef4:9247'
;
const
String
addr
=
'fe80::8eae:4cff:fef4:9247'
;
runner
=
SshCommandRunner
.
withProcessManager
(
runner
=
SshCommandRunner
.
withProcessManager
(
mock
ProcessManager
,
fake
ProcessManager
,
address:
addr
,
address:
addr
,
);
);
when
<
dynamic
>(
mockProcessResult
.
stdout
).
thenReturn
(
'somestuff'
);
fakeProcessResult
.
stdout
=
'somestuff'
;
when
(
mockProcessResult
.
exitCode
).
thenReturn
(
0
);
await
runner
.
run
(
'ls /whatever'
);
await
runner
.
run
(
'ls /whatever'
);
final
List
<
String
>
passedCommand
=
final
List
<
String
>
passedCommand
=
fakeProcessManager
.
runCommands
.
single
as
List
<
String
>;
verify
(
mockProcessManager
.
run
(
captureAny
)).
captured
.
single
as
List
<
String
>;
final
int
indexOfFlag
=
passedCommand
.
indexOf
(
'-F'
);
final
int
indexOfFlag
=
passedCommand
.
indexOf
(
'-F'
);
expect
(
indexOfFlag
,
equals
(-
1
));
expect
(
indexOfFlag
,
equals
(-
1
));
});
});
});
});
}
}
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
class
FakeProcessManager
extends
Fake
implements
ProcessManager
{
FakeProcessResult
fakeResult
;
List
<
List
<
dynamic
>>
runCommands
=
<
List
<
dynamic
>>[];
@override
Future
<
ProcessResult
>
run
(
List
<
dynamic
>
command
,
{
String
workingDirectory
,
Map
<
String
,
String
>
environment
,
bool
includeParentEnvironment
=
true
,
bool
runInShell
=
false
,
Encoding
stdoutEncoding
=
systemEncoding
,
Encoding
stderrEncoding
=
systemEncoding
,
})
async
{
runCommands
.
add
(
command
);
return
fakeResult
;
}
}
class
FakeProcessResult
extends
Fake
implements
ProcessResult
{
@override
int
exitCode
=
0
;
class
MockProcessResult
extends
Mock
implements
ProcessResult
{}
@override
dynamic
stdout
;
@override
dynamic
stderr
;
}
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