-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathinfo_test.go
133 lines (106 loc) · 2.9 KB
/
info_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package fxcore_test
import (
"testing"
"github.com/ankorstore/yokai/config"
"github.com/ankorstore/yokai/fxcore"
"github.com/stretchr/testify/assert"
)
type testModuleInfo struct{}
func (i *testModuleInfo) Name() string {
return "test"
}
func (i *testModuleInfo) Data() map[string]interface{} {
return map[string]interface{}{}
}
func TestFxCoreModuleInfo(t *testing.T) {
t.Setenv("APP_ENV", "test")
cfg, err := config.NewDefaultConfigFactory().Create(
config.WithFilePaths("./testdata/config"),
)
assert.NoError(t, err)
info := fxcore.NewFxCoreModuleInfo(
fxcore.FxCoreModuleInfoParam{
Config: cfg,
ExtraInfos: []fxcore.FxExtraInfo{
fxcore.NewFxExtraInfo("foo", "bar"),
fxcore.NewFxExtraInfo("foo", "baz"),
},
},
)
assert.IsType(t, &fxcore.FxCoreModuleInfo{}, info)
assert.Implements(t, (*fxcore.FxModuleInfo)(nil), info)
assert.Equal(t, fxcore.ModuleName, info.Name())
assert.Equal(
t,
map[string]interface{}{
"app": map[string]interface{}{
"name": "core-app",
"description": "core app description",
"env": "test",
"debug": true,
"version": "0.1.0",
},
"log": map[string]interface{}{
"level": "debug",
"output": "test",
},
"trace": map[string]interface{}{
"processor": "test",
"sampler": "parent-based-always-on",
},
"extra": map[string]string{
"foo": "baz",
},
},
info.Data(),
)
}
func TestFxModuleInfoRegistry(t *testing.T) {
t.Parallel()
createRegistry := func(tb testing.TB) *fxcore.FxModuleInfoRegistry {
tb.Helper()
cfg, err := config.NewDefaultConfigFactory().Create(
config.WithFilePaths("./testdata/config"),
)
assert.NoError(tb, err)
return fxcore.NewFxModuleInfoRegistry(fxcore.FxModuleInfoRegistryParam{
Infos: []interface{}{
&testModuleInfo{},
fxcore.NewFxCoreModuleInfo(fxcore.FxCoreModuleInfoParam{
Config: cfg,
ExtraInfos: []fxcore.FxExtraInfo{},
}),
"invalid",
},
})
}
t.Run("test type", func(t *testing.T) {
t.Parallel()
registry := createRegistry(t)
assert.IsType(t, &fxcore.FxModuleInfoRegistry{}, registry)
})
t.Run("test all", func(t *testing.T) {
t.Parallel()
registry := createRegistry(t)
assert.Len(t, registry.All(), 2)
})
t.Run("test names", func(t *testing.T) {
t.Parallel()
registry := createRegistry(t)
assert.Equal(t, []string{fxcore.ModuleName, "test"}, registry.Names())
})
t.Run("test find", func(t *testing.T) {
t.Parallel()
registry := createRegistry(t)
testInfo, err := registry.Find("test")
assert.NoError(t, err)
assert.Equal(t, "test", testInfo.Name())
coreInfo, err := registry.Find(fxcore.ModuleName)
assert.NoError(t, err)
assert.Equal(t, fxcore.ModuleName, coreInfo.Name())
invalidInfo, err := registry.Find("invalid")
assert.Error(t, err)
assert.Equal(t, "fx module info with name invalid was not found", err.Error())
assert.Nil(t, invalidInfo)
})
}