forked from dart-lang/webdev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension_backend_test.dart
65 lines (55 loc) · 1.89 KB
/
extension_backend_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2021, 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.
@Timeout(Duration(minutes: 2))
library;
import 'dart:async';
import 'package:async/src/stream_queue.dart';
import 'package:dwds/data/extension_request.dart';
import 'package:dwds/src/handlers/socket_connections.dart';
import 'package:dwds/src/servers/extension_backend.dart';
import 'package:http/http.dart' as http;
import 'package:shelf/src/request.dart';
import 'package:shelf/src/response.dart';
import 'package:test/test.dart';
class MockSocketHandler implements SocketHandler {
static const mockResponse = 'Returned from MockSocketHandler';
@override
StreamQueue<SocketConnection> get connections =>
StreamQueue(const Stream.empty());
@override
FutureOr<Response> handler(Request request) {
return Response.ok(mockResponse);
}
@override
void shutdown() {}
}
void main() {
late ExtensionBackend extensionBackend;
setUpAll(() async {
extensionBackend =
await ExtensionBackend.start(MockSocketHandler(), 'localhost');
});
test('returns success statusCode', () async {
final result = await http.get(
Uri.parse(
'http://localhost:${extensionBackend.port}/$authenticationPath',
),
);
expect(result.statusCode, 200);
});
test('returns expected authentication response', () async {
final result = await http.get(
Uri.parse(
'http://localhost:${extensionBackend.port}/$authenticationPath',
),
);
expect(result.body, authenticationResponse);
});
test('delegates to the underlying socket handler', () async {
final result = await http.get(
Uri.parse('http://localhost:${extensionBackend.port}/somedummypath'),
);
expect(result.body, MockSocketHandler.mockResponse);
});
}