15
15
16
16
from __future__ import annotations
17
17
18
+ from typing import Type
18
19
from unittest .mock import Mock
19
20
20
21
import pytest
23
24
import ops .testing
24
25
25
26
_pydantic = pytest .importorskip ('pydantic' )
26
- from test .fixme_charm .src .charm import Charm # noqa: E402
27
27
28
28
pytestmark = pytest .mark .filterwarnings ('ignore::pydantic.PydanticDeprecatedSince20' )
29
29
30
30
31
- def test_charm_runs ():
32
- ctx = ops .testing .Context (Charm )
31
+ def test_charm_runs (sample_charm : Type [ ops . CharmBase ] ):
32
+ ctx = ops .testing .Context (sample_charm )
33
33
state_in = ops .testing .State ()
34
34
state_out = ctx .run (ctx .on .start (), state_in )
35
35
assert isinstance (state_out .unit_status , ops .ActiveStatus )
@@ -42,28 +42,31 @@ def mock_destination(monkeypatch: pytest.MonkeyPatch) -> Mock:
42
42
return rv
43
43
44
44
45
- def test_no_tracing_destination (mock_destination : Mock ):
46
- ctx = ops .testing .Context (Charm )
45
+ def test_no_tracing_destination (sample_charm : Type [ ops . CharmBase ], mock_destination : Mock ):
46
+ ctx = ops .testing .Context (sample_charm )
47
47
state = ops .testing .State ()
48
48
ctx .run (ctx .on .start (), state )
49
49
mock_destination .assert_called_with (url = None , ca = None )
50
50
51
51
52
- def test_http_tracing_destination (mock_destination : Mock , http_relation : ops .testing .Relation ):
53
- ctx = ops .testing .Context (Charm )
52
+ def test_http_tracing_destination (
53
+ sample_charm : Type [ops .CharmBase ], mock_destination : Mock , http_relation : ops .testing .Relation
54
+ ):
55
+ ctx = ops .testing .Context (sample_charm )
54
56
state = ops .testing .State (relations = {http_relation })
55
57
ctx .run (ctx .on .relation_changed (http_relation ), state )
56
58
mock_destination .assert_called_with (url = 'http://tracing.example:4318/v1/traces' , ca = None )
57
59
58
60
59
61
@pytest .mark .parametrize ('relation_to_poke' , [0 , 1 ])
60
62
def test_https_tracing_destination (
63
+ sample_charm : Type [ops .CharmBase ],
61
64
mock_destination : Mock ,
62
65
https_relation : ops .testing .Relation ,
63
66
ca_relation : ops .testing .Relation ,
64
67
relation_to_poke : int ,
65
68
):
66
- ctx = ops .testing .Context (Charm )
69
+ ctx = ops .testing .Context (sample_charm )
67
70
state = ops .testing .State (relations = {https_relation , ca_relation })
68
71
ctx .run (ctx .on .relation_changed ([https_relation , ca_relation ][relation_to_poke ]), state )
69
72
mock_destination .assert_called_with (url = 'https://tls.example/v1/traces' , ca = 'FIRST\n SECOND' )
0 commit comments