1import pytest
3
4import testsuite.plugins.testpoint
5
6
7
8async def test_basic(service_client, testpoint: testsuite.plugins.testpoint.TestpointFixture):
9 @testpoint('simple-testpoint')
10 def simple_testpoint(data: dict):
11 assert data == {'payload': 'Hello, world!'}
12
13 response = await service_client.get('/testpoint')
14 assert response.status == 200
15 assert 'application/json' in response.headers['Content-Type']
16 assert simple_testpoint.times_called == 1
17
18
19
20
21async def test_injection(service_client, testpoint: testsuite.plugins.testpoint.TestpointFixture):
22 @testpoint('injection-point')
23 def injection_point(data: dict):
24 return {'value': 'injected'}
25
26 response = await service_client.get('/testpoint')
27 assert response.status == 200
28 assert 'application/json' in response.headers['Content-Type']
29 assert response.json() == {'value': 'injected'}
30
31
32 assert injection_point.times_called == 1
33
34
35
36async def test_disabled_testpoint(service_client, testpoint):
37 response = await service_client.get('/testpoint')
38 assert response.status == 200
39
40 @testpoint('injection-point')
41 def injection_point(data: dict):
42 return {'value': 'injected'}
43
44
45 with pytest.raises(
47 ):
48 assert injection_point.times_called == 0
49
50
51 await service_client.update_server_state()
52 assert injection_point.times_called == 0
53
54
55async def test_manual_testpoint_registration(service_client, testpoint):
56
57 @testpoint('injection-point')
58 def injection_point(data):
59 return {'value': 'injected'}
60
61 await service_client.update_server_state()
62 assert injection_point.times_called == 0
63
64
65 response = await service_client.get('/testpoint')
66 assert response.status == 200
67
68 assert injection_point.times_called == 1