Skip to content

Commit 3befae9

Browse files
committed
image policy tests: include test cleanup within the It block
Using g.Cleanup means the cleanup steps aren't included as part of the monitor testing event interval. This causes MCP rollouts to trigger events out of the window of forgiveness, causing test failures Signed-off-by: Peter Hunt <[email protected]>
1 parent 7da3e1c commit 3befae9

1 file changed

Lines changed: 40 additions & 9 deletions

File tree

test/extended/imagepolicy/imagepolicy.go

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ var _ = g.Describe("[sig-imagepolicy][OCPFeatureGate:SigstoreImageVerification][
8484

8585
g.It("Should fail clusterimagepolicy signature validation root of trust does not match the identity in the signature", func() {
8686
createClusterImagePolicy(oc, testClusterImagePolicies[invalidPublicKeyClusterImagePolicyName])
87-
g.DeferCleanup(deleteClusterImagePolicy, oc, invalidPublicKeyClusterImagePolicyName)
87+
88+
// Cleanup inline instead of DeferCleanup so it's included in test interval timing
89+
defer func() {
90+
o.Expect(deleteClusterImagePolicy(oc, invalidPublicKeyClusterImagePolicyName)).NotTo(o.HaveOccurred())
91+
}()
8892

8993
pod, err := launchTestPod(tctx, clif, testPodName, testSignedPolicyScope)
9094
o.Expect(err).NotTo(o.HaveOccurred())
@@ -98,10 +102,18 @@ var _ = g.Describe("[sig-imagepolicy][OCPFeatureGate:SigstoreImageVerification][
98102
// Ensure allowedRegistries do not skip signature verification by adding testSignedPolicyScope to the list.
99103
allowedRegistries := []string{"quay.io", "registry.redhat.io", "image-registry.openshift-image-registry.svc:5000", testSignedPolicyScope}
100104
updateImageConfig(oc, allowedRegistries)
101-
g.DeferCleanup(cleanupImageConfig, oc)
105+
106+
// Cleanup inline instead of DeferCleanup so it's included in test interval timing
107+
defer func() {
108+
o.Expect(cleanupImageConfig(oc)).NotTo(o.HaveOccurred())
109+
}()
102110

103111
createClusterImagePolicy(oc, testClusterImagePolicies[invalidPublicKeyClusterImagePolicyName])
104-
g.DeferCleanup(deleteClusterImagePolicy, oc, invalidPublicKeyClusterImagePolicyName)
112+
113+
// Cleanup inline instead of DeferCleanup so it's included in test interval timing
114+
defer func() {
115+
o.Expect(deleteClusterImagePolicy(oc, invalidPublicKeyClusterImagePolicyName)).NotTo(o.HaveOccurred())
116+
}()
105117

106118
pod, err := launchTestPod(tctx, clif, testPodName, testSignedPolicyScope)
107119
o.Expect(err).NotTo(o.HaveOccurred())
@@ -113,7 +125,11 @@ var _ = g.Describe("[sig-imagepolicy][OCPFeatureGate:SigstoreImageVerification][
113125

114126
g.It("Should pass clusterimagepolicy signature validation with signed image", func() {
115127
createClusterImagePolicy(oc, testClusterImagePolicies[publiKeyRekorClusterImagePolicyName])
116-
g.DeferCleanup(deleteClusterImagePolicy, oc, publiKeyRekorClusterImagePolicyName)
128+
129+
// Cleanup inline instead of DeferCleanup so it's included in test interval timing
130+
defer func() {
131+
o.Expect(deleteClusterImagePolicy(oc, publiKeyRekorClusterImagePolicyName)).NotTo(o.HaveOccurred())
132+
}()
117133

118134
pod, err := launchTestPod(tctx, clif, testPodName, testSignedPolicyScope)
119135
o.Expect(err).NotTo(o.HaveOccurred())
@@ -125,7 +141,11 @@ var _ = g.Describe("[sig-imagepolicy][OCPFeatureGate:SigstoreImageVerification][
125141

126142
g.It("Should fail imagepolicy signature validation in different namespaces root of trust does not match the identity in the signature", func() {
127143
createImagePolicy(oc, testImagePolicies[invalidPublicKeyImagePolicyName], imgpolicyClif.Namespace.Name)
128-
g.DeferCleanup(deleteImagePolicy, oc, invalidPublicKeyImagePolicyName, imgpolicyClif.Namespace.Name)
144+
145+
// Cleanup inline instead of DeferCleanup so it's included in test interval timing
146+
defer func() {
147+
o.Expect(deleteImagePolicy(oc, invalidPublicKeyImagePolicyName, imgpolicyClif.Namespace.Name)).NotTo(o.HaveOccurred())
148+
}()
129149

130150
pod, err := launchTestPod(tctx, imgpolicyClif, testPodName, testSignedPolicyScope)
131151
o.Expect(err).NotTo(o.HaveOccurred())
@@ -137,9 +157,12 @@ var _ = g.Describe("[sig-imagepolicy][OCPFeatureGate:SigstoreImageVerification][
137157
})
138158

139159
g.It("Should pass imagepolicy signature validation with signed image in namespaces", func() {
140-
141160
createImagePolicy(oc, testImagePolicies[publiKeyRekorImagePolicyName], imgpolicyClif.Namespace.Name)
142-
g.DeferCleanup(deleteImagePolicy, oc, publiKeyRekorImagePolicyName, imgpolicyClif.Namespace.Name)
161+
162+
// Cleanup inline instead of DeferCleanup so it's included in test interval timing
163+
defer func() {
164+
o.Expect(deleteImagePolicy(oc, publiKeyRekorImagePolicyName, imgpolicyClif.Namespace.Name)).NotTo(o.HaveOccurred())
165+
}()
143166

144167
pod, err := launchTestPod(tctx, imgpolicyClif, testPodName, testSignedPolicyScope)
145168
o.Expect(err).NotTo(o.HaveOccurred())
@@ -172,7 +195,11 @@ var _ = g.Describe("[sig-imagepolicy][OCPFeatureGate:SigstoreImageVerificationPK
172195
g.DescribeTable("clusterimagepolicy signature validation tests",
173196
func(policyName string, expectPass bool, imageSpec string, verifyFunc func(tctx context.Context, clif *e2e.Framework, expectPass bool, testPodName string, imageSpec string) error) {
174197
createClusterImagePolicy(oc, testClusterImagePolicies[policyName])
175-
g.DeferCleanup(deleteClusterImagePolicy, oc, policyName)
198+
199+
// Cleanup inline instead of DeferCleanup so it's included in test interval timing
200+
defer func() {
201+
o.Expect(deleteClusterImagePolicy(oc, policyName)).NotTo(o.HaveOccurred())
202+
}()
176203

177204
err := verifyFunc(tctx, clif, expectPass, testPodName, imageSpec)
178205
o.Expect(err).NotTo(o.HaveOccurred())
@@ -185,7 +212,11 @@ var _ = g.Describe("[sig-imagepolicy][OCPFeatureGate:SigstoreImageVerificationPK
185212
g.DescribeTable("imagepolicy signature validation tests",
186213
func(policyName string, expectPass bool, imageSpec string, verifyFunc func(tctx context.Context, clif *e2e.Framework, expectPass bool, testPodName string, imageSpec string) error) {
187214
createImagePolicy(oc, testImagePolicies[policyName], imgpolicyClif.Namespace.Name)
188-
g.DeferCleanup(deleteImagePolicy, oc, policyName, imgpolicyClif.Namespace.Name)
215+
216+
// Cleanup inline instead of DeferCleanup so it's included in test interval timing
217+
defer func() {
218+
o.Expect(deleteImagePolicy(oc, policyName, imgpolicyClif.Namespace.Name)).NotTo(o.HaveOccurred())
219+
}()
189220

190221
err := verifyFunc(tctx, imgpolicyClif, expectPass, testPodName, imageSpec)
191222
o.Expect(err).NotTo(o.HaveOccurred())

0 commit comments

Comments
 (0)