Skip to content

Commit cd2cb9c

Browse files
committed
Run AfterEach only if needed
The `backup` would not be assigned when the test is skipped earlier in `BeforeEach`. However, `AfterEach` still runs in that case. As a result `CV/version` could be updated with unexpected value. This pull fix the issue by introducing a guard `needRecover` on `AfterEach` which becomes `true` only after `CV` was updated earlier, i.e., it was not skipped.
1 parent a8a55ff commit cd2cb9c

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

test/cvo/accept_risks.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator`,
2626
configClient *configv1client.ConfigV1Client
2727
err error
2828

29-
ctx = context.TODO()
30-
backup configv1.ClusterVersionSpec
29+
ctx = context.TODO()
30+
needRecover bool
31+
backup configv1.ClusterVersionSpec
3132
)
3233

3334
g.BeforeEach(func() {
@@ -50,11 +51,13 @@ var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator`,
5051
})
5152

5253
g.AfterEach(func() {
53-
cv, err := configClient.ClusterVersions().Get(ctx, external.DefaultClusterVersionName, metav1.GetOptions{})
54-
o.Expect(err).NotTo(o.HaveOccurred())
55-
cv.Spec = backup
56-
_, err = configClient.ClusterVersions().Update(ctx, cv, metav1.UpdateOptions{})
57-
o.Expect(err).NotTo(o.HaveOccurred())
54+
if needRecover {
55+
cv, err := configClient.ClusterVersions().Get(ctx, external.DefaultClusterVersionName, metav1.GetOptions{})
56+
o.Expect(err).NotTo(o.HaveOccurred())
57+
cv.Spec = backup
58+
_, err = configClient.ClusterVersions().Update(ctx, cv, metav1.UpdateOptions{})
59+
o.Expect(err).NotTo(o.HaveOccurred())
60+
}
5861
})
5962

6063
g.It("should work with accept risks", g.Label("Serial"), func() {
@@ -67,6 +70,7 @@ var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator`,
6770

6871
_, err = configClient.ClusterVersions().Update(ctx, cv, metav1.UpdateOptions{})
6972
o.Expect(err).NotTo(o.HaveOccurred())
73+
needRecover = true
7074

7175
g.By("Checking that conditional updates shows up in status")
7276
// waiting for the conditional updates to show up

0 commit comments

Comments
 (0)