Skip to content

Commit

Permalink
commands/.../test.go: allow passing of flags to go test (#392)
Browse files Browse the repository at this point in the history
* commands/.../test.go: allow passing of flags to `go test`

* commands/.../test.go: update old usage message
  • Loading branch information
AlexNPavel authored Aug 10, 2018
1 parent 4a995ef commit 0383dff
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions commands/operator-sdk/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cmd

import (
"os"
"strings"

"github.com/operator-framework/operator-sdk/pkg/test"

Expand All @@ -28,10 +29,9 @@ var (
crdManifestPath string
opManifestPath string
rbacManifestPath string
verbose bool
goTestFlags string
)

// TODO: allow users to pass flags through to `go test`
func NewTestCmd() *cobra.Command {
testCmd := &cobra.Command{
Use: "test --test-location <path to tests directory> [flags]",
Expand All @@ -49,20 +49,18 @@ func NewTestCmd() *cobra.Command {
testCmd.Flags().StringVarP(&crdManifestPath, "crd", "c", "deploy/crd.yaml", "Path to CRD manifest")
testCmd.Flags().StringVarP(&opManifestPath, "operator", "o", "deploy/operator.yaml", "Path to operator manifest")
testCmd.Flags().StringVarP(&rbacManifestPath, "rbac", "r", "deploy/rbac.yaml", "Path to RBAC manifest")
testCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose go test")
testCmd.Flags().StringVarP(&goTestFlags, "go-test-flags", "g", "", "Additional flags to pass to go test")

return testCmd
}

func testFunc(cmd *cobra.Command, args []string) {
testArgs := []string{"test", testLocation + "/..."}
if verbose {
testArgs = append(testArgs, "-v")
}
testArgs = append(testArgs, "-"+test.KubeConfigFlag, kubeconfig)
testArgs = append(testArgs, "-"+test.CrdManPathFlag, crdManifestPath)
testArgs = append(testArgs, "-"+test.OpManPathFlag, opManifestPath)
testArgs = append(testArgs, "-"+test.RbacManPathFlag, rbacManifestPath)
testArgs = append(testArgs, "-"+test.ProjRootFlag, mustGetwd())
testArgs = append(testArgs, strings.Split(goTestFlags, " ")...)
execCmd(os.Stdout, "go", testArgs...)
}

0 comments on commit 0383dff

Please sign in to comment.