Skip to content

Commit b7504b1

Browse files
committed
fix: r
Signed-off-by: Ashing Zheng <[email protected]>
1 parent 4f63c3b commit b7504b1

File tree

1 file changed

+89
-2
lines changed

1 file changed

+89
-2
lines changed

test/e2e/crds/v2/basic.go

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,26 @@
1818
package v2
1919

2020
import (
21+
"fmt"
22+
"net/http"
23+
"time"
24+
2125
. "github.com/onsi/ginkgo/v2"
2226
. "github.com/onsi/gomega"
27+
"k8s.io/apimachinery/pkg/types"
2328

29+
apiv2 "github.com/apache/apisix-ingress-controller/api/v2"
30+
"github.com/apache/apisix-ingress-controller/test/e2e/framework"
2431
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
2532
)
2633

2734
var _ = Describe("APISIX Standalone Basic Tests", Label("apisix.apache.org", "v2", "basic"), func() {
28-
s := scaffold.NewDefaultScaffold()
35+
var (
36+
s = scaffold.NewDefaultScaffold()
37+
applier = framework.NewApplier(s.GinkgoT, s.K8sClient, s.CreateResourceFromString)
38+
)
2939

30-
Describe("APISIX HTTP Proxy", func() {
40+
Context("APISIX HTTP Proxy", func() {
3141
It("should handle basic HTTP requests", func() {
3242
httpClient := s.NewAPISIXClient()
3343
Expect(httpClient).NotTo(BeNil())
@@ -52,4 +62,81 @@ var _ = Describe("APISIX Standalone Basic Tests", Label("apisix.apache.org", "v2
5262
})
5363

5464
})
65+
66+
Context("IngressClass Annotations", func() {
67+
It("Basic tests", func() {
68+
const ingressClassYaml = `
69+
apiVersion: networking.k8s.io/v1
70+
kind: IngressClass
71+
metadata:
72+
name: %s
73+
annotations:
74+
apisix.apache.org/parameters-namespace: %s
75+
spec:
76+
controller: %s
77+
parameters:
78+
apiGroup: apisix.apache.org
79+
kind: GatewayProxy
80+
name: apisix-proxy-config
81+
`
82+
83+
By("create GatewayProxy")
84+
85+
err := s.CreateResourceFromString(s.GetGatewayProxySpec())
86+
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
87+
time.Sleep(5 * time.Second)
88+
89+
By("create IngressClass")
90+
ingressClass := fmt.Sprintf(ingressClassYaml, s.Namespace(), s.Namespace(), s.GetControllerName())
91+
err = s.CreateResourceFromString(ingressClass)
92+
Expect(err).NotTo(HaveOccurred(), "creating IngressClass")
93+
time.Sleep(5 * time.Second)
94+
95+
const apisixRouteSpec = `
96+
apiVersion: apisix.apache.org/v2
97+
kind: ApisixRoute
98+
metadata:
99+
name: default
100+
spec:
101+
ingressClassName: %s
102+
http:
103+
- name: rule0
104+
match:
105+
hosts:
106+
- httpbin
107+
paths:
108+
- %s
109+
backends:
110+
- serviceName: httpbin-service-e2e-test
111+
servicePort: 80
112+
`
113+
request := func(path string) int {
114+
return s.NewAPISIXClient().GET(path).WithHost("httpbin").Expect().Raw().StatusCode
115+
}
116+
117+
By("apply ApisixRoute")
118+
var apisixRoute apiv2.ApisixRoute
119+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute,
120+
fmt.Sprintf(apisixRouteSpec, s.Namespace(), "/get"))
121+
122+
By("verify ApisixRoute works")
123+
Eventually(request).WithArguments("/get").WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK))
124+
125+
By("update ApisixRoute")
126+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute,
127+
fmt.Sprintf(apisixRouteSpec, s.Namespace(), "/headers"))
128+
Eventually(request).WithArguments("/get").WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound))
129+
s.RequestAssert(&scaffold.RequestAssert{
130+
Method: "GET",
131+
Path: "/headers",
132+
Host: "httpbin",
133+
Check: scaffold.WithExpectedStatus(http.StatusOK),
134+
})
135+
136+
By("delete ApisixRoute")
137+
err = s.DeleteResource("ApisixRoute", "default")
138+
Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixRoute")
139+
Eventually(request).WithArguments("/headers").WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound))
140+
})
141+
})
55142
})

0 commit comments

Comments
 (0)