MCPcopy Create free account
hub / github.com/DoNewsCode/core / TestModule_Watch

Function TestModule_Watch

config/module_test.go:170–211  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

168}
169
170func TestModule_Watch(t *testing.T) {
171 t.Run("test without module", func(t *testing.T) {
172 ctx, cancel := context.WithCancel(context.Background())
173 defer cancel()
174
175 dispatcher := &events.SyncDispatcher{}
176 dispatcher.Subscribe(events.Listen(events.OnReload, func(ctx context.Context, event interface{}) error {
177 data := event.(events.OnReloadPayload).NewConf.(*KoanfAdapter)
178 assert.Equal(t, "bar", data.String("foo"))
179 cancel()
180 return nil
181 }))
182 conf, _ := NewConfig(WithDispatcher(dispatcher), WithProviderLayer(confmap.Provider(map[string]interface{}{"foo": "bar"}, "."), nil))
183 conf.Watch(ctx)
184 })
185
186 t.Run("test with module", func(t *testing.T) {
187 ctx, cancel := context.WithCancel(context.Background())
188 defer cancel()
189
190 dispatcher := &events.SyncDispatcher{}
191 dispatcher.Subscribe(events.Listen(events.OnReload, func(ctx context.Context, event interface{}) error {
192 data := event.(events.OnReloadPayload).NewConf.(*KoanfAdapter)
193 assert.Equal(t, "bar", data.String("foo"))
194 cancel()
195 return nil
196 }))
197
198 conf, _ := NewConfig(WithProviderLayer(confmap.Provider(map[string]interface{}{"foo": "bar"}, "."), nil), WithWatcher(&MockWatcher{}))
199 module, _ := New(ConfigIn{
200 Conf: conf,
201 Dispatcher: dispatcher,
202 })
203 var g run.Group
204 g.Add(func() error {
205 <-ctx.Done()
206 return nil
207 }, func(err error) {})
208 module.ProvideRunGroup(&g)
209 g.Run()
210 })
211}
212
213type MockWatcher struct{}
214

Callers

nothing calls this directly

Calls 13

SubscribeMethod · 0.95
ListenFunction · 0.92
NewConfigFunction · 0.85
WithDispatcherFunction · 0.85
WithProviderLayerFunction · 0.85
WithWatcherFunction · 0.85
DoneMethod · 0.80
NewFunction · 0.70
StringMethod · 0.65
WatchMethod · 0.65
ProvideRunGroupMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected