grantr / helloworld-crd

Repository for sample controller. Complements sample-apiserver
Apache License 2.0
3 stars 2 forks source link

Add controller tests #15

Closed grantr closed 6 years ago

grantr commented 6 years ago

Test that an event is recorded when a {Foo,Bar} is created or updated. This demonstrates a general strategy for testing controllers using fake clients and real informers.

In my research, I was unable to find an example of tests that assume informers and fake clients will work together. Similar tests in https://github.com/kubernetes-incubator/service-catalog insert objects into the informer store and call controller reconcile methods manually. I believe the difference here is that I'm starting informers for each test, but I'm not sure whether this is a bad idea or not.

I added a broadcaster field to controller structs to allow tests to use broadcast handlers instead of polling for new events.

I removed the filegroup statements in BUILD files to make bazel test pkg/... run correctly (thanks @mattmoor for the fix)