Null safe migration for fuchsia_remote_debug_protocol (#74762)
This commit is contained in:
@@ -11,9 +11,9 @@ import 'common.dart';
|
||||
|
||||
void main() {
|
||||
group('FuchsiaRemoteConnection.connect', () {
|
||||
List<FakePortForwarder> forwardedPorts;
|
||||
late List<FakePortForwarder> forwardedPorts;
|
||||
List<FakeVmService> fakeVmServices;
|
||||
List<Uri> uriConnections;
|
||||
late List<Uri> uriConnections;
|
||||
|
||||
setUp(() {
|
||||
final List<Map<String, dynamic>> flutterViewCannedResponses =
|
||||
@@ -63,7 +63,7 @@ void main() {
|
||||
uriConnections = <Uri>[];
|
||||
Future<vms.VmService> fakeVmConnectionFunction(
|
||||
Uri uri, {
|
||||
Duration timeout,
|
||||
Duration? timeout,
|
||||
}) {
|
||||
return Future<vms.VmService>(() async {
|
||||
final FakeVmService service = FakeVmService();
|
||||
@@ -89,8 +89,8 @@ void main() {
|
||||
Future<PortForwarder> fakePortForwardingFunction(
|
||||
String address,
|
||||
int remotePort, [
|
||||
String interface = '',
|
||||
String configFile,
|
||||
String? interface = '',
|
||||
String? configFile,
|
||||
]) {
|
||||
return Future<PortForwarder>(() {
|
||||
final FakePortForwarder pf = FakePortForwarder();
|
||||
@@ -156,8 +156,8 @@ void main() {
|
||||
Future<PortForwarder> fakePortForwardingFunction(
|
||||
String address,
|
||||
int remotePort, [
|
||||
String interface = '',
|
||||
String configFile,
|
||||
String? interface = '',
|
||||
String? configFile,
|
||||
]) {
|
||||
return Future<PortForwarder>(() {
|
||||
final FakePortForwarder pf = FakePortForwarder();
|
||||
@@ -223,8 +223,8 @@ void main() {
|
||||
Future<PortForwarder> fakePortForwardingFunction(
|
||||
String address,
|
||||
int remotePort, [
|
||||
String interface = '',
|
||||
String configFile,
|
||||
String? interface = '',
|
||||
String? configFile,
|
||||
]) {
|
||||
return Future<PortForwarder>(() {
|
||||
final FakePortForwarder pf = FakePortForwarder();
|
||||
@@ -296,24 +296,24 @@ void main() {
|
||||
}
|
||||
|
||||
class FakeSshCommandRunner extends Fake implements SshCommandRunner {
|
||||
List<String> findResponse;
|
||||
List<String> lsResponse;
|
||||
List<String>? findResponse;
|
||||
List<String>? lsResponse;
|
||||
@override
|
||||
Future<List<String>> run(String command) async {
|
||||
if (command.startsWith('/bin/find')) {
|
||||
return findResponse;
|
||||
return findResponse!;
|
||||
}
|
||||
if (command.startsWith('/bin/ls')) {
|
||||
return lsResponse;
|
||||
return lsResponse!;
|
||||
}
|
||||
throw UnimplementedError(command);
|
||||
}
|
||||
|
||||
@override
|
||||
String interface;
|
||||
String interface = '';
|
||||
|
||||
@override
|
||||
String address;
|
||||
String address = '';
|
||||
|
||||
@override
|
||||
String get sshConfigPath => '~/.ssh';
|
||||
@@ -321,13 +321,13 @@ class FakeSshCommandRunner extends Fake implements SshCommandRunner {
|
||||
|
||||
class FakePortForwarder extends Fake implements PortForwarder {
|
||||
@override
|
||||
int port;
|
||||
int port = 0;
|
||||
|
||||
@override
|
||||
int remotePort;
|
||||
int remotePort = 0;
|
||||
|
||||
@override
|
||||
String openPortAddress;
|
||||
String? openPortAddress;
|
||||
|
||||
bool stopped = false;
|
||||
@override
|
||||
@@ -338,7 +338,7 @@ class FakePortForwarder extends Fake implements PortForwarder {
|
||||
|
||||
class FakeVmService extends Fake implements vms.VmService {
|
||||
bool disposed = false;
|
||||
vms.Response flutterListViews;
|
||||
vms.Response? flutterListViews;
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {
|
||||
@@ -346,15 +346,15 @@ class FakeVmService extends Fake implements vms.VmService {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<vms.Response> callMethod(String method, {String isolateId, Map<String, dynamic> args}) async {
|
||||
Future<vms.Response> callMethod(String method, {String? isolateId, Map<String, dynamic>? args}) async {
|
||||
if (method == '_flutter.listViews') {
|
||||
return flutterListViews;
|
||||
return flutterListViews!;
|
||||
}
|
||||
throw UnimplementedError(method);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onDone;
|
||||
Future<void> onDone = Future<void>.value();
|
||||
|
||||
@override
|
||||
Future<vms.Version> getVersion() async {
|
||||
|
||||
@@ -16,24 +16,11 @@ void main() {
|
||||
restoreVmServiceConnectionFunction();
|
||||
});
|
||||
|
||||
test('null connector', () async {
|
||||
Future<vms.VmService> fakeServiceFunction(
|
||||
Uri uri, {
|
||||
Duration timeout,
|
||||
}) {
|
||||
return Future<vms.VmService>(() => null);
|
||||
}
|
||||
|
||||
fuchsiaVmServiceConnectionFunction = fakeServiceFunction;
|
||||
expect(await DartVm.connect(Uri.parse('http://this.whatever/ws')),
|
||||
equals(null));
|
||||
});
|
||||
|
||||
test('disconnect closes peer', () async {
|
||||
final FakeVmService service = FakeVmService();
|
||||
Future<vms.VmService> fakeServiceFunction(
|
||||
Uri uri, {
|
||||
Duration timeout,
|
||||
Duration? timeout,
|
||||
}) {
|
||||
return Future<vms.VmService>(() => service);
|
||||
}
|
||||
@@ -47,7 +34,7 @@ void main() {
|
||||
});
|
||||
|
||||
group('DartVm.getAllFlutterViews', () {
|
||||
FakeVmService fakeService;
|
||||
late FakeVmService fakeService;
|
||||
|
||||
setUp(() {
|
||||
fakeService = FakeVmService();
|
||||
@@ -91,7 +78,7 @@ void main() {
|
||||
|
||||
Future<vms.VmService> fakeVmConnectionFunction(
|
||||
Uri uri, {
|
||||
Duration timeout,
|
||||
Duration? timeout,
|
||||
}) {
|
||||
fakeService.flutterListViews = vms.Response.parse(flutterViewCannedResponses);
|
||||
return Future<vms.VmService>(() => fakeService);
|
||||
@@ -147,7 +134,7 @@ void main() {
|
||||
|
||||
Future<vms.VmService> fakeVmConnectionFunction(
|
||||
Uri uri, {
|
||||
Duration timeout,
|
||||
Duration? timeout,
|
||||
}) {
|
||||
fakeService.flutterListViews = vms.Response.parse(flutterViewCannedResponses);
|
||||
return Future<vms.VmService>(() => fakeService);
|
||||
@@ -194,7 +181,7 @@ void main() {
|
||||
|
||||
Future<vms.VmService> fakeVmConnectionFunction(
|
||||
Uri uri, {
|
||||
Duration timeout,
|
||||
Duration? timeout,
|
||||
}) {
|
||||
fakeService.flutterListViews = vms.Response.parse(flutterViewCannedResponseMissingId);
|
||||
return Future<vms.VmService>(() => fakeService);
|
||||
@@ -219,33 +206,33 @@ void main() {
|
||||
'id': 'isolates/1',
|
||||
'name': 'file://thingThatWillNotMatch:main()',
|
||||
'number': '1',
|
||||
}),
|
||||
})!,
|
||||
vms.IsolateRef.parse(<String, dynamic>{
|
||||
'type': '@Isolate',
|
||||
'fixedId': 'true',
|
||||
'id': 'isolates/2',
|
||||
'name': '0:dart_name_pattern()',
|
||||
'number': '2',
|
||||
}),
|
||||
})!,
|
||||
vms.IsolateRef.parse(<String, dynamic>{
|
||||
'type': '@Isolate',
|
||||
'fixedId': 'true',
|
||||
'id': 'isolates/3',
|
||||
'name': 'flutterBinary.cmx',
|
||||
'number': '3',
|
||||
}),
|
||||
})!,
|
||||
vms.IsolateRef.parse(<String, dynamic>{
|
||||
'type': '@Isolate',
|
||||
'fixedId': 'true',
|
||||
'id': 'isolates/4',
|
||||
'name': '0:some_other_dart_name_pattern()',
|
||||
'number': '4',
|
||||
}),
|
||||
})!,
|
||||
];
|
||||
|
||||
Future<vms.VmService> fakeVmConnectionFunction(
|
||||
Uri uri, {
|
||||
Duration timeout,
|
||||
Duration? timeout,
|
||||
}) {
|
||||
fakeService.vm = FakeVM(isolates: isolates);
|
||||
return Future<vms.VmService>(() => fakeService);
|
||||
@@ -279,7 +266,7 @@ void main() {
|
||||
|
||||
Future<vms.VmService> fakeVmConnectionFunction(
|
||||
Uri uri, {
|
||||
Duration timeout,
|
||||
Duration? timeout,
|
||||
}) {
|
||||
fakeService.flutterListViews = vms.Response.parse(flutterViewCannedResponseMissingIsolateName);
|
||||
return Future<vms.VmService>(() => fakeService);
|
||||
@@ -300,11 +287,11 @@ void main() {
|
||||
|
||||
class FakeVmService extends Fake implements vms.VmService {
|
||||
bool disposed = false;
|
||||
vms.Response flutterListViews;
|
||||
vms.VM vm;
|
||||
vms.Response? flutterListViews;
|
||||
vms.VM? vm;
|
||||
|
||||
@override
|
||||
Future<vms.VM> getVM() async => vm;
|
||||
Future<vms.VM> getVM() async => vm!;
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {
|
||||
@@ -312,15 +299,15 @@ class FakeVmService extends Fake implements vms.VmService {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<vms.Response> callMethod(String method, {String isolateId, Map<String, dynamic> args}) async {
|
||||
Future<vms.Response> callMethod(String method, {String? isolateId, Map<String, dynamic>? args}) async {
|
||||
if (method == '_flutter.listViews') {
|
||||
return flutterListViews;
|
||||
return flutterListViews!;
|
||||
}
|
||||
throw UnimplementedError(method);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onDone;
|
||||
Future<void> onDone = Future<void>.value();
|
||||
}
|
||||
|
||||
class FakeVM extends Fake implements vms.VM {
|
||||
@@ -329,5 +316,5 @@ class FakeVM extends Fake implements vms.VM {
|
||||
});
|
||||
|
||||
@override
|
||||
List<vms.IsolateRef> isolates;
|
||||
List<vms.IsolateRef>? isolates;
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ void main() {
|
||||
});
|
||||
|
||||
group('SshCommandRunner.run', () {
|
||||
FakeProcessManager fakeProcessManager;
|
||||
FakeProcessResult fakeProcessResult;
|
||||
late FakeProcessManager fakeProcessManager;
|
||||
late FakeProcessResult fakeProcessResult;
|
||||
SshCommandRunner runner;
|
||||
|
||||
setUp(() {
|
||||
@@ -103,10 +103,10 @@ void main() {
|
||||
);
|
||||
fakeProcessResult.stdout = 'somestuff';
|
||||
await runner.run('ls /whatever');
|
||||
final List<String> passedCommand = fakeProcessManager.runCommands.single as List<String>;
|
||||
final List<String?> passedCommand = fakeProcessManager.runCommands.single as List<String?>;
|
||||
expect(passedCommand, contains('-F'));
|
||||
final int indexOfFlag = passedCommand.indexOf('-F');
|
||||
final String passedConfig = passedCommand[indexOfFlag + 1];
|
||||
final String? passedConfig = passedCommand[indexOfFlag + 1];
|
||||
expect(passedConfig, config);
|
||||
});
|
||||
|
||||
@@ -118,7 +118,7 @@ void main() {
|
||||
);
|
||||
fakeProcessResult.stdout = 'somestuff';
|
||||
await runner.run('ls /whatever');
|
||||
final List<String> passedCommand = fakeProcessManager.runCommands.single as List<String>;
|
||||
final List<String?> passedCommand = fakeProcessManager.runCommands.single as List<String?>;
|
||||
final int indexOfFlag = passedCommand.indexOf('-F');
|
||||
expect(indexOfFlag, equals(-1));
|
||||
});
|
||||
@@ -126,21 +126,21 @@ void main() {
|
||||
}
|
||||
|
||||
class FakeProcessManager extends Fake implements ProcessManager {
|
||||
FakeProcessResult fakeResult;
|
||||
FakeProcessResult? fakeResult;
|
||||
|
||||
List<List<dynamic>> runCommands = <List<dynamic>>[];
|
||||
|
||||
@override
|
||||
Future<ProcessResult> run(List<dynamic> command, {
|
||||
String workingDirectory,
|
||||
Map<String, String> environment,
|
||||
String? workingDirectory,
|
||||
Map<String, String>? environment,
|
||||
bool includeParentEnvironment = true,
|
||||
bool runInShell = false,
|
||||
Encoding stdoutEncoding = systemEncoding,
|
||||
Encoding stderrEncoding = systemEncoding,
|
||||
}) async {
|
||||
runCommands.add(command);
|
||||
return fakeResult;
|
||||
return fakeResult!;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user