-
Notifications
You must be signed in to change notification settings - Fork 8
install watch reaction function to fake client #550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,9 @@ type ExpectConfig struct { | |
| // WithReactors installs each ReactionFunc into each fake clientset. ReactionFuncs intercept | ||
| // each call to the clientset providing the ability to mutate the resource or inject an error. | ||
| WithReactors []ReactionFunc | ||
| // WithWatchReactors installs WatchReactionFunc into the fake clientset. This provides ability | ||
| // to simulate events in the watcher. | ||
| WithWatchReactors []WatchReactionFunc | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May also need to define WithWatchReactors for (Sub)ReconcilerTestCase/AdmissionWebhookTestCase and pass it through when creating the ExpectConfig. Then again, I'm not sure watch makes sense in those particular contexts since reconcilers and webhooks are intended to execute at a moment in time while watches are long lived observations of change. What do you think? |
||
| // GivenTracks provide a set of tracked resources to seed the tracker with | ||
| GivenTracks []TrackRequest | ||
|
|
||
|
|
@@ -119,6 +122,11 @@ func (c *ExpectConfig) init() { | |
| reactor := c.WithReactors[len(c.WithReactors)-1-i] | ||
| c.client.PrependReactor("*", "*", reactor) | ||
| } | ||
| for i := range c.WithWatchReactors { | ||
| // in reverse order since we prepend | ||
| watchReactor := c.WithWatchReactors[len(c.WithWatchReactors)-1-i] | ||
| c.client.PrependWatchReactor("*", watchReactor) | ||
| } | ||
| c.apiReader = c.createClient(apiGivenObjects, c.StatusSubResourceTypes) | ||
| c.recorder = &eventRecorder{ | ||
| events: []Event{}, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,9 +48,10 @@ type ReconcilerTestCase struct { | |
|
|
||
| // Request identifies the object to be reconciled | ||
| Request reconcilers.Request | ||
| // WithReactors installs each ReactionFunc into each fake clientset. ReactionFuncs intercept | ||
| // WithReactors and WithWatchReactors installs each ReactionFunc into each fake clientset. ReactionFuncs intercept | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. document each field separately, otherwise the info won't show up in tooling for WithWatchReactors. x3 |
||
| // each call to the clientset providing the ability to mutate the resource or inject an error. | ||
| WithReactors []ReactionFunc | ||
| WithReactors []ReactionFunc | ||
| WithWatchReactors []WatchReactionFunc | ||
| // WithClientBuilder allows a test to modify the fake client initialization. | ||
| WithClientBuilder func(*fake.ClientBuilder) *fake.ClientBuilder | ||
| // StatusSubResourceTypes is a set of object types that support the status sub-resource. For | ||
|
|
@@ -188,6 +189,7 @@ func (tc *ReconcilerTestCase) Run(t *testing.T, scheme *runtime.Scheme, factory | |
| APIGivenObjects: tc.APIGivenObjects, | ||
| WithClientBuilder: tc.WithClientBuilder, | ||
| WithReactors: tc.WithReactors, | ||
| WithWatchReactors: tc.WithWatchReactors, | ||
| GivenTracks: tc.GivenTracks, | ||
| ExpectTracks: tc.ExpectTracks, | ||
| ExpectEvents: tc.ExpectEvents, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we trying to react to get/create/delete/update here? I would expect it to only react with watch actions. I'm not familiar enough with the mechanics of watch to know exactly what should be here.