-
Notifications
You must be signed in to change notification settings - Fork 24
Unit tests for api.go #27
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
Conversation
|
Working fine. |
laxmikantbpandhare
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
jmrodri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put in the It
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above
pkg/quarkus/v1alpha/api_test.go
Outdated
| Expect(kindError).To(HaveOccurred()) | ||
| }) | ||
|
|
||
| noErr := testAPISubcommand.InjectResource(&testResource) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This too
b00cc56 to
0838cb1
Compare
jmrodri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
Added unit tests for v1alpha/api.go
Note: These tests depend on the
v1_suite_test.gotest suite file from this PR: #24.