-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig_test.go
More file actions
89 lines (68 loc) · 1.7 KB
/
config_test.go
File metadata and controls
89 lines (68 loc) · 1.7 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package config
import (
"github.com/stretchr/testify/require"
"os"
"path"
"testing"
"github.com/adrg/xdg"
)
func TestSetGetValue(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
xdg.Reload()
err := SetValue("team", "my-team")
if err != nil {
t.Fatal(err)
}
got, err := GetValue("team")
if err != nil {
t.Fatal(err)
}
if got != "my-team" {
t.Fatalf("expected %q, got %q", "my-team", got)
}
err = UnsetValue("team")
if err != nil {
t.Fatal(err)
}
got, err = GetValue("team")
if err != nil {
t.Fatal(err)
}
if got != "" {
t.Fatalf("expected %q, got %q", "", got)
}
}
func TestSetConfigHome(t *testing.T) {
r := require.New(t)
configDir := t.TempDir()
err := SetConfigHome(configDir)
r.NoError(err)
r.Equal(configDir, xdg.ConfigHome)
err = SetValue("team", "set-config-test-value")
r.NoError(err)
// check that the config file was created in the temporary directory,
// not somewhere else
_, err = os.Stat(path.Join(configDir, "cloudquery", "config.json"))
r.NoError(err)
err = UnsetConfigHome()
r.NoError(err)
// check that we are no longer set to the temporary directory
r.NotEqual(configDir, xdg.ConfigHome)
}
func TestSetDataHome(t *testing.T) {
r := require.New(t)
configDir := t.TempDir()
err := SetDataHome(configDir)
r.NoError(err)
r.Equal(configDir, xdg.DataHome)
err = SaveDataString("cloudquery/token", "my-token")
r.NoError(err)
// check that the config file was created in the temporary directory,
// not somewhere else
_, err = os.Stat(path.Join(configDir, "cloudquery", "token"))
r.NoError(err)
err = UnsetDataHome()
r.NoError(err)
// check that we are no longer set to the temporary directory
r.NotEqual(configDir, xdg.DataHome)
}