Skip to content

Commit

Permalink
commands/.../test.go: allow passing of flags to go test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNPavel committed Aug 9, 2018
1 parent 9cdfbf1 commit fea3429
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 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,13 +29,12 @@ 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]",
Use: "test --test-location <path to tests directory> [flags] args [go test flags]",
Short: "Run End-To-End tests",
Run: testFunc,
}
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 fea3429

Please sign in to comment.