diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2020-08-04 18:10:36 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2020-08-05 13:23:21 +0300 |
commit | 33801fe9ba05c4bd304ebd8e40eb1337309f6b48 (patch) | |
tree | b87bdce7099c8f8c11ba9ecfe0ba81470ce38258 /internal/testhelpers | |
parent | b2922c74ae775f4a56c784572c6672fa2c7332fa (diff) |
Fix tests that use illegal ../ paths
Diffstat (limited to 'internal/testhelpers')
-rw-r--r-- | internal/testhelpers/chdir.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/internal/testhelpers/chdir.go b/internal/testhelpers/chdir.go new file mode 100644 index 00000000..4015d888 --- /dev/null +++ b/internal/testhelpers/chdir.go @@ -0,0 +1,29 @@ +package testhelpers + +import ( + "os" + "testing" + + "github.com/stretchr/testify/require" +) + +func ChdirInPath(t testing.TB, path string, chdirSet *bool) func() { + t.Helper() + + if *chdirSet { + return func() {} + } + + cwd, err := os.Getwd() + require.NoError(t, err, "Cannot Getwd") + + require.NoError(t, os.Chdir(path), "Cannot Chdir") + + *chdirSet = true + return func() { + err := os.Chdir(cwd) + require.NoError(t, err, "Cannot Chdir in cleanup") + + *chdirSet = false + } +} |