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

Add mockery test case to token reconciler #446

Merged
merged 27 commits into from
Feb 12, 2024

Conversation

efiacor
Copy link
Contributor

@efiacor efiacor commented Nov 27, 2023

Add mock nephio gitea client.
Add example test case fro deketeToken function.
Anti pattern arises in relation to the gitea client wrapper as it's also being used by the repo reconciler.

@nephio-prow nephio-prow bot requested review from s3wong and tliron November 27, 2023 16:24
@efiacor
Copy link
Contributor Author

efiacor commented Nov 27, 2023

@efiacor
Copy link
Contributor Author

efiacor commented Nov 27, 2023

/hold

@efiacor
Copy link
Contributor Author

efiacor commented Nov 27, 2023

@vjayaramrh
Using your example as a base I added a simple test to the token reconciler deleteToker function.
Some bits would need some clarification regarding the method signature and how the responses can be manipulated but over all, pretty straigh forward.

@@ -39,6 +39,7 @@ type GiteaClient interface {
GetRepo(userName string, repoCRName string) (*gitea.Repository, *gitea.Response, error)
CreateRepo(createRepoOption gitea.CreateRepoOption) (*gitea.Repository, *gitea.Response, error)
EditRepo(userName string, repoCRName string, editRepoOption gitea.EditRepoOption) (*gitea.Repository, *gitea.Response, error)
DeleteAccessToken(value interface{}) (*gitea.Response, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious as to why is this an interface{}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

giteaClient: tt.fields.giteaClient,
finalizer: tt.fields.finalizer,
}
// The below block being setup and processing of mocks before invoking the function to be tested
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the block of code from L85 to L91 can be captured in a function to be reused by every test case that uses mockery, right? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like its generic/common to all yes. I pulled it directly from your other example.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can leave it here for now and maybe refactor later. I'd like to get this PR merged so that I can refactor the Repository unit tests to use Mockery.

@liamfallon
Copy link
Member

/retest

@efiacor
Copy link
Contributor Author

efiacor commented Dec 5, 2023

/retest

@efiacor
Copy link
Contributor Author

efiacor commented Jan 12, 2024

/ok-to-test

@efiacor
Copy link
Contributor Author

efiacor commented Jan 12, 2024

/unhold

@henderiw
Copy link
Contributor

/lgtm
/approve

@nephio-prow nephio-prow bot added the lgtm label Feb 12, 2024
Copy link
Contributor

nephio-prow bot commented Feb 12, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: henderiw

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@nephio-prow nephio-prow bot added the approved label Feb 12, 2024
@nephio-prow nephio-prow bot merged commit 7d81bd2 into nephio-project:main Feb 12, 2024
9 checks passed
@efiacor efiacor deleted the token_rec_mockery branch February 12, 2024 15:20
PrimalPimmy pushed a commit to 5GSEC/nephio that referenced this pull request Aug 2, 2024
Add mock nephio gitea client.
Add example test case fro deketeToken function.
Anti pattern arises in relation to the gitea client wrapper as it's also
being used by the repo reconciler.

---------

Signed-off-by: efiacor <[email protected]>
Co-authored-by: Liam Fallon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants