cybozu-go / accurate

Kubernetes controller for multi-tenancy. It propagates resources between namespaces accurately and allows tenant users to create/delete sub-namespaces.
https://cybozu-go.github.io/accurate/
Apache License 2.0
34 stars 5 forks source link

test: improve namespace webhook tests #123

Closed erikgb closed 4 months ago

erikgb commented 4 months ago

While working on https://github.com/cybozu-go/accurate/pull/121 I noticed some flaky tests I have seen before in previous pull requests. Flakes are annoying, so this PR attempts to improve this somehow.

Since the webhook uses a caching client, the webhook might deny the request based on a non-updated cache. If the test creates a namespace referring to another namespace just created, this can make the test fail. Hopefully, this PR will improve the situation by replacing Except with Eventually in such cases.

I have also added assertions of error messages expected from the webhook for denied requests. This should prevent tests from passing if the request fails for any other reason than the expected. This will force us to update the test if error messages are changed, but I think this makes sense.