Skip to content

Commit dc32e46

Browse files
authored
Merge pull request #1175 from pivotal-k8s/doc-garbage-collection
Document lack of controller manager in integration tests
2 parents 49c143d + cdc066f commit dc32e46

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

docs/book/src/reference/testing/envtest.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,19 @@ testEnv = &envtest.Environment{
5555
KubeAPIServerFlags: apiServerFlags,
5656
}
5757
```
58+
59+
### Testing considerations
60+
61+
Unless you're using an existing cluster, keep in mind that no built-in controllers are running in the test context. In some ways, the test control plane will behave differently from "real" clusters, and that might have an impact on how you write tests. One common example is garbage collection; because there are no controllers monitoring built-in resources, objects do not get deleted, even if an `OwnerReference` is set up.
62+
63+
To test that the deletion lifecycle works, test the ownership instead of asserting on existence. For example:
64+
65+
```go
66+
expectedOwnerReference := v1.OwnerReference{
67+
Kind: "MyCoolCustomResource",
68+
APIVersion: "my.api.example.com/v1beta1",
69+
UID: "d9607e19-f88f-11e6-a518-42010a800195",
70+
Name: "userSpecifiedResourceName",
71+
}
72+
Expect(deployment.ObjectMeta.OwnerReferences).To(ContainElement(expectedOwnerReference))
73+
```

0 commit comments

Comments
 (0)