diff --git a/internal/datafs/envfs_test.go b/internal/datafs/envfs_test.go index cb1fce695..d8bfd092b 100644 --- a/internal/datafs/envfs_test.go +++ b/internal/datafs/envfs_test.go @@ -71,6 +71,8 @@ func TestEnvFile_Stat(t *testing.T) { } func TestEnvFS(t *testing.T) { + t.Cleanup(func() { environ = os.Environ }) + u, _ := url.Parse("env:") lfsys := fstest.MapFS{} @@ -96,7 +98,7 @@ func TestEnvFS(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "hello world", string(b)) - assert.NoError(t, fstest.TestFS(fsys, "FOO", "FOO_FILE", "HOME")) + assert.NoError(t, fstest.TestFS(fsys, "FOO", "FOO_FILE")) } func TestEnvFile_ReadDir(t *testing.T) { diff --git a/internal/datafs/fsys_test.go b/internal/datafs/fsys_test.go index ca30f9120..269c4d72f 100644 --- a/internal/datafs/fsys_test.go +++ b/internal/datafs/fsys_test.go @@ -15,6 +15,8 @@ import ( ) func TestFSysForPath(t *testing.T) { + vol, _, _ := getVolWd() + t.Run("no provider", func(t *testing.T) { ctx := ContextWithFSProvider(context.Background(), nil) _, err := FSysForPath(ctx, "foo") @@ -29,12 +31,12 @@ func TestFSysForPath(t *testing.T) { assert.Equal(t, "file", u.Scheme) if runtime.GOOS == "windows" { - assert.Equal(t, "C:/tmp/foo/", u.Path) - return os.DirFS("C:/tmp/foo/"), nil + assert.Equal(t, vol+"/tmp/foo/", u.Path) + return os.DirFS(vol + "/"), nil } assert.Equal(t, "/tmp/foo", u.Path) - return os.DirFS("/tmp/foo"), nil + return os.DirFS("/"), nil }, "file") ctx := ContextWithFSProvider(context.Background(), fsp) @@ -60,7 +62,7 @@ func TestFSysForPath(t *testing.T) { fsp := fsimpl.FSProviderFunc(func(u *url.URL) (fs.FS, error) { assert.Equal(t, "git+file", u.Scheme) if runtime.GOOS == "windows" { - assert.Equal(t, "C:/tmp/repo/", u.Path) + assert.Equal(t, vol+"/tmp/repo/", u.Path) } else { assert.Equal(t, "/tmp/repo", u.Path) } diff --git a/internal/datafs/wdfs.go b/internal/datafs/wdfs.go index 38a2c8ed6..20cef0679 100644 --- a/internal/datafs/wdfs.go +++ b/internal/datafs/wdfs.go @@ -31,7 +31,7 @@ func ResolveLocalPath(fsys fs.FS, name string) (root, resolved string, err error default: } - vol, wd, err := getWdVol() + vol, wd, err := getVolWd() if err != nil { return "", "", err } @@ -40,7 +40,9 @@ func ResolveLocalPath(fsys fs.FS, name string) (root, resolved string, err error return f.resolveLocalPath(name) } -func getWdVol() (string, string, error) { +// getVolWd - returns the volume name and current working directory, or "/" if +// the current working directory has no volume name (e.g. on Unix). +func getVolWd() (string, string, error) { wd, err := os.Getwd() if err != nil { return "", "", fmt.Errorf("getwd: %w", err) @@ -208,7 +210,7 @@ var WdFS = fsimpl.FSProviderFunc( return nil, fmt.Errorf("unsupported path %q: %w", u.Path, fs.ErrInvalid) } - vol, wd, _ := getWdVol() + vol, wd, _ := getVolWd() var fsys fs.FS if vol == "" || vol == "/" { @@ -237,7 +239,7 @@ func WrapWdFS(fsys fs.FS) fs.FS { return fsys } - vol, wd, _ := getWdVol() + vol, wd, _ := getVolWd() return &wdFS{fsys: fsys, vol: vol, wd: wd} }