diff --git a/cmd/venom/root/root.go b/cmd/venom/root/root.go index 36d90914..c34c4540 100644 --- a/cmd/venom/root/root.go +++ b/cmd/venom/root/root.go @@ -18,7 +18,7 @@ func New() *cobra.Command { return rootCmd } -//AddCommands adds child commands to the root command rootCmd. +// AddCommands adds child commands to the root command rootCmd. func addCommands(cmd *cobra.Command) { cmd.AddCommand(run.Cmd) cmd.AddCommand(version.Cmd) diff --git a/cmd/venom/root/root_test.go b/cmd/venom/root/root_test.go new file mode 100644 index 00000000..847d7874 --- /dev/null +++ b/cmd/venom/root/root_test.go @@ -0,0 +1,35 @@ +package root + +import ( + "os/exec" + "path/filepath" + "strings" + "testing" + + "github.com/ovh/venom" + "github.com/stretchr/testify/assert" +) + +// getTopLevelFolder returns the top level folder of the project +func getTopLevelFolder() string { + out, err := exec.Command("go", "list", "-m", "-f", "{{.Dir}}").Output() + if err != nil { + panic(err) + } + return strings.TrimSpace(string(out)) +} + +// TestRunCmd tests the run command +func TestRunCmd(t *testing.T) { + var validArgs []string + + validArgs = append(validArgs, "run", filepath.Join(getTopLevelFolder(), "tests", "assertions")) + rootCmd := New() + rootCmd.SetArgs(validArgs) + venom.IsTest = "test" + assert.Equal(t, 3, len(rootCmd.Commands())) + err := rootCmd.Execute() + assert.NoError(t, err) + rootCmd.Execute() + +} diff --git a/cmd/venom/run/cmd.go b/cmd/venom/run/cmd.go index 5900b300..d7d85870 100644 --- a/cmd/venom/run/cmd.go +++ b/cmd/venom/run/cmd.go @@ -244,6 +244,7 @@ func initFromEnv(environ []string) ([]string, error) { v := strings.Split(os.Getenv("VENOM_VAR"), " ") variables = v } + if os.Getenv("VENOM_VAR_FROM_FILE") != "" { varFiles = strings.Split(os.Getenv("VENOM_VAR_FROM_FILE"), " ") } diff --git a/venom.go b/venom.go index fd0be3f4..dfd9f5da 100644 --- a/venom.go +++ b/venom.go @@ -27,6 +27,7 @@ var ( IsTest = "" ) +// OSExit is a wrapper for os.Exit func OSExit(exitCode int) { if IsTest != "" { bincover.ExitCode = exitCode