(t *testing.T)
| 227 | } |
| 228 | |
| 229 | func TestWatchKeyWithNoStartValue(t *testing.T) { |
| 230 | c, closer := NewInMemoryClient(codec.String{}, testLogger{}, prometheus.NewPedanticRegistry()) |
| 231 | t.Cleanup(func() { |
| 232 | assert.NoError(t, closer.Close()) |
| 233 | }) |
| 234 | |
| 235 | const key = "test" |
| 236 | |
| 237 | go func() { |
| 238 | time.Sleep(100 * time.Millisecond) |
| 239 | _, err := c.kv.Put(&consul.KVPair{Key: key, Value: []byte("start")}, nil) |
| 240 | require.NoError(t, err) |
| 241 | |
| 242 | time.Sleep(100 * time.Millisecond) |
| 243 | _, err = c.kv.Put(&consul.KVPair{Key: key, Value: []byte("end")}, nil) |
| 244 | require.NoError(t, err) |
| 245 | }() |
| 246 | |
| 247 | ctx, fn := context.WithTimeout(context.Background(), 300*time.Millisecond) |
| 248 | defer fn() |
| 249 | |
| 250 | reported := 0 |
| 251 | c.WatchKey(ctx, key, func(i any) bool { |
| 252 | reported++ |
| 253 | return reported != 2 |
| 254 | }) |
| 255 | |
| 256 | // we should see both start and end values. |
| 257 | require.Equal(t, 2, reported) |
| 258 | } |
| 259 | |
| 260 | type testLogger struct { |
| 261 | } |
nothing calls this directly
no test coverage detected