Skip to content

Commit 1e28300

Browse files
Add unit testing for files(external) in pkg/cli/alpha
1 parent ab8a683 commit 1e28300

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

pkg/cli/alpha/command_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
//lint:ignore ST1001 we use dot-imports in tests for brevity
15+
16+
package alpha
17+
18+
import (
19+
"testing"
20+
21+
. "github.com/onsi/ginkgo/v2"
22+
. "github.com/onsi/gomega"
23+
)
24+
25+
// Figuring out ways to test run these tests similar to existing.
26+
// Currently unable to run without this on VSCode. Will remove once done
27+
func TestCommand(t *testing.T) {
28+
RegisterFailHandler(Fail)
29+
RunSpecs(t, "alpha")
30+
}
31+
32+
var _ = Describe("NewScaffoldCommand", func() {
33+
When("NewScaffoldCommand", func() {
34+
It("Testing the NewScaffoldCommand", func() {
35+
cmd := NewScaffoldCommand()
36+
Expect(cmd).NotTo(BeNil())
37+
Expect(cmd.Use).NotTo(Equal(""))
38+
Expect(cmd.Use).To(ContainSubstring("generate"))
39+
Expect(cmd.Short).NotTo(Equal(""))
40+
Expect(cmd.Short).To(ContainSubstring("Re-scaffold a Kubebuilder project from its PROJECT file"))
41+
Expect(cmd.Example).NotTo(Equal(""))
42+
Expect(cmd.Example).To(ContainSubstring("kubebuilder alpha generate"))
43+
})
44+
})
45+
})

pkg/cli/alpha/update_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
//lint:ignore ST1001 we use dot-imports in tests for brevity
15+
16+
package alpha
17+
18+
import (
19+
. "github.com/onsi/ginkgo/v2"
20+
. "github.com/onsi/gomega"
21+
)
22+
23+
var _ = Describe("NewUpdateCommand", func() {
24+
When("NewUpdateCommand", func() {
25+
It("Testing the NewUpdateCommand", func() {
26+
cmd := NewUpdateCommand()
27+
Expect(cmd).NotTo(BeNil())
28+
Expect(cmd.Use).NotTo(Equal(""))
29+
Expect(cmd.Use).To(ContainSubstring("update"))
30+
Expect(cmd.Short).NotTo(Equal(""))
31+
Expect(cmd.Short).To(ContainSubstring("Update a Kubebuilder project to a newer version"))
32+
})
33+
})
34+
})

0 commit comments

Comments
 (0)