Skip to content

Fixes for tests on windows. #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions cmd/repl/repl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
package main

import (
"errors"
"os"
"path/filepath"
"strings"
"testing"
)
Expand All @@ -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: "",
},
{
Expand Down Expand Up @@ -70,23 +73,23 @@ 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",
},
{
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",
},
{
name: "invalid directory returns error",
cqlInputText: "",
bundleFileText: "",
valuesetDirText: "/my/fake/dir",
valuesetDirText: filepath.Join("my", "fake", "dir"),
wantErr: "no such file or directory",
},
}
Expand All @@ -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())
}
})
}
}
4 changes: 3 additions & 1 deletion internal/iohelpers/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading