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

Converted Repository operator tests to Mockery #461

Merged
merged 13 commits into from
Feb 12, 2024

Conversation

liamfallon
Copy link
Member

@liamfallon liamfallon commented Dec 14, 2023

This PR uses the approach and code described by @vjayaramrh in #441 to replace the unit tests for the Repository operator. This PR replaces all the unit tests with Mockery implementations.

@liamfallon
Copy link
Member Author

/assign @efiacor @lapentad @vjayaramrh


func (gc NephioGiteaClientMock) GetMyUserInfo() (*gitea.User, *gitea.Response, error) {
return &gitea.User{}, &gitea.Response{}, gc.myUserInfoError
type mockHelper struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: it may be a good idea to create a separate directory called testing and defined the mockHelper struct there and then could be imported by other packages that will use mockery for unit testing

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

})
}
}

func initMockeryMocks(tt *repoTest) {
Copy link
Contributor

@vjayaramrh vjayaramrh Dec 14, 2023

Choose a reason for hiding this comment

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

Suggestion: This function could be generalized and moved to a the testing folder as well to be reused by others.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@liamfallon liamfallon force-pushed the convert-unit-tests-to-mockery branch from 53aed0c to 4bee818 Compare December 20, 2023 15:39
@liamfallon liamfallon force-pushed the convert-unit-tests-to-mockery branch from 4bee818 to 9201771 Compare January 2, 2024 15:52
@liamfallon
Copy link
Member Author

I need to split the mockeryutils module out into a separate PR so that it can go in first and avoid the missing ref from the reconciler.

@liamfallon
Copy link
Member Author

We need to wait for this PR to be merged
#468

@liamfallon liamfallon added documentation Improvements or additions to documentation do-not-merge/hold and removed documentation Improvements or additions to documentation labels Jan 3, 2024
@liamfallon
Copy link
Member Author

/retest

@liamfallon liamfallon force-pushed the convert-unit-tests-to-mockery branch from 0d766e3 to 2cb7961 Compare January 12, 2024 10:54
@liamfallon
Copy link
Member Author

/retest

1 similar comment
@liamfallon
Copy link
Member Author

/retest

@liamfallon
Copy link
Member Author

@vjayaramrh @efiacor This is ready for review now.

interfaces:
GiteaClient:
config:
dir: "{{.InterfaceDir}}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure on the best way to fix this one but..
The mock file gets picked up by the coverage report. ie 0%
Using the config in mockery we can name the file with a _test suffix, but for me this breaks the import in the test.go.
Alternatively, which is what I plan to do for say the controller-runtime client mock, is to output to a "mocks" dir under controller/pkg and maybe exclude that in the report. Or we suffix them with _test and add the logic for that in the coverage cmd.
Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can we take this discussion separately? Would it be OK to bring this PR in? I'll look at this in a subsequent PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, if it's not here the build fails. The main Makefile expects a Makefile in every submodule that contains "go" files.

@efiacor
Copy link
Collaborator

efiacor commented Jan 18, 2024

/lgtm

@nephio-prow nephio-prow bot added the lgtm label Jan 18, 2024
@efiacor
Copy link
Collaborator

efiacor commented Jan 19, 2024

/approve

@liamfallon liamfallon force-pushed the convert-unit-tests-to-mockery branch from c7194bf to c1251b3 Compare February 2, 2024 10:09
@nephio-prow nephio-prow bot removed the lgtm label Feb 2, 2024
@liamfallon
Copy link
Member Author

@vjayaramrh @efiacor Can we resurrect this work?

@efiacor
Copy link
Collaborator

efiacor commented Feb 2, 2024

/lgtm

@nephio-prow nephio-prow bot added the lgtm label Feb 2, 2024
@liamfallon liamfallon force-pushed the convert-unit-tests-to-mockery branch from c1251b3 to 7e65aa2 Compare February 6, 2024 12:09
@nephio-prow nephio-prow bot removed the lgtm label Feb 6, 2024
@liamfallon
Copy link
Member Author

I need to split the mockeryutils module out into a separate PR so that it can go in first and avoid the missing ref from the reconciler.

Done

@liamfallon
Copy link
Member Author

@s3wong @tliron @johnbelamaric @vjayaramrh Can we get reviews on this please?

@liamfallon liamfallon changed the title Conveted Repository operator tests to Mockery Converted Repository operator tests to Mockery Feb 8, 2024
@henderiw
Copy link
Contributor

/lgtm
/approve

Copy link
Contributor

nephio-prow bot commented Feb 12, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: efiacor, 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 3ddd4e2 into nephio-project:main Feb 12, 2024
9 checks passed
@efiacor efiacor deleted the convert-unit-tests-to-mockery branch February 12, 2024 15:22
PrimalPimmy pushed a commit to 5GSEC/nephio that referenced this pull request Aug 2, 2024
This PR uses the approach and code described by @vjayaramrh in
nephio-project#441 to replace the unit
tests for the Repository operator. This PR replaces all the unit tests
with Mockery implementations.
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.

5 participants