-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon_test.go
More file actions
49 lines (43 loc) · 854 Bytes
/
common_test.go
File metadata and controls
49 lines (43 loc) · 854 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
41
42
43
44
45
46
47
48
49
package controller
import (
"io/ioutil"
"os"
"path"
"strings"
)
func setup() {
tmp, err := ioutil.TempDir("", "pki.io-test")
if err != nil {
panic(err)
}
if err := os.Setenv("PKIIO_HOME", path.Join(tmp, "home")); err != nil {
panic(err)
}
if err := os.Setenv("PKIIO_LOCAL", path.Join(tmp, "local")); err != nil {
panic(err)
}
}
func teardown() {
var dir string
home := os.Getenv("PKIIO_HOME")
if home != "" {
dir = home
os.Unsetenv("PKIIO_HOME")
} else {
local := os.Getenv("PKIIO_LOCAL")
if local != "" {
dir = local
os.Unsetenv("PKIIO_LOCAL")
} else {
panic("No PKIIO env variables set")
}
}
parentDir := path.Dir(dir)
if strings.Contains(parentDir, "pki.io-test") {
if err := os.RemoveAll(parentDir); err != nil {
panic(err)
}
} else {
panic("Directory isn't a pki.io test directory")
}
}