(t *testing.T)
| 76 | } |
| 77 | |
| 78 | func TestFactory_Watch(t *testing.T) { |
| 79 | t.Parallel() |
| 80 | |
| 81 | mockConf := "foo" |
| 82 | ctx, cancel := context.WithCancel(context.Background()) |
| 83 | defer cancel() |
| 84 | f := NewFactory(func(_ string) (Pair, error) { |
| 85 | return Pair{ |
| 86 | Conn: mockConf, |
| 87 | Closer: func() {}, |
| 88 | }, nil |
| 89 | }) |
| 90 | dispatcher := events.SyncDispatcher{} |
| 91 | go func() { |
| 92 | f.SubscribeReloadEventFrom(&dispatcher) |
| 93 | }() |
| 94 | |
| 95 | foo, err := f.Make("default") |
| 96 | assert.NoError(t, err) |
| 97 | assert.Equal(t, "foo", foo.(string)) |
| 98 | |
| 99 | mockConf = "bar" |
| 100 | |
| 101 | foo, err = f.Make("default") |
| 102 | assert.NoError(t, err) |
| 103 | assert.Equal(t, "foo", foo.(string)) |
| 104 | |
| 105 | time.Sleep(3 * time.Second) |
| 106 | _ = dispatcher.Dispatch(ctx, events.OnReload, events.OnReloadPayload{}) |
| 107 | |
| 108 | time.Sleep(3 * time.Second) |
| 109 | foo, err = f.Make("default") |
| 110 | assert.NoError(t, err) |
| 111 | assert.Equal(t, "bar", foo.(string)) |
| 112 | } |
| 113 | |
| 114 | func TestFactory_SubscribeReloadEventFrom(t *testing.T) { |
| 115 | t.Parallel() |
nothing calls this directly
no test coverage detected