1
1
package graph
2
2
3
3
import (
4
- "errors"
5
4
"testing"
6
5
7
6
. "github.com/onsi/gomega"
8
7
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9
8
"k8s.io/apimachinery/pkg/types"
9
+ "k8s.io/apimachinery/pkg/util/validation/field"
10
10
"sigs.k8s.io/controller-runtime/pkg/client"
11
11
v1 "sigs.k8s.io/gateway-api/apis/v1"
12
12
@@ -16,8 +16,6 @@ import (
16
16
"github.com/nginxinc/nginx-gateway-fabric/internal/framework/helpers"
17
17
"github.com/nginxinc/nginx-gateway-fabric/internal/framework/kinds"
18
18
staticConds "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/conditions"
19
- "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/validation"
20
- "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/validation/validationfakes"
21
19
)
22
20
23
21
func TestProcessGatewayClasses (t * testing.T ) {
@@ -166,24 +164,7 @@ func TestBuildGatewayClass(t *testing.T) {
166
164
},
167
165
}
168
166
169
- createValidNPValidator := func () * validationfakes.FakeGenericValidator {
170
- v := & validationfakes.FakeGenericValidator {}
171
- v .ValidateServiceNameReturns (nil )
172
- v .ValidateEndpointReturns (nil )
173
-
174
- return v
175
- }
176
-
177
- createInvalidNPValidator := func () * validationfakes.FakeGenericValidator {
178
- v := & validationfakes.FakeGenericValidator {}
179
- v .ValidateServiceNameReturns (errors .New ("error" ))
180
- v .ValidateEndpointReturns (errors .New ("error" ))
181
-
182
- return v
183
- }
184
-
185
167
tests := []struct {
186
- validator validation.GenericValidator
187
168
gc * v1.GatewayClass
188
169
np * NginxProxy
189
170
crdMetadata map [types.NamespacedName ]* metav1.PartialObjectMetadata
@@ -220,7 +201,6 @@ func TestBuildGatewayClass(t *testing.T) {
220
201
},
221
202
Valid : true ,
222
203
},
223
- validator : createValidNPValidator (),
224
204
expected : & GatewayClass {
225
205
Source : gcWithParams ,
226
206
Valid : true ,
@@ -267,22 +247,20 @@ func TestBuildGatewayClass(t *testing.T) {
267
247
{
268
248
gc : gcWithParams ,
269
249
np : & NginxProxy {
270
- Source : & ngfAPI. NginxProxy {
271
- TypeMeta : metav1. TypeMeta {
272
- Kind : kinds . NginxProxy ,
273
- } ,
274
- Spec : ngfAPI. NginxProxySpec {
275
- Telemetry : & ngfAPI. Telemetry {
276
- ServiceName : helpers . GetPointer ( "my-svc" ),
277
- Exporter : & ngfAPI. TelemetryExporter {
278
- Endpoint : "my- endpoint" ,
279
- } ,
280
- } ,
281
- } ,
250
+ Valid : false ,
251
+ ErrMsgs : field. ErrorList {
252
+ field . Invalid (
253
+ field . NewPath ( "spec" , "telemetry" , "serviceName" ) ,
254
+ "my-svc" ,
255
+ "error" ,
256
+ ),
257
+ field . Invalid (
258
+ field . NewPath ( "spec" , "telemetry" , "exporter" , " endpoint") ,
259
+ "my-endpoint" ,
260
+ "error" ,
261
+ ) ,
282
262
},
283
- Valid : true ,
284
263
},
285
- validator : createInvalidNPValidator (),
286
264
expected : & GatewayClass {
287
265
Source : gcWithParams ,
288
266
Valid : true ,
@@ -312,7 +290,7 @@ func TestBuildGatewayClass(t *testing.T) {
312
290
t .Run (test .name , func (t * testing.T ) {
313
291
g := NewWithT (t )
314
292
315
- result := buildGatewayClass (test .gc , test .np , test .crdMetadata , test . validator )
293
+ result := buildGatewayClass (test .gc , test .np , test .crdMetadata )
316
294
g .Expect (helpers .Diff (test .expected , result )).To (BeEmpty ())
317
295
if test .np != nil {
318
296
g .Expect (test .np .Valid ).ToNot (Equal (test .expNPInvalid ))
0 commit comments