-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsecuretemp_test.go
More file actions
40 lines (34 loc) · 888 Bytes
/
securetemp_test.go
File metadata and controls
40 lines (34 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package securetemp
import (
"os"
"testing"
)
const (
size = DefaultSize
)
func TestTempDir(t *testing.T) {
tmpDir, cleanupFunc, err := TempDir(size)
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
if _, err := os.Stat(tmpDir); err != nil {
t.Fatalf("something is wrong with the temp dir: %v", err)
}
cleanupFunc()
if _, err := os.Stat(tmpDir); err == nil {
t.Fatalf("temp dir %q should no longer exist after cleanup, but does", tmpDir)
}
}
func TestTempFile(t *testing.T) {
tmpFile, cleanupFunc, err := TempFile(size)
if err != nil {
t.Fatalf("failed to create temp file: %v", err)
}
if _, err := tmpFile.Stat(); err != nil {
t.Fatalf("something is wrong with the temp file: %v", err)
}
cleanupFunc()
if _, err := tmpFile.Stat(); err == nil {
t.Fatalf("temp dir %q should no longer exist after cleanup, but does", tmpFile.Name())
}
}