-
Notifications
You must be signed in to change notification settings - Fork 251
/
Copy pathconfig_test.go
47 lines (35 loc) · 913 Bytes
/
config_test.go
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
package helpers
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetConfigDirectoryWithEnv(t *testing.T) {
var previousEnv string
if v, isSet := os.LookupEnv("FLY_CONFIG_DIR"); isSet {
previousEnv = v
}
os.Setenv("FLY_CONFIG_DIR", "/var/db/flyctl")
value, err := GetConfigDirectory()
assert.NoError(t, err)
assert.Equal(t, "/var/db/flyctl", value)
if previousEnv != "" {
os.Setenv("FLY_CONFIG_DIR", previousEnv)
}
}
func TestGetConfigDirectoryDefault(t *testing.T) {
var previousEnv string
if v, isSet := os.LookupEnv("FLY_CONFIG_DIR"); isSet {
previousEnv = v
}
os.Unsetenv("FLY_CONFIG_DIR")
value, err := GetConfigDirectory()
assert.NoError(t, err)
homeDir, err := os.UserHomeDir()
assert.NoError(t, err)
assert.Equal(t, filepath.Join(homeDir, ".fly"), value)
if previousEnv != "" {
os.Setenv("FLY_CONFIG_DIR", previousEnv)
}
}