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

tests: skip update portions of the test if we don't have an update configured. #2281

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pkg/controller/dynamic/dynamic_controller_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ func testUpdate(ctx context.Context, t *testing.T, testContext testrunner.TestCo
if resourceContext.SkipUpdate || resourceContext.IsAutoGenerated(systemContext.SMLoader) {
return
}
if testContext.UpdateUnstruct == nil {
t.Logf("UpdateUnstruct not set; skipping update")
return
}
kubeClient := systemContext.Manager.GetClient()
initialUnstruct := testContext.CreateUnstruct.DeepCopy()
if err := kubeClient.Get(ctx, testContext.NamespacedName, initialUnstruct); err != nil {
Expand All @@ -367,9 +371,6 @@ func testUpdate(ctx context.Context, t *testing.T, testContext testrunner.TestCo

// Update resource from test data
updateUnstruct := testContext.UpdateUnstruct.DeepCopy()
if updateUnstruct == nil {
t.Fatalf("updateUnstruct is nil for '%v'. should SkipUpdate be set to true in resourcefixture/contexts?", testContext.ResourceFixture.Name)
}
Comment on lines -370 to -372
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like there's a plan to move away from SkipUpdate so disregard if this point will become moot in the future but as I onboarded on the code base, what I liked about this failure is that it gave me a strong signal for how to set up the fixtures tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if there's a plan per-se :-) I think the information in SkipUpdate is redundant - if we have an update.yaml then SkipUpdate must be true. So that's why I don't want to rely on it.

I do think we want tests for coverage e.g. does every kind have a create & update test, is every field in a kind touched in at least one test, are all mutable fields updated in at least one test etc. But I think those should be explicit tests (and they're more like apilinters, in that they are testing our tests, not testing the controllers itself)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need a better way to ensure coverage. This change isn't really part of it.

Regarding testdata, if we do want to enforce the existence of update.yaml, we probably should do it via a unit test but not the integration test.

updateUnstruct.SetResourceVersion(initialUnstruct.GetResourceVersion())
// For resources with server-generated IDs, ensure the relevant fields are in the status
status := initialUnstruct.Object["status"]
Expand Down
Loading