@@ -339,6 +339,49 @@ spec:
339339 name: httpbin-service-e2e-test
340340 port:
341341 number: 80
342+ `
343+ allowMethods = `
344+ apiVersion: networking.k8s.io/v1
345+ kind: Ingress
346+ metadata:
347+ name: allow-methods
348+ annotations:
349+ k8s.apisix.apache.org/http-allow-methods: "GET,POST"
350+ spec:
351+ ingressClassName: %s
352+ rules:
353+ - host: httpbin.example
354+ http:
355+ paths:
356+ - path: /anything
357+ pathType: Exact
358+ backend:
359+ service:
360+ name: httpbin-service-e2e-test
361+ port:
362+ number: 80
363+ `
364+
365+ blockMethods = `
366+ apiVersion: networking.k8s.io/v1
367+ kind: Ingress
368+ metadata:
369+ name: block-methods
370+ annotations:
371+ k8s.apisix.apache.org/http-block-methods: "DELETE"
372+ spec:
373+ ingressClassName: %s
374+ rules:
375+ - host: httpbin2.example
376+ http:
377+ paths:
378+ - path: /anything
379+ pathType: Exact
380+ backend:
381+ service:
382+ name: httpbin-service-e2e-test
383+ port:
384+ number: 80
342385`
343386 )
344387 BeforeEach (func () {
@@ -496,5 +539,76 @@ spec:
496539 Expect (err ).NotTo (HaveOccurred (), "unmarshalling echo plugin config" )
497540 Expect (echoConfig ["body" ]).To (Equal ("hello from plugin config" ), "checking echo plugin body" )
498541 })
542+ It ("methods" , func () {
543+ Expect (s .CreateResourceFromString (fmt .Sprintf (allowMethods , s .Namespace ()))).ShouldNot (HaveOccurred (), "creating Ingress" )
544+ Expect (s .CreateResourceFromString (fmt .Sprintf (blockMethods , s .Namespace ()))).ShouldNot (HaveOccurred (), "creating Ingress" )
545+
546+ tets := []* scaffold.RequestAssert {
547+ {
548+ Method : "GET" ,
549+ Path : "/anything" ,
550+ Host : "httpbin.example" ,
551+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
552+ },
553+ {
554+ Method : "POST" ,
555+ Path : "/anything" ,
556+ Host : "httpbin.example" ,
557+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
558+ },
559+ {
560+ Method : "PUT" ,
561+ Path : "/anything" ,
562+ Host : "httpbin.example" ,
563+ Check : scaffold .WithExpectedStatus (http .StatusMethodNotAllowed ),
564+ },
565+ {
566+ Method : "PATCH" ,
567+ Path : "/anything" ,
568+ Host : "httpbin.example" ,
569+ Check : scaffold .WithExpectedStatus (http .StatusMethodNotAllowed ),
570+ },
571+ {
572+ Method : "DELETE" ,
573+ Path : "/anything" ,
574+ Host : "httpbin.example" ,
575+ Check : scaffold .WithExpectedStatus (http .StatusMethodNotAllowed ),
576+ },
577+ {
578+ Method : "GET" ,
579+ Path : "/anything" ,
580+ Host : "httpbin2.example" ,
581+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
582+ },
583+ {
584+ Method : "POST" ,
585+ Path : "/anything" ,
586+ Host : "httpbin2.example" ,
587+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
588+ },
589+ {
590+ Method : "PUT" ,
591+ Path : "/anything" ,
592+ Host : "httpbin2.example" ,
593+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
594+ },
595+ {
596+ Method : "PATCH" ,
597+ Path : "/anything" ,
598+ Host : "httpbin2.example" ,
599+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
600+ },
601+ {
602+ Method : "DELETE" ,
603+ Path : "/anything" ,
604+ Host : "httpbin2.example" ,
605+ Check : scaffold .WithExpectedStatus (http .StatusMethodNotAllowed ),
606+ },
607+ }
608+
609+ for _ , test := range tets {
610+ s .RequestAssert (test )
611+ }
612+ })
499613 })
500614})
0 commit comments