(t *testing.T)
| 168 | } |
| 169 | |
| 170 | func 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 | |
| 213 | type MockWatcher struct{} |
| 214 |
nothing calls this directly
no test coverage detected