-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
88 lines (68 loc) · 2.27 KB
/
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
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
package configlite_test
import (
"path"
"testing"
"github.com/stretchr/testify/require"
. "github.com/dgsb/configlite"
)
func TestRepository(t *testing.T) {
t.Run("setup", func(t *testing.T) {
dbFile := path.Join(t.TempDir(), "config.db")
repo, err := New(dbFile)
require.NoError(t, err)
require.NotNil(t, repo)
t.Cleanup(repo.Close)
otherRepo, err := New(dbFile)
require.NoError(t, err)
require.NotNil(t, repo)
t.Cleanup(otherRepo.Close)
})
t.Run("simple config registration", func(t *testing.T) {
repo, err := New(":memory:")
require.NoError(t, err)
require.NotNil(t, repo)
t.Cleanup(repo.Close)
err = repo.RegisterApplication("fakeApp")
require.NoError(t, err)
err = repo.UpsertConfig("fakeApp", "fakeConfig", "fakeValue")
require.NoError(t, err)
config, err := repo.GetConfig("fakeApp", "fakeConfig")
require.NoError(t, err)
require.Equal(t, "fakeValue", config)
err = repo.UpsertConfig("fakeApp", "fakeConfig", "updatedFakeValue")
require.NoError(t, err)
config, err = repo.GetConfig("fakeApp", "fakeConfig")
require.NoError(t, err)
require.Equal(t, "updatedFakeValue", config)
})
t.Run("multiple apps get all config", func(t *testing.T) {
repo, err := New(":memory:")
require.NoError(t, err)
require.NotNil(t, repo)
t.Cleanup(repo.Close)
err = repo.RegisterApplication("fakeApp")
require.NoError(t, err)
err = repo.RegisterApplication("otherFakeApp")
require.NoError(t, err)
err = repo.UpsertConfig("fakeApp", "fakeConfig", "fakeValue")
require.NoError(t, err)
err = repo.UpsertConfig("fakeApp", "secondFakeConfig", "secondFakeValue")
require.NoError(t, err)
err = repo.UpsertConfig("otherFakeApp", "otherFakeConfig", "otherFakeValue")
require.NoError(t, err)
err = repo.UpsertConfig("otherFakeApp", "secondOtherFakeConfig", "secondOtherFakeValue")
require.NoError(t, err)
configs, err := repo.GetConfigs("fakeApp")
require.NoError(t, err)
require.Equal(t, map[string]string{
"fakeConfig": "fakeValue",
"secondFakeConfig": "secondFakeValue",
}, configs)
configs, err = repo.GetConfigs("otherFakeApp")
require.NoError(t, err)
require.Equal(t, map[string]string{
"otherFakeConfig": "otherFakeValue",
"secondOtherFakeConfig": "secondOtherFakeValue",
}, configs)
})
}