Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Allow testing of watches created in Setup() #306

Open
mamachanko opened this issue Oct 3, 2022 · 1 comment
Open

Allow testing of watches created in Setup() #306

mamachanko opened this issue Oct 3, 2022 · 1 comment

Comments

@mamachanko
Copy link
Collaborator

As a reconciler author,
I want to express expected watches in my tests
So that I know when I forgot to create a watch to enqueue tracked resources

When my reconciler uses c.TrackAndGet to track a resource, its easy to forget to create a watch in my reconciler's Setup. I would like to express the expected watches (or lack thereof) through unit tests.

Eventually, I want this to pass

Setup: func(ctx context.Context, mgr ctrl.Manager, bldr *builder.Builder) error {
	bldr.Watches(&source.Kind{Type: &v1.Secret{}}, reconcilers.EnqueueTracked(ctx, &v1.Secret{}))
	return nil
},

and this to fail:

Setup: func(ctx context.Context, mgr ctrl.Manager, bldr *builder.Builder) error {
	return nil
},

I am not even sure there's a case for c.TrackAndGet without its companion watch, or is there?

@scothis
Copy link
Contributor

scothis commented Oct 3, 2022

I haven't found a good fake for the manager and builder resources that would make them unit testable. e2e testing is the preferred approach to date.

It might be worth dealing with the complexity of creating our own fakes since this is a significant part of the controller that isn't unit testable today.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants