Skip to content

refactor(relation): update tests patterns #19465

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

Merged
merged 2 commits into from
Apr 9, 2025

Conversation

gfouillet
Copy link
Contributor

  • change addRelationStatus to setRelationStatus: even if set relation status is actually inserting a row in the relation_status table, this row isn't an entity (no uuid). Better naming is setRelationStatus. I also handle the update usecase for convenience and easier maintainability.
  • make all "add" helpers returning the inserted entity uuid. reduce clutter while arranging test.

More improvement can be done, however it is the most widespread. I don't want to push more in this PR, due to limited time and to avoid conflicts.

QA steps

Unit test still passes

Copy link
Contributor

@Aflynn50 Aflynn50 left a comment

Choose a reason for hiding this comment

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

Amazing, thanks for doing this.

…onStatus`

Even if set relation status is actually inserting a row in the relation_status table, this row isn't
 an entity (no uuid). Better naming is `setRelationStatus`. I also handle the update usecase for
 convenience and easier maintainability.

- `domain/relation/state/relation_test.go`: Updated tests to replace usage of
  `addRelationStatus` with `setRelationStatus`.
- `domain/relation/state/relation.go`: Removed the `addRelationStatus` function
   and introduced `setRelationStatus` with conflict handling for better idempotency.
@gfouillet gfouillet force-pushed the v4/dqlite/relation/refactor-test branch from e5457af to 83a689e Compare April 9, 2025 15:24
Helpers in relation_test add object from an UUID given as argument. This PR inverse the logic and
make all the helpers prefixed by "add" and inserting an actual entity in the db (something that have
a uuid) return the inserted UUID.

It reduce the clutter in the arrange phase of test and provide more flexibility.

- `domain/relation/state/relation_test.go`:
  - Replaced manual UUID generation and variable assignments like `GenRelationUUID` with test
   helper functions (`addCharm`, `addRelation`, and others) for clarity and consistency.
   - Removed unused imports and redundant declarations, simplifying the overall test structure.
@gfouillet gfouillet force-pushed the v4/dqlite/relation/refactor-test branch from 83a689e to 9b9a5c9 Compare April 9, 2025 15:36
@gfouillet
Copy link
Contributor Author

/merge

@jujubot jujubot merged commit cbccd56 into juju:main Apr 9, 2025
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants