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 unit tests for cmd/bundle #3247

Merged
merged 1 commit into from
Jul 1, 2020

Conversation

jberkhahn
Copy link
Contributor

Description of the change:
Add unit tests for the bundle validate and bundle create commands.

Motivation for the change:
Golang unit tests are another layer of robust CI when paired with the e2e and script testing we currently have.

@jberkhahn jberkhahn added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 16, 2020
@jberkhahn
Copy link
Contributor Author

jberkhahn commented Jun 16, 2020

@estroz started work on this. I've had to refactor a couple things to make them accessible from the tests. I'm leaving the Run() tests as pending for the moment as I'm not sure how to test that stuff without doing the counterfeiter refactor, which we should probably wait for the KB integration before we do that. Please tag anyone else you think might be interested in this.

@jberkhahn jberkhahn force-pushed the bundle_tests branch 3 times, most recently from 44fbc81 to 156ab49 Compare June 18, 2020 00:19
@jberkhahn jberkhahn requested a review from estroz June 18, 2020 00:34
@jberkhahn jberkhahn removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 18, 2020
@jberkhahn
Copy link
Contributor Author

this should be good to go

Comment on lines 129 to 94
PDescribe("Run", func() {
})
Copy link
Contributor

Choose a reason for hiding this comment

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

why it is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put in pending tests just as a reminder that they need to be implemented, but was going to wait until after kubebuilder is merged in because it'll require some additional refactoring. I can remove them if you think that's not needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

could you please add // todo(jberkhahn): {desc of what should be done} or remove them ?

Comment on lines 219 to 146
PDescribe("Run", func() {
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Why it is required?

channels string
generateOnly bool
GenerateOnly bool
Copy link
Contributor

Choose a reason for hiding this comment

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

why we need these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to make a bunch of fields public to be able to set them in the tests. It's because cobra normally populated the fields set via flag when you initialize the command struct, but I can't do it that way because I'm not cobra. So I have to make them public so I can manually set them.

newCreateCmd(),
newValidateCmd(),
NewCreateCmd(),
NewValidateCmd(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we need to export the NewCreateCmd and NewValidateCmd?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So i can call them from the tests.

})
})

Describe("Validate", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the validate is in the create_test.go and not in the validate_test.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is testing the argument validation method of the create command, not the bundle validate command

)

var _ = Describe("Running a bundle validate command", func() {
Describe("NewCreateCmd", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Describe("NewCreateCmd", func() {
Describe("NewCreateCmd should", func() {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer to leave those describes as just the name of the method they're testing

// See the License for the specific language governing permissions and
// limitations under the License.

package bundle_test
Copy link
Member

Choose a reason for hiding this comment

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

Are you unable to write these tests in the same package? I've done this before without issues.

Suggested change
package bundle_test
package bundle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can, but I didn't on purpose. I'm trying to test the functionality of the package as a unit, so I don't want to be able to reach inside and use private stuff, as other packages won't be able to do that.

Copy link
Member

Choose a reason for hiding this comment

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

I would agree if these packages were intended to be libraries. For now can you keep tests in the same package so we don't have to export a bunch of stuff? Before exporting private stuff we should have a conversation about general CLI refactoring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I'll move everything into a single package

@jberkhahn
Copy link
Contributor Author

updated. hopefully I didn't screw up squashing the commits

@@ -32,7 +32,7 @@ import (
"github.com/spf13/pflag"
)

type bundleCreateCmd struct {
type createCmd struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that the name is redundant and we could/should change but it is not part of the scope of this PR.
Could we do a PR just to do the renames?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

woops, forgot to revert this when I moved everything back to private. fixed.

Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

IMO: we are not testing here what we should test. See my comments.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 22, 2020
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 22, 2020
@jberkhahn
Copy link
Contributor Author

Updated. Cut out most of the simple reflective tests, had to do some actual refactoring because something touched validate and added a new image builder, so I incorporated it into the validate func there and added a test for it.

@jberkhahn jberkhahn force-pushed the bundle_tests branch 2 times, most recently from 308a77e to 5c73f15 Compare June 22, 2020 22:36
Copy link
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 23, 2020
if c.imageBuilder != containertools.DockerTool.String() &&
c.imageBuilder != containertools.PodmanTool.String() &&
c.imageBuilder != containertools.NoneTool.String() {
return fmt.Errorf("unrecognized image-builder option: %s", c.imageBuilder)
}

return nil
Copy link
Contributor

@camilamacedo86 camilamacedo86 Jun 23, 2020

Choose a reason for hiding this comment

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

It should be another PR it is not part of the ad unit test scope. Could we please split it?

Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

Just 2 nits. otherwise, it shows great.
Really tks for your terrific contribution 🥇

Co-authored-by: Camila Macedo <[email protected]>
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Jun 24, 2020
@jberkhahn
Copy link
Contributor Author

@camilamacedo86 updated

@jberkhahn
Copy link
Contributor Author

Is there anything else that needs to be changed here or is it good to go? @camilamacedo86 @estroz

Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

👍

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 1, 2020
@camilamacedo86 camilamacedo86 merged commit 80c1672 into operator-framework:master Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants