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

rollouts: add unit test and fake client for simple reconcileRollouts case #3894

Merged
merged 2 commits into from
Mar 25, 2023

Conversation

natasha41575
Copy link
Contributor

@natasha41575 natasha41575 commented Mar 23, 2023

This PR adds a unit test for a simple case for reconcileRollouts. To support the unit test, this PR adds a fake client and refactors a few things out of reconcileRollout. I'd like to add the remaining unit tests in a followup, so that the review here can focus on structure of the test, fake client code, and refactoring, and the followup PR can focus on code coverage.

I looked at using https://github.com/golang/mock for the fake client, but felt that this fake client is simple enough that another framework wasn't needed. Happy to revisit this idea though.

Related issue: #3856

@natasha41575 natasha41575 requested a review from droot March 23, 2023 20:48
@natasha41575 natasha41575 requested a review from a team as a code owner March 23, 2023 20:48
@natasha41575 natasha41575 changed the title rollouts: unit test for simple case rollouts: add unit test and fake client for simple reconcileRollouts case Mar 23, 2023
Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

I like the approach. It is much simpler and will help a ton in reproducing edge scenario.
I have some minor comments.

rollouts/controllers/fakeclient.go Outdated Show resolved Hide resolved
rollouts/controllers/fakeclient.go Outdated Show resolved Hide resolved
rollouts/controllers/rollout_controller.go Outdated Show resolved Hide resolved
targetClusters,
[]packagediscovery.DiscoveredPackage{discoveredPackage},
)
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we using this style of assertions in other parts of kpt project ? otherwise I have found omega matchers to be very good for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a number of places in kpt repo that we are using the testify/assert and testify/require packages to do similar assertions in unit tests. require is a subtly different flavor of assert, except that require exits the test immediately, while assert continues running the rest of the test even when it encounters an error.

That said, I am happy to convert to omega matchers if you prefer!

Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't see usage of require before. But the failure behavior of require does make more sense.

I am fine using require here, so let's ship it.

@natasha41575 natasha41575 requested a review from droot March 24, 2023 21:44
targetClusters,
[]packagediscovery.DiscoveredPackage{discoveredPackage},
)
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't see usage of require before. But the failure behavior of require does make more sense.

I am fine using require here, so let's ship it.

@natasha41575 natasha41575 merged commit 4cee890 into kptdev:main Mar 25, 2023
@natasha41575 natasha41575 deleted the rollouts/unittest branch March 25, 2023 02:58
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.

None yet

2 participants