-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathoperations_test.dart
50 lines (45 loc) · 1.51 KB
/
operations_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
import 'package:test/test.dart';
import 'package:mockito/mockito.dart';
import 'package:typesense/src/operations.dart';
import 'test_utils.mocks.dart';
void main() {
late Operations operations;
late MockApiCall mock;
setUp(() {
mock = MockApiCall();
operations = Operations(mock);
});
group('Operations', () {
test('has a resourcepath', () {
expect(Operations.resourcepath, equals('/operations'));
});
test('createSnapshot() calls ApiCall.post()', () async {
when(
mock.post(
'/operations/snapshot',
queryParams: {
'snapshot_path': '/tmp/typesense-data-snapshot',
},
),
).thenAnswer((realInvocation) => Future.value({"success": true}));
expect(await operations.createSnapshot('/tmp/typesense-data-snapshot'),
equals({"success": true}));
});
test('initLeaderElection() calls ApiCall.post()', () async {
when(
mock.post(
'/operations/vote',
),
).thenAnswer((realInvocation) => Future.value({"success": true}));
expect(await operations.initLeaderElection(), equals({"success": true}));
});
test('toggleSlowRequestLog() calls ApiCall.post()', () async {
when(
mock.post('/config',
bodyParameters: {'log-slow-requests-time-ms': 2000}),
).thenAnswer((realInvocation) => Future.value({"success": true}));
expect(await operations.toggleSlowRequestLog(Duration(seconds: 2)),
equals({"success": true}));
});
});
}