From 099a6bc60224c4e02aadc98362a85fa271abedde Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Sat, 22 Apr 2023 20:41:40 +0530 Subject: [PATCH] Update version_test.go removed extralines updated tests Create version_test.go --- pkg/cli/version.go | 3 +-- pkg/cli/version_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 pkg/cli/version_test.go diff --git a/pkg/cli/version.go b/pkg/cli/version.go index ad16d615cd8..ef4a7ff318b 100644 --- a/pkg/cli/version.go +++ b/pkg/cli/version.go @@ -29,8 +29,7 @@ func (c CLI) newVersionCmd() *cobra.Command { Long: fmt.Sprintf("Print the %s version", c.commandName), Example: fmt.Sprintf("%s version", c.commandName), RunE: func(_ *cobra.Command, _ []string) error { - fmt.Println(c.version) - return nil + return fmt.Errorf("%s", c.version) }, } } diff --git a/pkg/cli/version_test.go b/pkg/cli/version_test.go new file mode 100644 index 00000000000..7dd53edec14 --- /dev/null +++ b/pkg/cli/version_test.go @@ -0,0 +1,35 @@ +/* +Copyright 2022 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 cli + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +var _ = Describe("newVersionCmd", func() { + It("should print the version number", func() { + cli := CLI{version: "1.0.0", commandName: "myapp"} + cmd := cli.newVersionCmd() + + // execute the command + err := cmd.Execute() + + // verify the output + Expect(err.Error()).To(Equal("1.0.0")) + }) +})