Skip to content

Commit 81fd868

Browse files
committed
Initialise ginko and k8sClient at the start of each test
1 parent 92caf12 commit 81fd868

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

tests/cel/clientsettingspolicy_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ import (
66

77
. "github.com/onsi/gomega"
88
controllerruntime "sigs.k8s.io/controller-runtime"
9+
"sigs.k8s.io/controller-runtime/pkg/client"
910
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
1011

1112
ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha1"
1213
)
1314

1415
func TestClientSettingsPoliciesTargetRefKind(t *testing.T) {
1516
t.Parallel()
17+
g := NewWithT(t)
18+
k8sClient, err := getKubernetesClient(t)
19+
g.Expect(err).ToNot(HaveOccurred())
1620
tests := []struct {
1721
policySpec ngfAPIv1alpha1.ClientSettingsPolicySpec
1822
name string
@@ -70,13 +74,16 @@ func TestClientSettingsPoliciesTargetRefKind(t *testing.T) {
7074
for _, tt := range tests {
7175
t.Run(tt.name, func(t *testing.T) {
7276
t.Parallel()
73-
validateClientSettingsPolicy(t, tt)
77+
validateClientSettingsPolicy(t, tt, g, k8sClient)
7478
})
7579
}
7680
}
7781

7882
func TestClientSettingsPoliciesTargetRefGroup(t *testing.T) {
7983
t.Parallel()
84+
g := NewWithT(t)
85+
k8sClient, err := getKubernetesClient(t)
86+
g.Expect(err).ToNot(HaveOccurred())
8087
tests := []struct {
8188
policySpec ngfAPIv1alpha1.ClientSettingsPolicySpec
8289
name string
@@ -116,7 +123,7 @@ func TestClientSettingsPoliciesTargetRefGroup(t *testing.T) {
116123
for _, tt := range tests {
117124
t.Run(tt.name, func(t *testing.T) {
118125
t.Parallel()
119-
validateClientSettingsPolicy(t, tt)
126+
validateClientSettingsPolicy(t, tt, g, k8sClient)
120127
})
121128
}
122129
}
@@ -125,10 +132,9 @@ func validateClientSettingsPolicy(t *testing.T, tt struct {
125132
policySpec ngfAPIv1alpha1.ClientSettingsPolicySpec
126133
name string
127134
wantErrors []string
128-
},
135+
}, g *WithT, k8sClient client.Client,
129136
) {
130137
t.Helper()
131-
g := NewWithT(t)
132138

133139
policySpec := tt.policySpec
134140
policySpec.TargetRef.Name = gatewayv1alpha2.ObjectName(uniqueResourceName(testTargetRefName))
@@ -142,11 +148,7 @@ func validateClientSettingsPolicy(t *testing.T, tt struct {
142148
Spec: policySpec,
143149
}
144150

145-
k8sClient, err := getKubernetesClient(t)
146-
147-
g.Expect(err).ToNot(HaveOccurred())
148-
149-
err = k8sClient.Create(context.Background(), clientSettingsPolicy)
151+
err := k8sClient.Create(context.Background(), clientSettingsPolicy)
150152

151153
// Clean up after test
152154
defer func() {

0 commit comments

Comments
 (0)