Skip to content

Commit

Permalink
chore: re-add unit test for pusing certs to container
Browse files Browse the repository at this point in the history
Signed-off-by: guillaume <guillaume.belanger27@gmail.com>
  • Loading branch information
gruyaume committed Aug 16, 2024
1 parent 43cdf82 commit 58f0f4d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@


class TestCharm:
@pytest.fixture(autouse=True)
def setup(self):
self.mock_open = mock_open()
self.patcher = patch("builtins.open", self.mock_open)
self.patcher.start()

@pytest.fixture(autouse=True)
def context(self):
self.ctx = scenario.Context(
Expand Down Expand Up @@ -85,6 +91,30 @@ def test_given_valid_config_when_collect_unit_status_then_status_is_active(

assert state_out.unit_status == ActiveStatus()

@patch("charm.generate_private_key")
@patch("charm.generate_ca")
def test_given_valid_config_when_config_changed_then_ca_certificate_is_pushed_to_charm_container( # noqa: E501
self,
patch_generate_ca,
patch_generate_private_key,
):
ca_certificate_string = "whatever CA certificate"
private_key_string = "whatever private key"
patch_generate_ca.return_value = ca_certificate_string
patch_generate_private_key.return_value = private_key_string
state_in = scenario.State(
config={
"ca-common-name": "pizza.com",
"certificate-validity": 100,
"root-ca-validity": 200,
},
leader=True,
)

self.ctx.run(event="config_changed", state=state_in)

self.mock_open.return_value.write.assert_called_with(ca_certificate_string)

@patch("charm.generate_private_key")
@patch("charm.generate_ca")
def test_given_valid_config_when_config_changed_then_ca_certificate_is_stored_in_juju_secret(
Expand Down

0 comments on commit 58f0f4d

Please sign in to comment.