Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve k8s charm test coverage #1199

Merged
merged 5 commits into from
Apr 30, 2024

Conversation

kian99
Copy link
Contributor

@kian99 kian99 commented Apr 29, 2024

Description

Improve the JIMM k8s charm unit test coverage.
Adds tests for:

  • The create-authorization-model action.
  • Adding a postgres relation.
  • The stop hook.
  • The update-status hook.
  • The certificate relation joined and certificate available hooks.

Updated the postgres relation library to the latest one as the previously used one was deprecated. Also removed some unused code.

Partially addresses CSS-8235

Engineering checklist

Check only items that apply

  • Documentation updated
  • Covered by unit tests
  • Covered by integration tests

kian99 added 2 commits April 29, 2024 15:51
- Added tests for create-auth-model action.
- Added tests for Postgres relation.
- Updated database lib to the latest maintained.
Copy link
Contributor

@ale8k ale8k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@babakks babakks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a suggestion; if we add this to pyproject.toml then we can see the uncovered branches in the final report:

[tool.coverage.run]
branch = true

Comment on lines 413 to 431
def mocked_requests_post(*args, **kwargs):
class MockResponse:
def __init__(self, json_data, status_code):
self.json_data = json_data
self.status_code = status_code
self.ok = True

def json(self):
return self.json_data

return MockResponse({"authorization_model_id": 123}, 200)

@mock.patch("src.charm.requests.post")
def test_create_auth_model_action(self, mock_post):
mock_post.side_effect = self.mocked_requests_post
self.harness.enable_hooks()
self.add_openfga_relation()
self.harness.run_action("create-authorization-model", {"model": "null"})
self.assertEqual(self.harness.charm._state.openfga_auth_model_id, 123)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If mocked_requests_post is only used in this test (test_create_auth_model_action), I think it's better to move it's definition to the body of the test (instead of defining it at the class scope).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, can do.

@kian99 kian99 merged commit 548aa2d into canonical:feature-oidc Apr 30, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants