sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/cli/completion_test.go (about) 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 })