@@ -19,6 +19,11 @@ import (
1919 "github.com/envoyproxy/gateway/internal/envoygateway/config"
2020 "github.com/envoyproxy/gateway/internal/gatewayapi/resource"
2121 "github.com/envoyproxy/gateway/internal/message"
22+
23+ gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
24+ gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
25+ gwapiv1a3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
26+ gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"
2227)
2328
2429func TestNewOfflineGatewayAPIController (t * testing.T ) {
@@ -114,27 +119,132 @@ func TestNewOfflineGatewayAPIController(t *testing.T) {
114119}
115120
116121func TestNewOfflineGatewayAPIControllerIndexRegistration (t * testing.T ) {
117- t .Run ("offline controller creation list index test" , func (t * testing.T ) {
118- cfg , err := config .New (os .Stdout , os .Stderr )
122+ cfg , err := config .New (os .Stdout , os .Stderr )
123+ require .NoError (t , err )
124+
125+ cfg .EnvoyGateway .Provider = & egv1a1.EnvoyGatewayProvider {
126+ Type : egv1a1 .ProviderTypeCustom ,
127+ }
128+
129+ pResources := new (message.ProviderResources )
130+ reconciler , err := NewOfflineGatewayAPIController (context .Background (), cfg , nil , pResources )
131+ require .NoError (t , err )
132+ require .NotNil (t , reconciler )
133+
134+ // verify all indices registered by newOfflineGatewayAPIClient are usable via MatchingFields
135+ cli := reconciler .Client
136+
137+ t .Run ("Gateway indices" , func (t * testing.T ) {
138+ err := cli .List (context .Background (), & gwapiv1.GatewayList {}, client.MatchingFields {classGatewayIndex : "any" })
139+ require .NoError (t , err )
140+ err = cli .List (context .Background (), & gwapiv1.GatewayList {}, client.MatchingFields {secretGatewayIndex : "any" })
119141 require .NoError (t , err )
142+ })
120143
121- cfg .EnvoyGateway .Provider = & egv1a1.EnvoyGatewayProvider {
122- Type : egv1a1 .ProviderTypeCustom ,
123- }
144+ t .Run ("HTTPRoute indices" , func (t * testing.T ) {
145+ err := cli .List (context .Background (), & gwapiv1.HTTPRouteList {}, client.MatchingFields {gatewayHTTPRouteIndex : "any" })
146+ require .NoError (t , err )
147+ err = cli .List (context .Background (), & gwapiv1.HTTPRouteList {}, client.MatchingFields {backendHTTPRouteIndex : "any" })
148+ require .NoError (t , err )
149+ err = cli .List (context .Background (), & gwapiv1.HTTPRouteList {}, client.MatchingFields {httpRouteFilterHTTPRouteIndex : "any" })
150+ require .NoError (t , err )
151+ })
124152
125- pResources := new (message. ProviderResources )
126- reconciler , err := NewOfflineGatewayAPIController (context .Background (), cfg , nil , pResources )
153+ t . Run ( "GRPCRoute indices" , func ( t * testing. T ) {
154+ err := cli . List (context .Background (), & gwapiv1. GRPCRouteList {}, client. MatchingFields { gatewayGRPCRouteIndex : "any" } )
127155 require .NoError (t , err )
128- require .NotNil (t , reconciler )
156+ err = cli .List (context .Background (), & gwapiv1.GRPCRouteList {}, client.MatchingFields {backendGRPCRouteIndex : "any" })
157+ require .NoError (t , err )
158+ })
129159
130- // test an index that is registered by a "WithIndex" call
131- cli := reconciler .Client
132- // call client.List with a "matching field" list option that uses the index
160+ t .Run ("TCPRoute indices" , func (t * testing.T ) {
161+ err := cli .List (context .Background (), & gwapiv1a2.TCPRouteList {}, client.MatchingFields {gatewayTCPRouteIndex : "any" })
162+ require .NoError (t , err )
163+ err = cli .List (context .Background (), & gwapiv1a2.TCPRouteList {}, client.MatchingFields {backendTCPRouteIndex : "any" })
164+ require .NoError (t , err )
165+ })
166+
167+ t .Run ("UDPRoute indices" , func (t * testing.T ) {
168+ err := cli .List (context .Background (), & gwapiv1a2.UDPRouteList {}, client.MatchingFields {gatewayUDPRouteIndex : "any" })
169+ require .NoError (t , err )
170+ err = cli .List (context .Background (), & gwapiv1a2.UDPRouteList {}, client.MatchingFields {backendUDPRouteIndex : "any" })
171+ require .NoError (t , err )
172+ })
173+
174+ t .Run ("TLSRoute indices" , func (t * testing.T ) {
175+ err := cli .List (context .Background (), & gwapiv1a3.TLSRouteList {}, client.MatchingFields {gatewayTLSRouteIndex : "any" })
176+ require .NoError (t , err )
177+ err = cli .List (context .Background (), & gwapiv1a3.TLSRouteList {}, client.MatchingFields {backendTLSRouteIndex : "any" })
178+ require .NoError (t , err )
179+ })
180+
181+ t .Run ("EnvoyProxy indices" , func (t * testing.T ) {
182+ err := cli .List (context .Background (), & egv1a1.EnvoyProxyList {}, client.MatchingFields {backendEnvoyProxyTelemetryIndex : "any" })
183+ require .NoError (t , err )
133184 err = cli .List (context .Background (), & egv1a1.EnvoyProxyList {}, client.MatchingFields {secretEnvoyProxyIndex : "any" })
134185 require .NoError (t , err )
186+ })
135187
136- // test another index which exists in indexers.go but isn't registered
137- err = cli .List (context .Background (), & egv1a1.BackendList {}, client.MatchingFields {secretBackendIndex : "test " })
188+ t . Run ( "BackendTrafficPolicy index" , func ( t * testing. T ) {
189+ err : = cli .List (context .Background (), & egv1a1.BackendTrafficPolicyList {}, client.MatchingFields {configMapBtpIndex : "any " })
138190 require .NoError (t , err )
139191 })
192+
193+ t .Run ("ClientTrafficPolicy indices" , func (t * testing.T ) {
194+ err := cli .List (context .Background (), & egv1a1.ClientTrafficPolicyList {}, client.MatchingFields {configMapCtpIndex : "any" })
195+ require .NoError (t , err )
196+ err = cli .List (context .Background (), & egv1a1.ClientTrafficPolicyList {}, client.MatchingFields {secretCtpIndex : "any" })
197+ require .NoError (t , err )
198+ err = cli .List (context .Background (), & egv1a1.ClientTrafficPolicyList {}, client.MatchingFields {clusterTrustBundleCtpIndex : "any" })
199+ require .NoError (t , err )
200+ })
201+
202+ t .Run ("SecurityPolicy indices" , func (t * testing.T ) {
203+ err := cli .List (context .Background (), & egv1a1.SecurityPolicyList {}, client.MatchingFields {secretSecurityPolicyIndex : "any" })
204+ require .NoError (t , err )
205+ err = cli .List (context .Background (), & egv1a1.SecurityPolicyList {}, client.MatchingFields {backendSecurityPolicyIndex : "any" })
206+ require .NoError (t , err )
207+ err = cli .List (context .Background (), & egv1a1.SecurityPolicyList {}, client.MatchingFields {configMapSecurityPolicyIndex : "any" })
208+ require .NoError (t , err )
209+ })
210+
211+ t .Run ("EnvoyExtensionPolicy indices" , func (t * testing.T ) {
212+ err := cli .List (context .Background (), & egv1a1.EnvoyExtensionPolicyList {}, client.MatchingFields {backendEnvoyExtensionPolicyIndex : "any" })
213+ require .NoError (t , err )
214+ err = cli .List (context .Background (), & egv1a1.EnvoyExtensionPolicyList {}, client.MatchingFields {secretEnvoyExtensionPolicyIndex : "any" })
215+ require .NoError (t , err )
216+ err = cli .List (context .Background (), & egv1a1.EnvoyExtensionPolicyList {}, client.MatchingFields {configMapEepIndex : "any" })
217+ require .NoError (t , err )
218+ })
219+
220+ t .Run ("BackendTLSPolicy indices" , func (t * testing.T ) {
221+ err := cli .List (context .Background (), & gwapiv1.BackendTLSPolicyList {}, client.MatchingFields {configMapBtlsIndex : "any" })
222+ require .NoError (t , err )
223+ err = cli .List (context .Background (), & gwapiv1.BackendTLSPolicyList {}, client.MatchingFields {secretBtlsIndex : "any" })
224+ require .NoError (t , err )
225+ err = cli .List (context .Background (), & gwapiv1.BackendTLSPolicyList {}, client.MatchingFields {clusterTrustBundleBtlsIndex : "any" })
226+ require .NoError (t , err )
227+ })
228+
229+ t .Run ("Backend indices" , func (t * testing.T ) {
230+ err := cli .List (context .Background (), & egv1a1.BackendList {}, client.MatchingFields {configMapBackendIndex : "any" })
231+ require .NoError (t , err )
232+ err = cli .List (context .Background (), & egv1a1.BackendList {}, client.MatchingFields {secretBackendIndex : "any" })
233+ require .NoError (t , err )
234+ err = cli .List (context .Background (), & egv1a1.BackendList {}, client.MatchingFields {clusterTrustBundleBackendIndex : "any" })
235+ require .NoError (t , err )
236+ })
237+
238+ t .Run ("HTTPRouteFilter indices" , func (t * testing.T ) {
239+ err := cli .List (context .Background (), & egv1a1.HTTPRouteFilterList {}, client.MatchingFields {configMapHTTPRouteFilterIndex : "any" })
240+ require .NoError (t , err )
241+ err = cli .List (context .Background (), & egv1a1.HTTPRouteFilterList {}, client.MatchingFields {secretHTTPRouteFilterIndex : "any" })
242+ require .NoError (t , err )
243+ })
244+
245+ t .Run ("ReferenceGrant index" , func (t * testing.T ) {
246+ err := cli .List (context .Background (), & gwapiv1b1.ReferenceGrantList {}, client.MatchingFields {targetRefGrantRouteIndex : "any" })
247+ require .NoError (t , err )
248+ })
249+
140250}
0 commit comments