Conversation
|
Working fine. |
jmrodri
left a comment
There was a problem hiding this comment.
A few changes to the test structure.
pkg/quarkus/v1alpha/api_test.go
Outdated
| testAPIOptions := &createAPIOptions{ | ||
| CRDVersion: "testVersion", | ||
| Namespaced: true, | ||
| } | ||
| updateTestResource := resource.Resource{} | ||
| testAPIOptions.UpdateResource(&updateTestResource) | ||
|
|
||
| It("verify that resource API's CRDVersion was set", func() { | ||
| Expect(updateTestResource.API.CRDVersion, testAPIOptions.CRDVersion) | ||
| }) | ||
|
|
||
| It("verify that resource API's Namespaced was set", func() { | ||
| Expect(updateTestResource.API.Namespaced, testAPIOptions.Namespaced) | ||
| }) | ||
|
|
||
| It("verify that resource path is an empty string", func() { | ||
| Expect(updateTestResource.Path, "") | ||
| }) | ||
|
|
||
| It("verify that resource controller is false", func() { | ||
| Expect(updateTestResource.Controller).To(BeFalse()) | ||
| }) |
There was a problem hiding this comment.
The UpdateResource method call should be in the It blocks. OR put it in a BeforeEach block.
pkg/quarkus/v1alpha/api_test.go
Outdated
| testAPIOptions := &createAPIOptions{ | ||
| CRDVersion: "testVersion", | ||
| Namespaced: true, | ||
| } | ||
| updateTestResource := resource.Resource{} |
There was a problem hiding this comment.
I would move these into a BeforeEach block.
| testAPIOptions := &createAPIOptions{ | |
| CRDVersion: "testVersion", | |
| Namespaced: true, | |
| } | |
| updateTestResource := resource.Resource{} | |
| var ( | |
| testAPIOptions createAPIOptions | |
| updateTestResource resource.Resource | |
| ) | |
| BeforeEach(func() { | |
| testAPIOptions = &createAPIOptions{ | |
| CRDVersion: "testVersion", | |
| Namespaced: true, | |
| } | |
| updateTestResource = resource.Resource{} | |
| }) |
pkg/quarkus/v1alpha/api_test.go
Outdated
| Namespaced: true, | ||
| } | ||
| updateTestResource := resource.Resource{} | ||
| testAPIOptions.UpdateResource(&updateTestResource) |
There was a problem hiding this comment.
Make this call inside the It blocks. Or you could put all of the expects in a single It. Either way is fine. I'm okay with it being in multiple Its.
| testAPIOptions.UpdateResource(&updateTestResource) | |
| It("...", func() { | |
| testAPIOptions.UpdateResource(&updateTestResource) | |
| Expect(....) | |
| }) |
pkg/quarkus/v1alpha/api_test.go
Outdated
| testAPIOptions.UpdateResource(&updateTestResource) | ||
|
|
||
| It("verify that resource API's CRDVersion was set", func() { | ||
| Expect(updateTestResource.API.CRDVersion, testAPIOptions.CRDVersion) |
There was a problem hiding this comment.
This suggestion applies to all the Expects
| Expect(updateTestResource.API.CRDVersion, testAPIOptions.CRDVersion) | |
| Expect(updateTestResource.API.CRDVersion).To(Equal(testAPIOptions.CRDVersion)) |
pkg/quarkus/v1alpha/api_test.go
Outdated
|
|
||
| Describe("BindFlags", func() { | ||
| flagTest := pflag.NewFlagSet("testFlag", -1) | ||
| testAPISubcommand.BindFlags(flagTest) |
| Describe("Run", func() { | ||
| It("should return nil", func() { | ||
| Expect(testAPISubcommand.Run(machinery.Filesystem{})).To(BeNil()) | ||
| }) | ||
| }) | ||
|
|
||
| Describe("Validate", func() { | ||
| It("should return nil", func() { | ||
| Expect(testAPISubcommand.Validate()).To(BeNil()) | ||
| }) | ||
| }) | ||
|
|
||
| Describe("PostScaffold", func() { | ||
| It("should return nil", func() { | ||
| Expect(testAPISubcommand.PostScaffold()).To(BeNil()) | ||
| }) | ||
| }) |
There was a problem hiding this comment.
These tests are using a testApiSubcommand that you created in another test. You want tests to always have a clean version, they should not depend on what happens in another test. That's why the BeforeEach comes in handy.
pkg/quarkus/v1alpha/api_test.go
Outdated
| Plural: "test-plural", | ||
| } | ||
|
|
||
| groupErr := failAPISubcommand.InjectResource(&failResource) |
There was a problem hiding this comment.
These calls should be included with the It blocks. Basically consider the It as a specific test and it should include the call and the expectations.
pkg/quarkus/v1alpha/api_test.go
Outdated
| failResource.GVK.Group = "test-group" | ||
| versionErr := failAPISubcommand.InjectResource(&failResource) |
There was a problem hiding this comment.
This has to be inside the It block. Otherwise you are affecting subsequent tests.
pkg/quarkus/v1alpha/api_test.go
Outdated
| failResource.GVK.Version = "v1" | ||
| kindError := failAPISubcommand.InjectResource(&failResource) |
pkg/quarkus/v1alpha/api_test.go
Outdated
| Expect(kindError).To(HaveOccurred()) | ||
| }) | ||
|
|
||
| noErr := testAPISubcommand.InjectResource(&testResource) |
b00cc56 to
0838cb1
Compare
Added unit tests for v1alpha/api.go
Note: These tests depend on the
v1_suite_test.gotest suite file from this PR: #24.