Skip to content

Commit ecc32f7

Browse files
committed
certgen: Use t.TempDir in tests.
This update the test code to make use of the testing.TempDir method introduced in Go 1.15 to ensure the temporary directories are automatically removed when the associated tests and all of their subtests complete.
1 parent a746655 commit ecc32f7

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

cert_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import (
1515
// TestCertCreationWithHosts creates a certificate pair with extra hosts and
1616
// ensures the extra hosts are present in the generated files.
1717
func TestCertCreationWithHosts(t *testing.T) {
18-
certFile, err := os.CreateTemp("", "certfile")
18+
certFile, err := os.CreateTemp(t.TempDir(), "certfile")
1919
if err != nil {
2020
t.Fatalf("Unable to create temp certfile: %s", err)
2121
}
2222
certFile.Close()
2323
defer os.Remove(certFile.Name())
2424

25-
keyFile, err := os.CreateTemp("", "keyfile")
25+
keyFile, err := os.CreateTemp(t.TempDir(), "keyfile")
2626
if err != nil {
2727
t.Fatalf("Unable to create temp keyfile: %s", err)
2828
}
@@ -57,14 +57,14 @@ func TestCertCreationWithHosts(t *testing.T) {
5757
// TestCertCreationWithOutHosts ensures the creating a certificate pair without
5858
// any hosts works as intended.
5959
func TestCertCreationWithOutHosts(t *testing.T) {
60-
certFile, err := os.CreateTemp("", "certfile")
60+
certFile, err := os.CreateTemp(t.TempDir(), "certfile")
6161
if err != nil {
6262
t.Fatalf("Unable to create temp certfile: %s", err)
6363
}
6464
certFile.Close()
6565
defer os.Remove(certFile.Name())
6666

67-
keyFile, err := os.CreateTemp("", "keyfile")
67+
keyFile, err := os.CreateTemp(t.TempDir(), "keyfile")
6868
if err != nil {
6969
t.Fatalf("Unable to create temp keyfile: %s", err)
7070
}

0 commit comments

Comments
 (0)