diff --git a/cmd/repl/repl_test.go b/cmd/repl/repl_test.go index 414a2be..efd93dc 100644 --- a/cmd/repl/repl_test.go +++ b/cmd/repl/repl_test.go @@ -15,6 +15,9 @@ package main import ( + "errors" + "os" + "path/filepath" "strings" "testing" ) @@ -34,14 +37,14 @@ func TestValidateFlags(t *testing.T) { }, { name: "cql file suffix is valid", - cqlInputText: "/tmp/cql.cql", + cqlInputText: filepath.Join("tmp", "cql.cql"), bundleFileText: "", valuesetDirText: "", }, { name: "bundle json suffix is valid", cqlInputText: "", - bundleFileText: "/tmp/bundle.json", + bundleFileText: filepath.Join("tmp", "bundle.json"), valuesetDirText: "", }, { @@ -70,7 +73,7 @@ func TestValidateFlagsError(t *testing.T) { }{ { name: "cql file without cql suffix returns error", - cqlInputText: "/tmp/cql.txt", + cqlInputText: filepath.Join("tmp", "cql.txt"), bundleFileText: "", valuesetDirText: "", wantErr: "--cql_file flag is required to be a valid .cql", @@ -78,7 +81,7 @@ func TestValidateFlagsError(t *testing.T) { { name: "bundle json file without json suffix returns error", cqlInputText: "", - bundleFileText: "/tmp/bundle.txt", + bundleFileText: filepath.Join("tmp", "bundle.txt"), valuesetDirText: "", wantErr: "--bundle_file when specified, is required to be a valid json file", }, @@ -86,7 +89,7 @@ func TestValidateFlagsError(t *testing.T) { name: "invalid directory returns error", cqlInputText: "", bundleFileText: "", - valuesetDirText: "/my/fake/dir", + valuesetDirText: filepath.Join("my", "fake", "dir"), wantErr: "no such file or directory", }, } @@ -98,3 +101,30 @@ func TestValidateFlagsError(t *testing.T) { }) } } + +func TestValidateFlagPathError(t *testing.T) { + // Path errors can return different text for windows and linux, so we need to assert on the error + // itself, not the error text. + tests := []struct { + name string + cqlInputText string + bundleFileText string + valuesetDirText string + wantErr error + }{ + { + name: "invalid directory returns not exist error", + cqlInputText: "", + bundleFileText: "", + valuesetDirText: filepath.Join("my", "fake", "dir"), + wantErr: os.ErrNotExist, + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + if err := validateFlags(tc.cqlInputText, tc.bundleFileText, tc.valuesetDirText); !errors.Is(err, tc.wantErr) { + t.Errorf("validateFlags() returned unexpected error (-want +got):\n%s, %s", tc.wantErr, err.Error()) + } + }) + } +} diff --git a/internal/iohelpers/files_test.go b/internal/iohelpers/files_test.go index be5efc8..78eb93a 100644 --- a/internal/iohelpers/files_test.go +++ b/internal/iohelpers/files_test.go @@ -208,9 +208,11 @@ func TestWriteFileGCS(t *testing.T) { } } +// gcsPath returns the full GCS path for a given suffixPath. +// Since these are not real file paths, we don't need to use filepath.Join. func gcsPath(t *testing.T, suffixPath string) string { t.Helper() - return "gs://" + filepath.Join(testBucketName, suffixPath) + return "gs://" + testBucketName + "/" + suffixPath } func gcsObject(t *testing.T, content string) testhelpers.GCSObjectEntry {