Skip to content

Commit

Permalink
remove 'HOME' from expected env vars
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Henderson <[email protected]>
  • Loading branch information
hairyhenderson committed Jan 21, 2024
1 parent f20e904 commit 340840b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 3 additions & 1 deletion internal/datafs/envfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions internal/datafs/fsys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down
10 changes: 6 additions & 4 deletions internal/datafs/wdfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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 == "/" {
Expand Down Expand Up @@ -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}
}
Expand Down

0 comments on commit 340840b

Please sign in to comment.