diff --git a/kyaml/filesys/fsondisk_test.go b/kyaml/filesys/fsondisk_test.go index d349c5063a..fc93e9c7d9 100644 --- a/kyaml/filesys/fsondisk_test.go +++ b/kyaml/filesys/fsondisk_test.go @@ -7,10 +7,12 @@ import ( "os" "path/filepath" "reflect" + "runtime" "sort" "testing" "github.com/stretchr/testify/require" + "golang.org/x/sys/windows" ) const dirMsg = "expected '%s' to be a dir" @@ -58,7 +60,8 @@ func TestCleanedAbs_2(t *testing.T) { req := require.New(t) fSys, _ := makeTestDir(t) - root := getOSRoot(t) + root, err := getOSRoot() + req.NoError(err) d, f, err := fSys.CleanedAbs(root) req.NoError(err) req.Equal(root, d.String()) @@ -122,7 +125,8 @@ func TestConfirmDirDisk(t *testing.T) { err = os.Symlink(filepath.Join(wd, relDir), linkDir) req.NoError(err) - root := getOSRoot(t) + root, err := getOSRoot() + req.NoError(err) tests := map[string]*struct { path string expected string @@ -257,3 +261,12 @@ func TestReadFilesRealFS(t *testing.T) { }) } } + +func getOSRoot() (string, error) { + if runtime.GOOS == "windows" { + sysDir, err := windows.GetSystemDirectory() + return filepath.VolumeName(sysDir) + `\`, err + } else { + return string(filepath.Separator), nil + } +} diff --git a/kyaml/filesys/fsondisk_unix_test.go b/kyaml/filesys/fsondisk_unix_test.go deleted file mode 100644 index 370170526a..0000000000 --- a/kyaml/filesys/fsondisk_unix_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2022 The Kubernetes Authors. -// SPDX-License-Identifier: Apache-2.0 - -//go:build !windows -// +build !windows - -package filesys //nolint - -import ( - "path/filepath" - "testing" -) - -func getOSRoot(t *testing.T) string { - t.Helper() - return string(filepath.Separator) -} diff --git a/kyaml/filesys/fsondisk_windows_test.go b/kyaml/filesys/fsondisk_windows_test.go deleted file mode 100644 index 6c5095fec6..0000000000 --- a/kyaml/filesys/fsondisk_windows_test.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2022 The Kubernetes Authors. -// SPDX-License-Identifier: Apache-2.0 - -package filesys //nolint - -import ( - "path/filepath" - "testing" - - "github.com/stretchr/testify/require" - "golang.org/x/sys/windows" -) - -func getOSRoot(t *testing.T) string { - t.Helper() - - sysDir, err := windows.GetSystemDirectory() - require.NoError(t, err) - return filepath.VolumeName(sysDir) + `\` -}