test: use t.TempDir to create temporary test directory (#6164)

This commit is contained in:
Eng Zer Jun 2023-06-17 21:21:01 +08:00 committed by GitHub
parent 06cd843918
commit b868350fc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 77 deletions

View file

@ -9,11 +9,7 @@ import (
)
func setupProxyTargetCoreDNS(t *testing.T, fn func(string)) {
tmpdir, err := os.MkdirTemp(os.TempDir(), "coredns")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
tmpdir := t.TempDir()
content := `
example.org. IN SOA sns.dns.icann.org. noc.dns.icann.org. 1 3600 3600 3600 3600
@ -23,7 +19,7 @@ google.com. IN A 172.217.25.110
`
path := filepath.Join(tmpdir, "file")
if err = os.WriteFile(path, []byte(content), 0644); err != nil {
if err := os.WriteFile(path, []byte(content), 0644); err != nil {
t.Fatalf("Could not write to temp file: %s", err)
}
defer os.Remove(path)