-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
馃悰 Fix issue found to re-generate the scaffolds with the new alpha command and adding e2e tests #3461
馃悰 Fix issue found to re-generate the scaffolds with the new alpha command and adding e2e tests #3461
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package alphagenerate | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
// Run e2e tests using the Ginkgo runner. | ||
func TestE2E(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
fmt.Fprintf(GinkgoWriter, "Starting kubebuilder suite test for the alpha command generate\n") | ||
RunSpecs(t, "Kubebuilder alpha generate suite") | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,96 @@ | ||||||||
/* | ||||||||
Copyright 2023 The Kubernetes Authors. | ||||||||
|
||||||||
Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||
you may not use this file except in compliance with the License. | ||||||||
You may obtain a copy of the License at | ||||||||
|
||||||||
http://www.apache.org/licenses/LICENSE-2.0 | ||||||||
|
||||||||
Unless required by applicable law or agreed to in writing, software | ||||||||
distributed under the License is distributed on an "AS IS" BASIS, | ||||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||
See the License for the specific language governing permissions and | ||||||||
limitations under the License. | ||||||||
*/ | ||||||||
|
||||||||
package alphagenerate | ||||||||
|
||||||||
import ( | ||||||||
"fmt" | ||||||||
"path/filepath" | ||||||||
|
||||||||
pluginutil "sigs.k8s.io/kubebuilder/v3/pkg/plugin/util" | ||||||||
|
||||||||
. "github.com/onsi/ginkgo/v2" | ||||||||
. "github.com/onsi/gomega" | ||||||||
|
||||||||
"sigs.k8s.io/kubebuilder/v3/test/e2e/utils" | ||||||||
) | ||||||||
|
||||||||
var _ = Describe("kubebuilder", func() { | ||||||||
Context("alpha generate ", func() { | ||||||||
var ( | ||||||||
kbc *utils.TestContext | ||||||||
) | ||||||||
|
||||||||
BeforeEach(func() { | ||||||||
var err error | ||||||||
kbc, err = utils.NewTestContext(pluginutil.KubebuilderBinName, "GO111MODULE=on") | ||||||||
Expect(err).NotTo(HaveOccurred()) | ||||||||
Expect(kbc.Prepare()).To(Succeed()) | ||||||||
}) | ||||||||
|
||||||||
AfterEach(func() { | ||||||||
kbc.Destroy() | ||||||||
}) | ||||||||
|
||||||||
It("should regenerate the project with success", func() { | ||||||||
ReGenerateProject(kbc) | ||||||||
}) | ||||||||
|
||||||||
}) | ||||||||
}) | ||||||||
|
||||||||
// ReGenerateProject implements a project that is regenerated by kubebuilder. | ||||||||
func ReGenerateProject(kbc *utils.TestContext) { | ||||||||
var err error | ||||||||
|
||||||||
By("initializing a project") | ||||||||
err = kbc.Init( | ||||||||
"--plugins", "go/v4", | ||||||||
"--project-version", "3", | ||||||||
"--domain", kbc.Domain, | ||||||||
) | ||||||||
ExpectWithOffset(1, err).NotTo(HaveOccurred()) | ||||||||
|
||||||||
By("regenerating the project") | ||||||||
err = kbc.Regenerate( | ||||||||
"--input-dir", kbc.Dir, | ||||||||
"--output-dir", filepath.Join(kbc.Dir, "testdir"), | ||||||||
) | ||||||||
ExpectWithOffset(1, err).NotTo(HaveOccurred()) | ||||||||
|
||||||||
By("checking if the project file was generated with the expected layout") | ||||||||
var layout = `layout: | ||||||||
- go.kubebuilder.io/v4 | ||||||||
` | ||||||||
fileContainsExpr, err := pluginutil.HasFileContentWith( | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a description so we have further info when fails to know where it failed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good idea. |
||||||||
filepath.Join(kbc.Dir, "testdir", "PROJECT"), layout) | ||||||||
ExpectWithOffset(1, err).NotTo(HaveOccurred()) | ||||||||
ExpectWithOffset(1, fileContainsExpr).To(BeTrue()) | ||||||||
|
||||||||
By("checking if the project file was generated with the expected domain") | ||||||||
var domain = fmt.Sprintf("domain: %s", kbc.Domain) | ||||||||
fileContainsExpr, err = pluginutil.HasFileContentWith( | ||||||||
filepath.Join(kbc.Dir, "testdir", "PROJECT"), domain) | ||||||||
ExpectWithOffset(1, err).NotTo(HaveOccurred()) | ||||||||
ExpectWithOffset(1, fileContainsExpr).To(BeTrue()) | ||||||||
|
||||||||
By("checking if the project file was generated with the expected version") | ||||||||
var version = `version: "3"` | ||||||||
fileContainsExpr, err = pluginutil.HasFileContentWith( | ||||||||
filepath.Join(kbc.Dir, "testdir", "PROJECT"), version) | ||||||||
ExpectWithOffset(1, err).NotTo(HaveOccurred()) | ||||||||
ExpectWithOffset(1, fileContainsExpr).To(BeTrue()) | ||||||||
} |
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.
could we do all the appends together?
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.
No, I tried this and it will not compile: