Skip to content
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

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants