Skip to content

Commit

Permalink
Revert "Use t.TempDir() instead of os.MkdirTemp() in tests"
Browse files Browse the repository at this point in the history
This reverts commit 9c7b291.
  • Loading branch information
JohnStarich committed Jun 3, 2024
1 parent ab146a3 commit 92b9362
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion gopages/internal/generate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,12 @@ func JSONFunc() {
tc.trySkip(t)
}
// create a new package "thing" and generate docs for it
thing := t.TempDir()
thing, err := os.MkdirTemp("", "")
require.NoError(t, err)
require.NoError(t, os.Chdir(thing))
t.Cleanup(func() {
os.RemoveAll(thing)
})
thingFS := osfs.New("")
outputFS := memfs.New()
writeFile := func(path, contents string) {
Expand Down
12 changes: 9 additions & 3 deletions gopages/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func TestMain(t *testing.T) {
func TestMainArgs(t *testing.T) {
t.Parallel()
cmd.SetupTestExiter(t)
tmp, err := os.MkdirTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(tmp)

for _, tc := range []struct {
description string
Expand Down Expand Up @@ -61,7 +64,6 @@ func TestMainArgs(t *testing.T) {
runner := func(string, flags.Args) error {
return tc.runnerErr
}
tmp := t.TempDir()
getWD := func() (string, error) {
return tmp, tc.wdErr
}
Expand Down Expand Up @@ -109,7 +111,9 @@ func testRun(t *testing.T, tc testRunTestCase) {
}

// create dummy repo to enable cloning
ghPagesDir := t.TempDir()
ghPagesDir, err := os.MkdirTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(ghPagesDir)
const defaultBranch = "refs/heads/main"
ghPagesRepo, err := git.PlainInitWithOptions(ghPagesDir, &git.PlainInitOptions{
InitOptions: git.InitOptions{
Expand All @@ -132,7 +136,9 @@ func testRun(t *testing.T, tc testRunTestCase) {
Branch: defaultBranch,
}))

modulePath := t.TempDir()
modulePath, err := os.MkdirTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(modulePath)
wd, err := os.Getwd()
require.NoError(t, err)
require.NoError(t, os.Chdir(modulePath))
Expand Down

0 comments on commit 92b9362

Please sign in to comment.