@@ -7,14 +7,14 @@ import (
7
7
"github.com/go-logr/logr/testr"
8
8
. "github.com/onsi/gomega"
9
9
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10
- "k8s.io/apimachinery/pkg/runtime"
11
10
"k8s.io/apimachinery/pkg/runtime/schema"
12
11
"k8s.io/apimachinery/pkg/types"
13
12
v1 "sigs.k8s.io/gateway-api/apis/v1"
14
13
"sigs.k8s.io/gateway-api/apis/v1alpha2"
15
14
16
15
ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha2"
17
16
"github.com/nginx/nginx-gateway-fabric/v2/internal/controller/nginx/config/policies"
17
+ "github.com/nginx/nginx-gateway-fabric/v2/internal/controller/nginx/config/policies/policiesfakes"
18
18
"github.com/nginx/nginx-gateway-fabric/v2/internal/framework/kinds"
19
19
)
20
20
@@ -278,82 +278,40 @@ func TestGetAncestorName(t *testing.T) {
278
278
}
279
279
}
280
280
281
- type mockPolicy struct {
282
- name string
283
- namespace string
284
- kind string
285
- }
286
-
287
- func (m * mockPolicy ) GetName () string { return m .name }
288
- func (m * mockPolicy ) SetName (name string ) { m .name = name }
289
- func (m * mockPolicy ) GetNamespace () string { return m .namespace }
290
- func (m * mockPolicy ) SetNamespace (namespace string ) { m .namespace = namespace }
291
- func (m * mockPolicy ) GetObjectKind () schema.ObjectKind {
292
- if m .kind == "" {
293
- return nil
294
- }
295
- return & mockObjectKind {kind : m .kind }
296
- }
297
- func (m * mockPolicy ) GetTargetRefs () []v1alpha2.LocalPolicyTargetReference { return nil }
298
- func (m * mockPolicy ) GetPolicyStatus () v1alpha2.PolicyStatus { return v1alpha2.PolicyStatus {} }
299
- func (m * mockPolicy ) SetPolicyStatus (_ v1alpha2.PolicyStatus ) {}
300
- func (m * mockPolicy ) DeepCopyObject () runtime.Object { return m }
301
- func (m * mockPolicy ) GetUID () types.UID { return "" }
302
- func (m * mockPolicy ) GetResourceVersion () string { return "" }
303
- func (m * mockPolicy ) SetUID (_ types.UID ) {}
304
- func (m * mockPolicy ) SetResourceVersion (_ string ) {}
305
- func (m * mockPolicy ) GetGeneration () int64 { return 0 }
306
- func (m * mockPolicy ) SetGeneration (_ int64 ) {}
307
- func (m * mockPolicy ) GetCreationTimestamp () metav1.Time { return metav1.Time {} }
308
- func (m * mockPolicy ) SetCreationTimestamp (_ metav1.Time ) {}
309
- func (m * mockPolicy ) GetDeletionTimestamp () * metav1.Time { return nil }
310
- func (m * mockPolicy ) SetDeletionTimestamp (_ * metav1.Time ) {}
311
- func (m * mockPolicy ) GetDeletionGracePeriodSeconds () * int64 { return nil }
312
- func (m * mockPolicy ) SetDeletionGracePeriodSeconds (* int64 ) {}
313
- func (m * mockPolicy ) GetLabels () map [string ]string { return nil }
314
- func (m * mockPolicy ) SetLabels (_ map [string ]string ) {}
315
- func (m * mockPolicy ) GetAnnotations () map [string ]string { return nil }
316
- func (m * mockPolicy ) SetAnnotations (_ map [string ]string ) {}
317
- func (m * mockPolicy ) GetFinalizers () []string { return nil }
318
- func (m * mockPolicy ) SetFinalizers (_ []string ) {}
319
- func (m * mockPolicy ) GetOwnerReferences () []metav1.OwnerReference { return nil }
320
- func (m * mockPolicy ) SetOwnerReferences ([]metav1.OwnerReference ) {}
321
- func (m * mockPolicy ) GetManagedFields () []metav1.ManagedFieldsEntry { return nil }
322
- func (m * mockPolicy ) SetManagedFields (_ []metav1.ManagedFieldsEntry ) {}
323
- func (m * mockPolicy ) GetGenerateName () string { return "" }
324
- func (m * mockPolicy ) SetGenerateName (_ string ) {}
325
- func (m * mockPolicy ) GetSelfLink () string { return "" }
326
- func (m * mockPolicy ) SetSelfLink (_ string ) {}
327
-
328
- type mockObjectKind struct { kind string }
329
-
330
- func (m * mockObjectKind ) GroupVersionKind () schema.GroupVersionKind {
331
- return schema.GroupVersionKind {Kind : m .kind }
332
- }
333
- func (m * mockObjectKind ) SetGroupVersionKind (_ schema.GroupVersionKind ) {}
334
-
335
281
func TestGetPolicyName (t * testing.T ) {
336
282
t .Parallel ()
337
283
g := NewWithT (t )
338
- policy := & mockPolicy {name : "test-policy" , namespace : "test-ns" }
284
+ policy := & policiesfakes.FakePolicy {}
285
+ policy .GetNameReturns ("test-policy" )
286
+ policy .GetNamespaceReturns ("test-ns" )
339
287
g .Expect (getPolicyName (policy )).To (Equal ("test-ns/test-policy" ))
340
288
}
341
289
342
290
func TestGetPolicyKind (t * testing.T ) {
343
291
t .Parallel ()
344
292
tests := []struct {
345
293
name string
346
- policy policies.Policy
294
+ setup func () policies.Policy
347
295
expected string
348
296
}{
349
297
{
350
- name : "with kind" ,
351
- policy : & mockPolicy {kind : "TestPolicy" },
298
+ name : "with kind" ,
299
+ setup : func () policies.Policy {
300
+ policy := & policiesfakes.FakePolicy {}
301
+ objectKind := & policiesfakes.FakeObjectKind {}
302
+ objectKind .GroupVersionKindReturns (schema.GroupVersionKind {Kind : "TestPolicy" })
303
+ policy .GetObjectKindReturns (objectKind )
304
+ return policy
305
+ },
352
306
expected : "TestPolicy" ,
353
307
},
354
308
{
355
- name : "without kind" ,
356
- policy : & mockPolicy {},
309
+ name : "without kind" ,
310
+ setup : func () policies.Policy {
311
+ policy := & policiesfakes.FakePolicy {}
312
+ policy .GetObjectKindReturns (nil )
313
+ return policy
314
+ },
357
315
expected : "Policy" ,
358
316
},
359
317
}
@@ -362,7 +320,8 @@ func TestGetPolicyKind(t *testing.T) {
362
320
t .Run (test .name , func (t * testing.T ) {
363
321
t .Parallel ()
364
322
g := NewWithT (t )
365
- g .Expect (getPolicyKind (test .policy )).To (Equal (test .expected ))
323
+ policy := test .setup ()
324
+ g .Expect (getPolicyKind (policy )).To (Equal (test .expected ))
366
325
})
367
326
}
368
327
}
0 commit comments