-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
55 lines (51 loc) · 1.47 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
package psqlfront_test
import (
"testing"
psqlfront "github.com/mashiike/psql-front"
"github.com/samber/lo"
"github.com/stretchr/testify/require"
)
func TestConfigLoadNoError(t *testing.T) {
psqlfront.RegisterOriginType(DummyOriginType, func() psqlfront.OriginConfig {
return &DummyOriginConfig{}
})
defer psqlfront.UnregisterOriginType(DummyOriginType)
cases := []struct {
casename string
path string
check func(t *testing.T, cfg *psqlfront.Config)
}{
{
casename: "empty config",
path: "testdata/config/empty.yaml",
},
{
casename: "default config",
path: "testdata/config/default.yaml",
check: func(t *testing.T, cfg *psqlfront.Config) {
require.EqualValues(t, "postgres://postgres:postgres@localhost:5432/postgres?sslmode=prefer", cfg.CacheDatabase.DSN())
require.EqualValues(t, []string{"dummy-example", "dummy-internal"}, lo.Map(cfg.Origins, func(o *psqlfront.CommonOriginConfig, _ int) string {
return o.ID
}))
require.True(t, *cfg.Stats.Enabled)
},
},
{
casename: "if monitoring interval is zero,fallback enabled = false",
path: "testdata/config/monitoring_interval_zero.yaml",
check: func(t *testing.T, cfg *psqlfront.Config) {
require.False(t, *cfg.Stats.Enabled)
},
},
}
for _, c := range cases {
t.Run(c.casename, func(t *testing.T) {
cfg := psqlfront.DefaultConfig()
err := cfg.Load(c.path)
require.NoError(t, err)
if c.check != nil {
c.check(t, cfg)
}
})
}
}