@@ -2,6 +2,7 @@ package assertions
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
"time"
6
7
7
8
"github.com/onsi/ginkgo/v2"
@@ -15,6 +16,7 @@ import (
15
16
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16
17
"k8s.io/apimachinery/pkg/types"
17
18
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
19
+ gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
18
20
)
19
21
20
22
// Checks GetNamespacedStatuses status for gloo installation namespace
@@ -162,3 +164,90 @@ func (p *Provider) EventuallyHTTPRouteStatusContainsReason(
162
164
g .Expect (route .Status .RouteStatus ).To (gomega .HaveValue (matcher ))
163
165
}, currentTimeout , pollingInterval ).Should (gomega .Succeed ())
164
166
}
167
+
168
+ // EventuallyGatewayCondition checks the provided Gateway condition is set to expect.
169
+ func (p * Provider ) EventuallyGatewayCondition (
170
+ ctx context.Context ,
171
+ gatewayName string ,
172
+ gatewayNamespace string ,
173
+ cond gwv1.GatewayConditionType ,
174
+ expect metav1.ConditionStatus ,
175
+ timeout ... time.Duration ,
176
+ ) {
177
+ ginkgo .GinkgoHelper ()
178
+ currentTimeout , pollingInterval := helper .GetTimeouts (timeout ... )
179
+ p .Gomega .Eventually (func (g gomega.Gomega ) {
180
+ gateway := & gwv1.Gateway {}
181
+ err := p .clusterContext .Client .Get (ctx , types.NamespacedName {Name : gatewayName , Namespace : gatewayNamespace }, gateway )
182
+ g .Expect (err ).NotTo (gomega .HaveOccurred (), "failed to get Gateway" )
183
+
184
+ condition := getConditionByType (gateway .Status .Conditions , string (cond ))
185
+ g .Expect (condition ).NotTo (gomega .BeNil (), fmt .Sprintf ("%v condition not found" , cond ))
186
+ g .Expect (condition .Status ).To (gomega .Equal (expect ), fmt .Sprintf ("%v condition is not %v" , cond , expect ))
187
+ }, currentTimeout , pollingInterval ).Should (gomega .Succeed ())
188
+ }
189
+
190
+ // EventuallyGatewayListenerAttachedRoutes checks the provided Gateway contains the expected attached routes for the listener.
191
+ func (p * Provider ) EventuallyGatewayListenerAttachedRoutes (
192
+ ctx context.Context ,
193
+ gatewayName string ,
194
+ gatewayNamespace string ,
195
+ listener gwv1.SectionName ,
196
+ routes int32 ,
197
+ timeout ... time.Duration ,
198
+ ) {
199
+ ginkgo .GinkgoHelper ()
200
+ currentTimeout , pollingInterval := helper .GetTimeouts (timeout ... )
201
+ p .Gomega .Eventually (func (g gomega.Gomega ) {
202
+ gateway := & gwv1.Gateway {}
203
+ err := p .clusterContext .Client .Get (ctx , types.NamespacedName {Name : gatewayName , Namespace : gatewayNamespace }, gateway )
204
+ g .Expect (err ).NotTo (gomega .HaveOccurred (), "failed to get Gateway" )
205
+
206
+ found := false
207
+ for _ , l := range gateway .Status .Listeners {
208
+ if l .Name == listener {
209
+ found = true
210
+ g .Expect (l .AttachedRoutes ).To (gomega .Equal (routes ), fmt .Sprintf ("%v listener does not contain %d attached routes" , l , routes ))
211
+ }
212
+ }
213
+ g .Expect (found ).To (gomega .BeTrue (), fmt .Sprintf ("%v listener not found" , listener ))
214
+ }, currentTimeout , pollingInterval ).Should (gomega .Succeed ())
215
+ }
216
+
217
+ // EventuallyTCPRouteCondition checks that provided TCPRoute condition is set to expect.
218
+ func (p * Provider ) EventuallyTCPRouteCondition (
219
+ ctx context.Context ,
220
+ routeName string ,
221
+ routeNamespace string ,
222
+ cond gwv1.RouteConditionType ,
223
+ expect metav1.ConditionStatus ,
224
+ timeout ... time.Duration ,
225
+ ) {
226
+ ginkgo .GinkgoHelper ()
227
+ currentTimeout , pollingInterval := helper .GetTimeouts (timeout ... )
228
+ p .Gomega .Eventually (func (g gomega.Gomega ) {
229
+ route := & gwv1a2.TCPRoute {}
230
+ err := p .clusterContext .Client .Get (ctx , types.NamespacedName {Name : routeName , Namespace : routeNamespace }, route )
231
+ g .Expect (err ).NotTo (gomega .HaveOccurred (), "failed to get TCPRoute" )
232
+
233
+ var conditionFound bool
234
+ for _ , parentStatus := range route .Status .Parents {
235
+ condition := getConditionByType (parentStatus .Conditions , string (cond ))
236
+ if condition != nil && condition .Status == expect {
237
+ conditionFound = true
238
+ break
239
+ }
240
+ }
241
+ g .Expect (conditionFound ).To (gomega .BeTrue (), fmt .Sprintf ("%v condition is not %v for any parent" , cond , expect ))
242
+ }, currentTimeout , pollingInterval ).Should (gomega .Succeed ())
243
+ }
244
+
245
+ // Helper function to retrieve a condition by type from a list of conditions.
246
+ func getConditionByType (conditions []metav1.Condition , conditionType string ) * metav1.Condition {
247
+ for _ , condition := range conditions {
248
+ if condition .Type == conditionType {
249
+ return & condition
250
+ }
251
+ }
252
+ return nil
253
+ }
0 commit comments