Files
sdk/pkg/dds/test/uri_test.dart
T
Ben Konyi 96cf91bea3 [ package:dds ] Update DDS dependencies and set SDK requirement to >=2.12
Also updated non-migrated libraries to include @dart=2.10.

Change-Id: Idcf4e54f9aa37b9b016133144af594cc932418a0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192122
Reviewed-by: Gary Roumanis <grouma@google.com>
2021-03-19 19:49:08 +00:00

93 lines
2.4 KiB
Dart

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart=2.10
import 'dart:io';
import 'package:dds/dds.dart';
import 'package:test/test.dart';
import 'common/test_helper.dart';
void main() {
Process process;
DartDevelopmentService dds;
setUp(() async {
process = await spawnDartProcess('smoke.dart');
});
tearDown(() async {
await dds?.shutdown();
process?.kill();
dds = null;
process = null;
});
Future<int> getAvailablePort() async {
final tmpServer = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
final port = tmpServer.port;
await tmpServer.close();
return port;
}
group('Ensure DDS URIs are consistent', () {
test('without authentication codes', () async {
final port = await getAvailablePort();
final serviceUri = Uri.parse('http://127.0.0.1:$port/');
dds = await DartDevelopmentService.startDartDevelopmentService(
remoteVmServiceUri,
serviceUri: serviceUri,
enableAuthCodes: false,
);
expect(dds.uri, serviceUri);
expect(
dds.sseUri,
serviceUri.replace(
scheme: 'sse',
pathSegments: ['\$debugHandler'],
),
);
expect(
dds.wsUri,
serviceUri.replace(
scheme: 'ws',
pathSegments: ['ws'],
),
);
});
test('with authentication codes', () async {
final port = await getAvailablePort();
final serviceUri = Uri.parse('http://127.0.0.1:$port/');
dds = await DartDevelopmentService.startDartDevelopmentService(
remoteVmServiceUri,
serviceUri: serviceUri,
);
// We need to pull the authentication code out of the main DDS URI, so
// just make sure that it's at the right address and port.
expect(dds.uri.toString().contains(serviceUri.toString()), isTrue);
expect(dds.uri.pathSegments, isNotEmpty);
final authCode = dds.uri.pathSegments.first;
expect(
dds.sseUri,
serviceUri.replace(
scheme: 'sse',
pathSegments: [authCode, '\$debugHandler'],
),
);
expect(
dds.wsUri,
serviceUri.replace(
scheme: 'ws',
pathSegments: [authCode, 'ws'],
),
);
});
});
}