Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify tests by refactoring to T.TempDir #239

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions errcheck/errcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,11 @@ package custom
`
)

tmpGopath, err := os.MkdirTemp("", "testbuildtags")
if err != nil {
t.Fatalf("unable to create testbuildtags directory: %v", err)
}
tmpGopath := t.TempDir()
testBuildTagsDir := path.Join(tmpGopath, "src", "github.com/testbuildtags")
if err := os.MkdirAll(testBuildTagsDir, 0755); err != nil {
t.Fatalf("MkdirAll failed: %v", err)
}
defer func() {
os.RemoveAll(tmpGopath)
}()

if err := os.WriteFile(path.Join(testBuildTagsDir, "go.mod"), []byte("module github.com/testbuildtags"), 0644); err != nil {
t.Fatalf("Failed to write testbuildtags go.mod: %v", err)
Expand Down Expand Up @@ -228,17 +222,11 @@ require github.com/testlog v0.0.0
}`

// copy testvendor directory into directory for test
tmpGopath, err := os.MkdirTemp("", "testvendor")
if err != nil {
t.Fatalf("unable to create testvendor directory: %v", err)
}
tmpGopath := t.TempDir()
testVendorDir := path.Join(tmpGopath, "src", "github.com/testvendor")
if err := os.MkdirAll(testVendorDir, 0755); err != nil {
t.Fatalf("MkdirAll failed: %v", err)
}
defer func() {
os.RemoveAll(tmpGopath)
}()

if err := os.WriteFile(path.Join(testVendorDir, "go.mod"), []byte(testVendorGoMod), 0755); err != nil {
t.Fatalf("Failed to write testvendor go.mod: %v", err)
Expand Down Expand Up @@ -335,17 +323,11 @@ require github.com/testlog v0.0.0
}`

// copy testvendor directory into directory for test
tmpGopath, err := os.MkdirTemp("", "testvendor")
if err != nil {
t.Fatalf("unable to create testvendor directory: %v", err)
}
tmpGopath := t.TempDir()
testVendorDir := path.Join(tmpGopath, "src", "github.com/testvendor")
if err := os.MkdirAll(testVendorDir, 0755); err != nil {
t.Fatalf("MkdirAll failed: %v", err)
}
defer func() {
os.RemoveAll(tmpGopath)
}()

if err := os.WriteFile(path.Join(testVendorDir, "go.mod"), []byte(testVendorGoMod), 0755); err != nil {
t.Fatalf("Failed to write testvendor go.mod: %v", err)
Expand Down
Loading