Skip to content

Commit a1715bd

Browse files
author
wafuwafu13
committed
use TempDir, filepath
1 parent 90ac6e1 commit a1715bd

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package checkcertfile
22

33
import (
4-
"os"
4+
// "os"
55
"os/exec"
6+
"path/filepath"
67
"strings"
78
"testing"
89

@@ -13,24 +14,25 @@ import (
1314
func TestCertFile(t *testing.T) {
1415
goroot, err := exec.Command("go", "env", "GOROOT").Output()
1516
if err != nil {
16-
t.Fatalf("Faild to get GOROOT: %s", err)
17+
t.Fatalf("Failed to get GOROOT: %s", err)
1718
}
18-
err = exec.Command(
19+
20+
tmpDir := t.TempDir()
21+
cmd := exec.Command(
1922
"go",
2023
"run",
21-
strings.TrimSuffix(string(goroot), "\n")+"/src/crypto/tls/generate_cert.go",
24+
filepath.FromSlash(filepath.Join(strings.TrimSuffix(string(goroot), "\n"), "/src/crypto/tls/generate_cert.go")),
2225
"-host",
2326
"localhost",
2427
"-duration",
2528
"720h0m0s", // 30*24*time.Hour
26-
).Run()
29+
)
30+
cmd.Dir = tmpDir
31+
err = cmd.Run()
2732
if err != nil {
28-
t.Fatalf("Faild to generate cert.pem: %s", err)
33+
t.Fatalf("Failed to generate cert.pem: %s", err)
2934
}
3035

31-
ckr := Run([]string{"-f", "./cert.pem", "-w", "35", "-c", "25"})
36+
ckr := Run([]string{"-f", filepath.Join(tmpDir, "cert.pem"), "-w", "35", "-c", "25"})
3237
assert.Equal(t, checkers.WARNING, ckr.Status, "should be WARNING")
33-
34-
os.Remove("./cert.pem")
35-
os.Remove("./key.pem")
3638
}

0 commit comments

Comments
 (0)