traefik / yaegi

Yaegi is Another Elegant Go Interpreter
https://pkg.go.dev/github.com/traefik/yaegi
Apache License 2.0
6.94k stars 343 forks source link

test: use `t.TempDir` to create temporary test directory #1527

Closed Juneezee closed 1 year ago

Juneezee commented 1 year ago

This pull request replaces os.MkdirTemp with t.TempDir. We can use the t.TempDir function from the testing package to create temporary directory. The directory created by t.TempDir is automatically removed when the test and all its subtests complete.

Reference: https://pkg.go.dev/testing#T.TempDir

func TestFoo(t *testing.T) {
    // before
    tmpDir, err := os.MkdirTemp("", "")
    if err != nil {
        t.Fatalf("failed to create tmp directory: %v", err)
    }
    defer func() {
        if err := os.RemoveAll(dir); err != nil {
            t.Fatal(err)
        }
    }

    // now
    tmpDir := t.TempDir()
}
CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.