Skip to content

Commit

Permalink
test: Fix integration test for version subcommand (aquasecurity#125)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Pacak <pacak.daniel@gmail.com>
  • Loading branch information
danielpacak authored Aug 20, 2020
1 parent 7fec23d commit f799dd7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ build: $(BINARY)
.PHONY: get-ginkgo
## get-ginkgo Installs Ginkgo CLI.
get-ginkgo:
@go get github.com/onsi/ginkgo/ginkgo
go install github.com/onsi/ginkgo/ginkgo

.PHONY: get-qtc
## get-qtc Installs quicktemplate compiler.
get-qtc:
@go get github.com/valyala/quicktemplate/qtc
go install github.com/valyala/quicktemplate/qtc

.PHONY: compile-templates
## compile-templates Converts quicktemplate files (*.qtpl) into Go code.
Expand Down Expand Up @@ -46,4 +46,5 @@ integration-tests: get-ginkgo

.PHONY: clean
clean:
rm -r ./bin
rm -r ./bin
rm -r ./dist
9 changes: 5 additions & 4 deletions itest/starboard_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"time"

. "github.com/onsi/gomega/gbytes"

"github.com/aquasecurity/starboard/pkg/cmd"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -67,14 +69,13 @@ var _ = Describe("Starboard CLI", func() {

Describe("Command version", func() {
It("should print the current version of the executable binary", func() {
out := NewBuffer()
err := cmd.Run(versionInfo, []string{
"starboard",
"version",
}, GinkgoWriter, GinkgoWriter)
}, out, out)
Expect(err).ToNot(HaveOccurred())

// TODO Fix this assert as we no longer use Ginkgo session
// Eventually(session).Should(Say("Starboard Version: {Version:dev Commit:none Date:unknown}\n"))
Eventually(out).Should(Say("Starboard Version: {Version:dev Commit:none Date:unknown}"))
})
})

Expand Down
1 change: 0 additions & 1 deletion itest/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var (
)

var (
pathToStarboardCLI string
starboardCLILogLevel = "0"
versionInfo = cmd.VersionInfo{Version: "dev", Commit: "none", Date: "unknown"}
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewRootCmd(version VersionInfo, args []string, outWriter io.Writer, errWrit

executable := executable(args)

rootCmd.AddCommand(NewVersionCmd(version))
rootCmd.AddCommand(NewVersionCmd(version, outWriter))
rootCmd.AddCommand(NewInitCmd(cf))
rootCmd.AddCommand(NewFindCmd(executable, cf))
rootCmd.AddCommand(NewKubeBenchCmd(cf))
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"io"

"github.com/spf13/cobra"
)
Expand All @@ -12,12 +13,12 @@ type VersionInfo struct {
Date string
}

func NewVersionCmd(version VersionInfo) *cobra.Command {
func NewVersionCmd(version VersionInfo, outWriter io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Print the version information",
RunE: func(cmd *cobra.Command, args []string) (err error) {
fmt.Printf("Starboard Version: %+v\n", version)
_, _ = fmt.Fprintf(outWriter, "Starboard Version: %+v\n", version)
return
},
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// The version command is not supposed to be unit tested, but we keep this file to report test coverage properly.
package cmd_test

0 comments on commit f799dd7

Please sign in to comment.