@@ -6,13 +6,17 @@ import (
6
6
7
7
. "github.com/onsi/gomega"
8
8
controllerruntime "sigs.k8s.io/controller-runtime"
9
+ "sigs.k8s.io/controller-runtime/pkg/client"
9
10
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
10
11
11
12
ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha1"
12
13
)
13
14
14
15
func TestClientSettingsPoliciesTargetRefKind (t * testing.T ) {
15
16
t .Parallel ()
17
+ g := NewWithT (t )
18
+ k8sClient , err := getKubernetesClient (t )
19
+ g .Expect (err ).ToNot (HaveOccurred ())
16
20
tests := []struct {
17
21
policySpec ngfAPIv1alpha1.ClientSettingsPolicySpec
18
22
name string
@@ -70,13 +74,16 @@ func TestClientSettingsPoliciesTargetRefKind(t *testing.T) {
70
74
for _ , tt := range tests {
71
75
t .Run (tt .name , func (t * testing.T ) {
72
76
t .Parallel ()
73
- validateClientSettingsPolicy (t , tt )
77
+ validateClientSettingsPolicy (t , tt , g , k8sClient )
74
78
})
75
79
}
76
80
}
77
81
78
82
func TestClientSettingsPoliciesTargetRefGroup (t * testing.T ) {
79
83
t .Parallel ()
84
+ g := NewWithT (t )
85
+ k8sClient , err := getKubernetesClient (t )
86
+ g .Expect (err ).ToNot (HaveOccurred ())
80
87
tests := []struct {
81
88
policySpec ngfAPIv1alpha1.ClientSettingsPolicySpec
82
89
name string
@@ -116,7 +123,7 @@ func TestClientSettingsPoliciesTargetRefGroup(t *testing.T) {
116
123
for _ , tt := range tests {
117
124
t .Run (tt .name , func (t * testing.T ) {
118
125
t .Parallel ()
119
- validateClientSettingsPolicy (t , tt )
126
+ validateClientSettingsPolicy (t , tt , g , k8sClient )
120
127
})
121
128
}
122
129
}
@@ -125,10 +132,9 @@ func validateClientSettingsPolicy(t *testing.T, tt struct {
125
132
policySpec ngfAPIv1alpha1.ClientSettingsPolicySpec
126
133
name string
127
134
wantErrors []string
128
- },
135
+ }, g * WithT , k8sClient client. Client ,
129
136
) {
130
137
t .Helper ()
131
- g := NewWithT (t )
132
138
133
139
policySpec := tt .policySpec
134
140
policySpec .TargetRef .Name = gatewayv1alpha2 .ObjectName (uniqueResourceName (testTargetRefName ))
@@ -142,11 +148,7 @@ func validateClientSettingsPolicy(t *testing.T, tt struct {
142
148
Spec : policySpec ,
143
149
}
144
150
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 )
150
152
151
153
// Clean up after test
152
154
defer func () {
0 commit comments