@@ -6,25 +6,14 @@ import (
6
6
. "github.com/onsi/gomega"
7
7
v1 "sigs.k8s.io/gateway-api/apis/v1"
8
8
"sigs.k8s.io/gateway-api/apis/v1alpha2"
9
-
10
- "github.com/nginxinc/nginx-gateway-fabric/internal/framework/helpers"
11
- "github.com/nginxinc/nginx-gateway-fabric/internal/framework/kinds"
12
9
)
13
10
14
11
func TestAncestorsFull (t * testing.T ) {
15
- ns := "test"
16
-
17
12
createCurStatus := func (numAncestors int , ctlrName string ) []v1alpha2.PolicyAncestorStatus {
18
13
statuses := make ([]v1alpha2.PolicyAncestorStatus , 0 , numAncestors )
19
14
20
15
for i := 0 ; i < numAncestors ; i ++ {
21
16
statuses = append (statuses , v1alpha2.PolicyAncestorStatus {
22
- AncestorRef : v1.ParentReference {
23
- Group : helpers.GetPointer [v1.Group ](v1 .GroupName ),
24
- Kind : helpers.GetPointer [v1.Kind ](kinds .Gateway ),
25
- Namespace : (* v1 .Namespace )(& ns ),
26
- Name : "name" ,
27
- },
28
17
ControllerName : v1 .GatewayController (ctlrName ),
29
18
})
30
19
}
@@ -33,169 +22,33 @@ func TestAncestorsFull(t *testing.T) {
33
22
}
34
23
35
24
tests := []struct {
36
- newAncestor v1.ParentReference
37
- name string
38
- curStatus []v1alpha2.PolicyAncestorStatus
39
- expFull bool
25
+ name string
26
+ curStatus []v1alpha2.PolicyAncestorStatus
27
+ expFull bool
40
28
}{
41
29
{
42
30
name : "not full" ,
43
31
curStatus : createCurStatus (15 , "controller" ),
44
- newAncestor : v1.ParentReference {
45
- Group : helpers.GetPointer [v1.Group ](v1 .GroupName ),
46
- Kind : helpers.GetPointer [v1.Kind ](kinds .Gateway ),
47
- Namespace : (* v1 .Namespace )(& ns ),
48
- Name : "name" ,
49
- },
50
- expFull : false ,
32
+ expFull : false ,
51
33
},
52
34
{
53
35
name : "full; ancestor does not exist in current status" ,
54
36
curStatus : createCurStatus (16 , "controller" ),
55
- newAncestor : v1.ParentReference {
56
- Group : helpers.GetPointer [v1.Group ](v1 .GroupName ),
57
- Kind : helpers.GetPointer [v1.Kind ](kinds .Gateway ),
58
- Namespace : (* v1 .Namespace )(& ns ),
59
- Name : "name" ,
60
- },
61
- expFull : true ,
37
+ expFull : true ,
62
38
},
63
39
{
64
40
name : "full, but ancestor does exist in current status" ,
65
41
curStatus : createCurStatus (16 , "nginx-gateway" ),
66
- newAncestor : v1.ParentReference {
67
- Group : helpers.GetPointer [v1.Group ](v1 .GroupName ),
68
- Kind : helpers.GetPointer [v1.Kind ](kinds .Gateway ),
69
- Namespace : (* v1 .Namespace )(& ns ),
70
- Name : "name" ,
71
- },
72
- expFull : false ,
42
+ expFull : false ,
73
43
},
74
44
}
75
45
76
46
for _ , test := range tests {
77
47
t .Run (test .name , func (t * testing.T ) {
78
48
g := NewWithT (t )
79
49
80
- full := ancestorsFull (test .curStatus , test . newAncestor , "nginx-gateway" )
50
+ full := ancestorsFull (test .curStatus , "nginx-gateway" )
81
51
g .Expect (full ).To (Equal (test .expFull ))
82
52
})
83
53
}
84
54
}
85
-
86
- func TestAncestorStatusExists (t * testing.T ) {
87
- getStatus := func () v1alpha2.PolicyAncestorStatus {
88
- ns := "test"
89
-
90
- return v1alpha2.PolicyAncestorStatus {
91
- AncestorRef : v1.ParentReference {
92
- Group : helpers.GetPointer [v1.Group ](v1 .GroupName ),
93
- Kind : helpers.GetPointer [v1.Kind ](kinds .Gateway ),
94
- Namespace : (* v1 .Namespace )(& ns ),
95
- Name : "name" ,
96
- },
97
- ControllerName : "nginx-gateway" ,
98
- }
99
- }
100
-
101
- type modFunc func (s v1alpha2.PolicyAncestorStatus ) v1alpha2.PolicyAncestorStatus
102
-
103
- getModifiedStatus := func (mod modFunc ) v1alpha2.PolicyAncestorStatus {
104
- return mod (getStatus ())
105
- }
106
-
107
- tests := []struct {
108
- name string
109
- curStatus v1alpha2.PolicyAncestorStatus
110
- newStatus v1alpha2.PolicyAncestorStatus
111
- expEqual bool
112
- }{
113
- {
114
- name : "equal" ,
115
- curStatus : getStatus (),
116
- newStatus : getStatus (),
117
- expEqual : true ,
118
- },
119
- {
120
- name : "different controller name" ,
121
- curStatus : getStatus (),
122
- newStatus : getModifiedStatus (func (s v1alpha2.PolicyAncestorStatus ) v1alpha2.PolicyAncestorStatus {
123
- s .ControllerName = "not-ours"
124
- return s
125
- }),
126
- expEqual : false ,
127
- },
128
- {
129
- name : "different groups; one nil" ,
130
- curStatus : getStatus (),
131
- newStatus : getModifiedStatus (func (s v1alpha2.PolicyAncestorStatus ) v1alpha2.PolicyAncestorStatus {
132
- s .AncestorRef .Group = nil
133
- return s
134
- }),
135
- expEqual : false ,
136
- },
137
- {
138
- name : "different groups" ,
139
- curStatus : getStatus (),
140
- newStatus : getModifiedStatus (func (s v1alpha2.PolicyAncestorStatus ) v1alpha2.PolicyAncestorStatus {
141
- s .AncestorRef .Group = helpers.GetPointer [v1.Group ]("DiffGroup" )
142
- return s
143
- }),
144
- expEqual : false ,
145
- },
146
- {
147
- name : "different kinds; one nil" ,
148
- curStatus : getStatus (),
149
- newStatus : getModifiedStatus (func (s v1alpha2.PolicyAncestorStatus ) v1alpha2.PolicyAncestorStatus {
150
- s .AncestorRef .Kind = nil
151
- return s
152
- }),
153
- expEqual : false ,
154
- },
155
- {
156
- name : "different kinds" ,
157
- curStatus : getStatus (),
158
- newStatus : getModifiedStatus (func (s v1alpha2.PolicyAncestorStatus ) v1alpha2.PolicyAncestorStatus {
159
- s .AncestorRef .Kind = helpers.GetPointer [v1.Kind ](kinds .HTTPRoute )
160
- return s
161
- }),
162
- expEqual : false ,
163
- },
164
- {
165
- name : "different names" ,
166
- curStatus : getStatus (),
167
- newStatus : getModifiedStatus (func (s v1alpha2.PolicyAncestorStatus ) v1alpha2.PolicyAncestorStatus {
168
- s .AncestorRef .Name = "diff-name"
169
- return s
170
- }),
171
- expEqual : false ,
172
- },
173
- {
174
- name : "different namespaces; one nil" ,
175
- curStatus : getStatus (),
176
- newStatus : getModifiedStatus (func (s v1alpha2.PolicyAncestorStatus ) v1alpha2.PolicyAncestorStatus {
177
- s .AncestorRef .Namespace = nil
178
- return s
179
- }),
180
- expEqual : false ,
181
- },
182
- {
183
- name : "different namespaces" ,
184
- newStatus : getModifiedStatus (func (s v1alpha2.PolicyAncestorStatus ) v1alpha2.PolicyAncestorStatus {
185
- diffNs := "diff"
186
- s .AncestorRef .Namespace = (* v1 .Namespace )(& diffNs )
187
- return s
188
- }),
189
- expEqual : false ,
190
- },
191
- }
192
-
193
- for _ , test := range tests {
194
- t .Run (test .name , func (t * testing.T ) {
195
- g := NewWithT (t )
196
-
197
- equal := ancestorStatusEqual (test .curStatus , test .newStatus )
198
- g .Expect (equal ).To (Equal (test .expEqual ))
199
- })
200
- }
201
- }
0 commit comments