chore: Add VeryShortWatchError typed error

- Add a new VeryShortWatchError struct for error matching, returned
  by `handleAnyWatch`, up through `Reflector.ListAndWatch`.
- Update test expectations to match exact errors.

Kubernetes-commit: 6eff9db0f10db72f2c64390e106a80621d136439
This commit is contained in:
Karl Isenberg
2025-04-15 11:48:57 -07:00
committed by Kubernetes Publisher
parent 1601be3d14
commit 921628ecd6
2 changed files with 16 additions and 5 deletions

View File

@@ -291,8 +291,7 @@ func TestReflectorHandleWatchResultChanClosedBefore(t *testing.T) {
// Simulate the result channel being closed by the producer before handleWatch is called.
close(resultCh)
err := handleWatch(ctx, time.Now(), fw, s, g.expectedType, g.expectedGVK, g.name, g.typeDescription, g.setLastSyncResourceVersion, g.clock, nevererrc)
// TODO(karlkfi): Add exact error type for "very short watch"
require.Error(t, err)
require.Equal(t, &VeryShortWatchError{Name: g.name}, err)
// Ensure handleWatch calls ResultChan and Stop
assert.Equal(t, []string{"ResultChan", "Stop"}, calls)
}
@@ -323,8 +322,7 @@ func TestReflectorHandleWatchResultChanClosedAfter(t *testing.T) {
},
}
err := handleWatch(ctx, time.Now(), fw, s, g.expectedType, g.expectedGVK, g.name, g.typeDescription, g.setLastSyncResourceVersion, g.clock, nevererrc)
// TODO(karlkfi): Add exact error type for "very short watch"
require.Error(t, err)
require.Equal(t, &VeryShortWatchError{Name: g.name}, err)
// Ensure handleWatch calls ResultChan and Stop
assert.Equal(t, []string{"ResultChan", "Stop"}, calls)
}