Skip to content

Commit

Permalink
test: adding test in the root package in order to test the run command (
Browse files Browse the repository at this point in the history
#733)

* adding test in the root package in order to test the run command

Signed-off-by: Fokion Sotiropoulos <[email protected]>
  • Loading branch information
fokion authored Nov 29, 2023
1 parent 0e8d78e commit 75a3d67
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/venom/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 35 additions & 0 deletions cmd/venom/root/root_test.go
Original file line number Diff line number Diff line change
@@ -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()

}
1 change: 1 addition & 0 deletions cmd/venom/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"), " ")
}
Expand Down
1 change: 1 addition & 0 deletions venom.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
IsTest = ""
)

// OSExit is a wrapper for os.Exit
func OSExit(exitCode int) {
if IsTest != "" {
bincover.ExitCode = exitCode
Expand Down

0 comments on commit 75a3d67

Please sign in to comment.