Skip to content

Commit

Permalink
Update version_test.go
Browse files Browse the repository at this point in the history
removed extralines

updated tests

Create version_test.go
  • Loading branch information
khareyash05 committed Apr 23, 2023
1 parent ccd8944 commit 099a6bc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pkg/cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
35 changes: 35 additions & 0 deletions pkg/cli/version_test.go
Original file line number Diff line number Diff line change
@@ -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"))
})
})

0 comments on commit 099a6bc

Please sign in to comment.