From 14aa8597c79e973a3e3e5e1dc27a1246c091ab13 Mon Sep 17 00:00:00 2001 From: Bo-Cheng Chu Date: Thu, 28 Aug 2025 11:28:52 -0700 Subject: [PATCH] replace context.Background() with t.Context() --- api/v1beta1/gcpcluster_webhook_test.go | 3 +-- api/v1beta1/gcpclustertemplate_webhook_test.go | 3 +-- api/v1beta1/gcpmachine_webhook_test.go | 3 +-- api/v1beta1/gcpmachinetemplate_webhook_test.go | 3 +-- exp/api/v1beta1/gcpmanagedcluster_webhook_test.go | 3 +-- exp/api/v1beta1/gcpmanagedcontrolplane_webhook_test.go | 7 +++---- exp/api/v1beta1/gcpmanagedmachinepool_webhook_test.go | 5 ++--- 7 files changed, 10 insertions(+), 17 deletions(-) diff --git a/api/v1beta1/gcpcluster_webhook_test.go b/api/v1beta1/gcpcluster_webhook_test.go index 55f66fb25..32f1fde83 100644 --- a/api/v1beta1/gcpcluster_webhook_test.go +++ b/api/v1beta1/gcpcluster_webhook_test.go @@ -17,7 +17,6 @@ limitations under the License. package v1beta1 import ( - "context" "testing" . "github.com/onsi/gomega" @@ -90,7 +89,7 @@ func TestGCPCluster_ValidateUpdate(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { t.Parallel() - warn, err := (&gcpClusterWebhook{}).ValidateUpdate(context.Background(), test.oldCluster, test.newCluster) + warn, err := (&gcpClusterWebhook{}).ValidateUpdate(t.Context(), test.oldCluster, test.newCluster) if test.wantErr { g.Expect(err).To(HaveOccurred()) } else { diff --git a/api/v1beta1/gcpclustertemplate_webhook_test.go b/api/v1beta1/gcpclustertemplate_webhook_test.go index a278dc461..c621bf383 100644 --- a/api/v1beta1/gcpclustertemplate_webhook_test.go +++ b/api/v1beta1/gcpclustertemplate_webhook_test.go @@ -17,7 +17,6 @@ limitations under the License. package v1beta1 import ( - "context" "testing" . "github.com/onsi/gomega" @@ -84,7 +83,7 @@ func TestGCPClusterTemplate_ValidateUpdate(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { t.Parallel() - warn, err := (&gcpClusterTemplateWebhook{}).ValidateUpdate(context.Background(), test.oldTemplate, test.newTemplate) + warn, err := (&gcpClusterTemplateWebhook{}).ValidateUpdate(t.Context(), test.oldTemplate, test.newTemplate) if test.wantErr { g.Expect(err).To(HaveOccurred()) } else { diff --git a/api/v1beta1/gcpmachine_webhook_test.go b/api/v1beta1/gcpmachine_webhook_test.go index ee706c137..fe8ac13fe 100644 --- a/api/v1beta1/gcpmachine_webhook_test.go +++ b/api/v1beta1/gcpmachine_webhook_test.go @@ -17,7 +17,6 @@ limitations under the License. package v1beta1 import ( - "context" "testing" . "github.com/onsi/gomega" @@ -273,7 +272,7 @@ func TestGCPMachine_ValidateCreate(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { t.Parallel() - warn, err := (&gcpMachineWebhook{}).ValidateCreate(context.Background(), test.GCPMachine) + warn, err := (&gcpMachineWebhook{}).ValidateCreate(t.Context(), test.GCPMachine) if test.wantErr { g.Expect(err).To(HaveOccurred()) } else { diff --git a/api/v1beta1/gcpmachinetemplate_webhook_test.go b/api/v1beta1/gcpmachinetemplate_webhook_test.go index 6891ccb9a..2a20e5718 100644 --- a/api/v1beta1/gcpmachinetemplate_webhook_test.go +++ b/api/v1beta1/gcpmachinetemplate_webhook_test.go @@ -17,7 +17,6 @@ limitations under the License. package v1beta1 import ( - "context" "testing" . "github.com/onsi/gomega" @@ -233,7 +232,7 @@ func TestGCPMachineTemplate_ValidateCreate(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { t.Parallel() - warn, err := (&gcpMachineTemplateWebhook{}).ValidateCreate(context.Background(), test.template) + warn, err := (&gcpMachineTemplateWebhook{}).ValidateCreate(t.Context(), test.template) if test.wantErr { g.Expect(err).To(HaveOccurred()) } else { diff --git a/exp/api/v1beta1/gcpmanagedcluster_webhook_test.go b/exp/api/v1beta1/gcpmanagedcluster_webhook_test.go index 2b2ad8fe5..df00bb8fd 100644 --- a/exp/api/v1beta1/gcpmanagedcluster_webhook_test.go +++ b/exp/api/v1beta1/gcpmanagedcluster_webhook_test.go @@ -17,7 +17,6 @@ limitations under the License. package v1beta1 import ( - "context" "testing" . "github.com/onsi/gomega" @@ -101,7 +100,7 @@ func TestGCPManagedClusterValidatingWebhookUpdate(t *testing.T) { }, } - warn, err := (&gcpManagedClusterWebhook{}).ValidateUpdate(context.Background(), oldMC, newMC) + warn, err := (&gcpManagedClusterWebhook{}).ValidateUpdate(t.Context(), oldMC, newMC) if tc.expectError { g.Expect(err).To(HaveOccurred()) diff --git a/exp/api/v1beta1/gcpmanagedcontrolplane_webhook_test.go b/exp/api/v1beta1/gcpmanagedcontrolplane_webhook_test.go index d712f08c4..a58b57677 100644 --- a/exp/api/v1beta1/gcpmanagedcontrolplane_webhook_test.go +++ b/exp/api/v1beta1/gcpmanagedcontrolplane_webhook_test.go @@ -17,7 +17,6 @@ limitations under the License. package v1beta1 import ( - "context" "strings" "testing" @@ -110,7 +109,7 @@ func TestGCPManagedControlPlaneDefaultingWebhook(t *testing.T) { }, Spec: tc.spec, } - err := (&gcpManagedControlPlaneWebhook{}).Default(context.Background(), mcp) + err := (&gcpManagedControlPlaneWebhook{}).Default(t.Context(), mcp) g.Expect(err).NotTo(HaveOccurred()) g.Expect(mcp.Spec).ToNot(BeNil()) @@ -193,7 +192,7 @@ func TestGCPManagedControlPlaneValidatingWebhookCreate(t *testing.T) { mcp := &GCPManagedControlPlane{ Spec: tc.spec, } - warn, err := (&gcpManagedControlPlaneWebhook{}).ValidateCreate(context.Background(), mcp) + warn, err := (&gcpManagedControlPlaneWebhook{}).ValidateCreate(t.Context(), mcp) if tc.expectError { g.Expect(err).To(HaveOccurred()) @@ -288,7 +287,7 @@ func TestGCPManagedControlPlaneValidatingWebhookUpdate(t *testing.T) { }, } - warn, err := (&gcpManagedControlPlaneWebhook{}).ValidateUpdate(context.Background(), oldMCP, newMCP) + warn, err := (&gcpManagedControlPlaneWebhook{}).ValidateUpdate(t.Context(), oldMCP, newMCP) if tc.expectError { g.Expect(err).To(HaveOccurred()) diff --git a/exp/api/v1beta1/gcpmanagedmachinepool_webhook_test.go b/exp/api/v1beta1/gcpmanagedmachinepool_webhook_test.go index 1334c5de2..6930d14b1 100644 --- a/exp/api/v1beta1/gcpmanagedmachinepool_webhook_test.go +++ b/exp/api/v1beta1/gcpmanagedmachinepool_webhook_test.go @@ -17,7 +17,6 @@ limitations under the License. package v1beta1 import ( - "context" "strings" "testing" @@ -148,7 +147,7 @@ func TestGCPManagedMachinePoolValidatingWebhookCreate(t *testing.T) { mmp := &GCPManagedMachinePool{ Spec: tc.spec, } - warn, err := (&gcpManagedMachinePoolWebhook{}).ValidateCreate(context.Background(), mmp) + warn, err := (&gcpManagedMachinePoolWebhook{}).ValidateCreate(t.Context(), mmp) if tc.expectError { g.Expect(err).To(HaveOccurred()) @@ -215,7 +214,7 @@ func TestGCPManagedMachinePoolValidatingWebhookUpdate(t *testing.T) { }, } - warn, err := (&gcpManagedMachinePoolWebhook{}).ValidateUpdate(context.Background(), oldMMP, newMMP) + warn, err := (&gcpManagedMachinePoolWebhook{}).ValidateUpdate(t.Context(), oldMMP, newMMP) if tc.expectError { g.Expect(err).To(HaveOccurred())