add unit tests for cmd/bundle#3247
Conversation
|
@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. |
44fbc81 to
156ab49
Compare
|
this should be good to go |
| PDescribe("Run", func() { | ||
| }) |
There was a problem hiding this comment.
why it is required?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
could you please add // todo(jberkhahn): {desc of what should be done} or remove them ?
| PDescribe("Run", func() { | ||
| }) |
There was a problem hiding this comment.
Why it is required?
| DefaultChannel string | ||
| channels string | ||
| generateOnly bool | ||
| GenerateOnly bool |
There was a problem hiding this comment.
why we need these changes?
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
Why we need to export the NewCreateCmd and NewValidateCmd?
There was a problem hiding this comment.
So i can call them from the tests.
| }) | ||
| }) | ||
|
|
||
| Describe("Validate", func() { |
There was a problem hiding this comment.
Why the validate is in the create_test.go and not in the validate_test.go?
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
| Describe("NewCreateCmd", func() { | |
| Describe("NewCreateCmd should", func() { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Are you unable to write these tests in the same package? I've done this before without issues.
| package bundle_test | |
| package bundle |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
ok, I'll move everything into a single package
|
updated. hopefully I didn't screw up squashing the commits |
| ) | ||
|
|
||
| type bundleCreateCmd struct { | ||
| type createCmd struct { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
woops, forgot to revert this when I moved everything back to private. fixed.
|
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. |
308a77e to
5c73f15
Compare
| 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 |
There was a problem hiding this comment.
It should be another PR it is not part of the ad unit test scope. Could we please split it?
camilamacedo86
left a comment
There was a problem hiding this comment.
Just 2 nits. otherwise, it shows great.
Really tks for your terrific contribution 🥇
Co-authored-by: Camila Macedo <cmacedo@redhat.com>
|
@camilamacedo86 updated |
|
Is there anything else that needs to be changed here or is it good to go? @camilamacedo86 @estroz |
Description of the change:
Add unit tests for the
bundle validateandbundle createcommands.Motivation for the change:
Golang unit tests are another layer of robust CI when paired with the e2e and script testing we currently have.