test: use T.TempDir to create temporary test directory (#3725)

Prior to this commit, temporary directories in tests were created using
`filepath.Join` and `os.MkdirAll`.

This commit replaces `os.MkdirAll` with `t.TempDir` in tests. 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
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun 2022-11-09 00:16:32 +08:00 committed by GitHub
parent e1f881f82b
commit 45ce6f693a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 43 deletions

View file

@ -1,8 +1,6 @@
package databroker
import (
"log"
"os"
"testing"
"github.com/pomerium/pomerium/config"
@ -11,12 +9,6 @@ import (
)
func TestNew(t *testing.T) {
dir, err := os.MkdirTemp("", "example")
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(dir)
tests := []struct {
name string
opts config.Options