Skip to content

Commit 3811dd7

Browse files
author
Yash Singh
committed
Added the test coverage for completion.go and version.go
1 parent eb80472 commit 3811dd7

File tree

3 files changed

+132
-1
lines changed

3 files changed

+132
-1
lines changed

pkg/cli/completion_test.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package cli
18+
19+
import (
20+
. "github.com/onsi/ginkgo/v2"
21+
. "github.com/onsi/gomega"
22+
)
23+
24+
var _ = Describe("Completion", func() {
25+
var (
26+
c *CLI
27+
)
28+
29+
BeforeEach(func() {
30+
c = &CLI{}
31+
})
32+
33+
When("newBashCmd", func() {
34+
It("Testing the BashCompletion", func() {
35+
cmd := c.newBashCmd()
36+
Expect(cmd).NotTo(BeNil())
37+
Expect(cmd.Use).NotTo(Equal(""))
38+
Expect(cmd.Use).To(ContainSubstring("bash"))
39+
Expect(cmd.Short).NotTo(Equal(""))
40+
Expect(cmd.Short).To(ContainSubstring("Load bash completions"))
41+
Expect(cmd.Example).NotTo(Equal(""))
42+
Expect(cmd.Example).To(ContainSubstring("# To load completion for this session"))
43+
})
44+
})
45+
46+
Context("newZshCmd", func() {
47+
It("Testing the ZshCompletion", func() {
48+
cmd := c.newZshCmd()
49+
Expect(cmd).NotTo(BeNil())
50+
Expect(cmd.Use).NotTo(Equal(""))
51+
Expect(cmd.Use).To(ContainSubstring("zsh"))
52+
Expect(cmd.Short).NotTo(Equal(""))
53+
Expect(cmd.Short).To(ContainSubstring("Load zsh completions"))
54+
Expect(cmd.Example).NotTo(Equal(""))
55+
Expect(cmd.Example).To(ContainSubstring("# If shell completion is not already enabled in your environment"))
56+
})
57+
})
58+
59+
Context("newFishCmd", func() {
60+
It("Testing the FishCompletion", func() {
61+
cmd := c.newFishCmd()
62+
Expect(cmd).NotTo(BeNil())
63+
Expect(cmd.Use).NotTo(Equal(""))
64+
Expect(cmd.Use).To(ContainSubstring("fish"))
65+
Expect(cmd.Short).NotTo(Equal(""))
66+
Expect(cmd.Short).To(ContainSubstring("Load fish completions"))
67+
Expect(cmd.Example).NotTo(Equal(""))
68+
Expect(cmd.Example).To(ContainSubstring("# To load completion for this session, execute:"))
69+
})
70+
})
71+
72+
Context("newPowerShellCmd", func() {
73+
It("Testing the PowerShellCompletion", func() {
74+
cmd := c.newPowerShellCmd()
75+
Expect(cmd).NotTo(BeNil())
76+
Expect(cmd.Use).NotTo(Equal(""))
77+
Expect(cmd.Use).To(ContainSubstring("powershell"))
78+
Expect(cmd.Short).NotTo(Equal(""))
79+
Expect(cmd.Short).To(ContainSubstring("Load powershell completions"))
80+
})
81+
82+
})
83+
})

pkg/cli/version.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
func (c CLI) newVersionCmd() *cobra.Command {
26-
return &cobra.Command{
26+
cmd := &cobra.Command{
2727
Use: "version",
2828
Short: fmt.Sprintf("Print the %s version", c.commandName),
2929
Long: fmt.Sprintf("Print the %s version", c.commandName),
@@ -33,4 +33,5 @@ func (c CLI) newVersionCmd() *cobra.Command {
3333
return nil
3434
},
3535
}
36+
return cmd
3637
}

pkg/cli/version_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package cli
18+
19+
import (
20+
. "github.com/onsi/ginkgo/v2"
21+
. "github.com/onsi/gomega"
22+
)
23+
24+
var _ = Describe("Version", func() {
25+
var (
26+
c *CLI
27+
)
28+
29+
BeforeEach(func() {
30+
c = &CLI{}
31+
})
32+
33+
Context("newVersionCmd", func() {
34+
It("Test the version", func() {
35+
cmd := c.newVersionCmd()
36+
Expect(cmd).NotTo(BeNil())
37+
Expect(cmd.Use).To(ContainSubstring("version"))
38+
Expect(cmd.Use).NotTo(Equal(""))
39+
Expect(cmd.Short).NotTo(Equal(""))
40+
Expect(cmd.Short).To(ContainSubstring("Print the"))
41+
Expect(cmd.Long).NotTo(Equal(""))
42+
Expect(cmd.Long).To(ContainSubstring("Print the"))
43+
Expect(cmd.Example).NotTo(Equal(""))
44+
Expect(cmd.Example).To(ContainSubstring("version"))
45+
})
46+
})
47+
})

0 commit comments

Comments
 (0)