Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
migrate tests to use patches instead of updates to avoid occassional …
Browse files Browse the repository at this point in the history
…update conflict failures
  • Loading branch information
philbrookes committed Sep 28, 2023
1 parent c74fa43 commit 370849b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions test/integration/dnsheathcheckprobe_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ var _ = Describe("DNSHealthCheckProbe controller", func() {
}, probeObj)
Expect(err).NotTo(HaveOccurred())

patch := client.MergeFrom(probeObj.DeepCopy())
lastUpdate := probeObj.Status.LastCheckedAt
probeObj.Spec.Path = "/unhealthy"
err = k8sClient.Update(ctx, probeObj)
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient.Patch(ctx, probeObj, patch)).To(BeNil())

Eventually(func() error {
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(probeObj), probeObj)
Expand Down
10 changes: 5 additions & 5 deletions test/integration/dnspolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,10 @@ var _ = Describe("DNSPolicy", Ordered, func() {
}
}

patch := client.MergeFrom(existingGateway.DeepCopy())
existingGateway.Spec.Listeners = newListeners
rec := &v1alpha1.DNSRecord{}
if err := k8sClient.Update(ctx, existingGateway, &client.UpdateOptions{}); err != nil {
if err := k8sClient.Patch(ctx, existingGateway, patch); err != nil {
return err
}
//dns record should be removed for non wildcard
Expand Down Expand Up @@ -1329,10 +1330,9 @@ var _ = Describe("DNSPolicy", Ordered, func() {
Protocol: gatewayv1beta1.HTTPProtocolType,
}

Eventually(func() error {
gateway.Spec.Listeners = append(gateway.Spec.Listeners, otherListener)
return k8sClient.Update(ctx, gateway)
}).Should(BeNil())
patch = client.MergeFrom(gateway.DeepCopy())
gateway.Spec.Listeners = append(gateway.Spec.Listeners, otherListener)
Expect(k8sClient.Patch(ctx, gateway, patch)).To(BeNil())

probeList := &v1alpha1.DNSHealthCheckProbeList{}
Eventually(func() error {
Expand Down
5 changes: 4 additions & 1 deletion test/util/test_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package testutil

import (
"strings"

certmanv1 "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
cmmeta "github.com/jetstack/cert-manager/pkg/apis/meta/v1"

Expand Down Expand Up @@ -71,8 +73,9 @@ func (t *TestGateway) WithHTTPListener(hostname string) *TestGateway {
func (t *TestGateway) WithHTTPSListener(hostname, tlsSecretName string) *TestGateway {
typedHostname := gatewayv1beta1.Hostname(hostname)
typedNamespace := gatewayv1beta1.Namespace(t.GetNamespace())
typedNamed := gatewayv1beta1.SectionName(strings.Replace(hostname, "*", "wildcard", 1))
t.WithListener(gatewayv1beta1.Listener{
Name: gatewayv1beta1.SectionName(hostname),
Name: typedNamed,
Hostname: &typedHostname,
Port: gatewayv1beta1.PortNumber(443),
Protocol: gatewayv1beta1.HTTPSProtocolType,
Expand Down

0 comments on commit 370849b

Please sign in to comment.