@@ -314,4 +314,77 @@ spec:
314314 Body ().Contains (`{"error_msg":"404 Route Not Found"}` )
315315 })
316316 })
317+
318+ var (
319+ gatewayProxyWithInvalidProviderType = `
320+ apiVersion: gateway.apisix.io/v1alpha1
321+ kind: GatewayProxy
322+ metadata:
323+ name: api7-proxy-config
324+ spec:
325+ provider:
326+ type: "InvalidType"
327+ `
328+ gatewayProxyWithMissingControlPlane = `
329+ apiVersion: gateway.apisix.io/v1alpha1
330+ kind: GatewayProxy
331+ metadata:
332+ name: api7-proxy-config
333+ spec:
334+ provider:
335+ type: "ControlPlane"
336+ `
337+ gatewayProxyWithValidProvider = `
338+ apiVersion: gateway.apisix.io/v1alpha1
339+ kind: GatewayProxy
340+ metadata:
341+ name: api7-proxy-config
342+ spec:
343+ provider:
344+ type: "ControlPlane"
345+ controlPlane:
346+ endpoints:
347+ - "http://localhost:9180"
348+ auth:
349+ type: "AdminKey"
350+ adminKey:
351+ value: "test-key"
352+ `
353+ )
354+
355+ Context ("Test GatewayProxy Provider Validation" , func () {
356+ AfterEach (func () {
357+ By ("Clean up GatewayProxy resources" )
358+ _ = s .DeleteResourceFromString (gatewayProxyWithInvalidProviderType )
359+ _ = s .DeleteResourceFromString (gatewayProxyWithMissingControlPlane )
360+ _ = s .DeleteResourceFromString (gatewayProxyWithValidProvider )
361+ })
362+
363+ It ("Should reject invalid provider type" , func () {
364+ By ("Create GatewayProxy with invalid provider type" )
365+ err := s .CreateResourceFromString (gatewayProxyWithInvalidProviderType )
366+ Expect (err ).To (HaveOccurred (), "creating GatewayProxy with invalid provider type" )
367+ Expect (err .Error ()).To (ContainSubstring ("Invalid value" ))
368+ })
369+
370+ It ("Should reject missing controlPlane configuration" , func () {
371+ By ("Create GatewayProxy with missing controlPlane" )
372+ err := s .CreateResourceFromString (gatewayProxyWithMissingControlPlane )
373+ Expect (err ).To (HaveOccurred (), "creating GatewayProxy with missing controlPlane" )
374+ Expect (err .Error ()).To (ContainSubstring ("controlPlane must be specified when type is ControlPlane" ))
375+ })
376+
377+ It ("Should accept valid provider configuration" , func () {
378+ By ("Create GatewayProxy with valid provider" )
379+ err := s .CreateResourceFromString (gatewayProxyWithValidProvider )
380+ Expect (err ).NotTo (HaveOccurred (), "creating GatewayProxy with valid provider" )
381+
382+ Eventually (func () string {
383+ gpYaml , err := s .GetResourceYaml ("GatewayProxy" , "api7-proxy-config" )
384+ Expect (err ).NotTo (HaveOccurred (), "getting GatewayProxy yaml" )
385+ return gpYaml
386+ }).WithTimeout (8 * time .Second ).ProbeEvery (2 * time .Second ).
387+ Should (ContainSubstring (`"type":"ControlPlane"` ), "checking GatewayProxy is applied" )
388+ })
389+ })
317390})
0 commit comments