diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index 9a6367b..3e40e45 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -17,7 +17,6 @@ package cmd import ( "context" - "flag" "fmt" "log" "runtime" @@ -93,10 +92,5 @@ func versionString() string { version = fmt.Sprintf("%s (%s)", version, BuildDate) } - // don't return GoVersion during a test run for consistent test output - if flag.Lookup("test.v") != nil { - return version - } - return fmt.Sprintf("%s, Go Version: %s", version, runtime.Version()) } diff --git a/pkg/cmd/util/util_test.go b/pkg/cmd/util/util_test.go index 272e8e9..ebab4df 100644 --- a/pkg/cmd/util/util_test.go +++ b/pkg/cmd/util/util_test.go @@ -17,11 +17,13 @@ package util import ( "bytes" + "os" "path/filepath" "testing" "github.com/mia-platform/vab/pkg/apis/vab.mia-platform.eu/v1alpha1" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestWriteKustomizationData(t *testing.T) { @@ -114,3 +116,47 @@ func TestGroupFromConfig(t *testing.T) { }) } } + +func TestValidateContextPath(t *testing.T) { + t.Parallel() + + tempDir := t.TempDir() + tests := map[string]struct { + path string + expectedPath string + expectedError string + }{ + "valid path": { + path: tempDir, + expectedPath: tempDir, + }, + "path is not a directory": { + path: func() string { + filePath := filepath.Join(tempDir, "file") + _, err := os.Create(filepath.Join(tempDir, "file")) + require.NoError(t, err) + return filePath + }(), + expectedPath: filepath.Join(tempDir, "file"), + expectedError: "is not a directory", + }, + "path don't exists": { + path: filepath.Join("/", "invalid", "path"), + expectedPath: filepath.Join("/", "invalid", "path"), + expectedError: "no such file or directory", + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + resultPath, err := ValidateContextPath(test.path) + switch len(test.expectedError) { + case 0: + assert.NoError(t, err) + default: + assert.Error(t, err) + } + assert.Equal(t, test.expectedPath, resultPath) + }) + } +}