Skip to content

Commit

Permalink
test: add e2e test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tokers committed Apr 2, 2021
1 parent d083e12 commit 44641ed
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/apisix/resource.go
Expand Up @@ -76,6 +76,7 @@ type routeItem struct {
UpstreamId string `json:"upstream_id"`
ServiceId string `json:"service_id"`
Host string `json:"host"`
Hosts []string `json:"hosts"`
URI string `json:"uri"`
Vars [][]v1.StringOrSlice `json:"vars"`
Uris []string `json:"uris"`
Expand Down Expand Up @@ -115,6 +116,7 @@ func (i *item) route(clusterName string) (*v1.Route, error) {
UpstreamId: route.UpstreamId,
ServiceId: route.ServiceId,
Plugins: route.Plugins,
Hosts: route.Hosts,
Priority: route.Priority,
}, nil
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/apisix/route.go
Expand Up @@ -36,6 +36,7 @@ type routeReqBody struct {
Uris []string `json:"uris,omitempty"`
Vars [][]v1.StringOrSlice `json:"vars,omitempty"`
Host string `json:"host,omitempty"`
Hosts []string `json:"hosts,omitempty"`
ServiceId string `json:"service_id,omitempty"`
UpstreamId string `json:"upstream_id,omitempty"`
Plugins v1.Plugins `json:"plugins,omitempty"`
Expand Down Expand Up @@ -166,6 +167,7 @@ func (r *routeClient) Create(ctx context.Context, obj *v1.Route) (*v1.Route, err
Name: obj.Name,
URI: obj.Path,
Host: obj.Host,
Hosts: obj.Hosts,
ServiceId: obj.ServiceId,
UpstreamId: obj.UpstreamId,
Uris: obj.Uris,
Expand Down Expand Up @@ -235,6 +237,7 @@ func (r *routeClient) Update(ctx context.Context, obj *v1.Route) (*v1.Route, err
Desc: obj.Name,
Name: obj.Name,
Host: obj.Host,
Hosts: obj.Hosts,
URI: obj.Path,
ServiceId: obj.ServiceId,
Plugins: obj.Plugins,
Expand Down
42 changes: 42 additions & 0 deletions test/e2e/ingress/resourcepushing.go
Expand Up @@ -333,4 +333,46 @@ spec:
resp.Body().Contains("origin")
resp.Header("X-Request-Id").NotEmpty()
})

ginkgo.It("verify route items", func() {
backendSvc, backendSvcPort := s.DefaultHTTPBackend()
apisixRoute := fmt.Sprintf(`
apiVersion: apisix.apache.org/v2alpha1
kind: ApisixRoute
metadata:
name: httpbin-route
spec:
http:
- name: rule1
priority: 1
match:
hosts:
- httpbin.com
paths:
- /ip
backend:
serviceName: %s
servicePort: %d
`, backendSvc, backendSvcPort[0])

assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(apisixRoute), "creating ApisixRoute")
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1))
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(1))

routes, err := s.ListApisixRoutes()
assert.Nil(ginkgo.GinkgoT(), err, "listing routes")
assert.Len(ginkgo.GinkgoT(), routes, 1)
name := s.Namespace() + "_" + "httpbin-route" + "_" + "rule1"
assert.Equal(ginkgo.GinkgoT(), routes[0].Name, name)
assert.Equal(ginkgo.GinkgoT(), routes[0].Uris, []string{"/ip"})
assert.Equal(ginkgo.GinkgoT(), routes[0].Hosts, []string{"httpbin.com"})

resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect()
resp.Status(http.StatusOK)
resp.Body().Contains("origin")

resp = s.NewAPISIXClient().GET("/ip").Expect()
resp.Status(http.StatusNotFound)
resp.Body().Contains("404 Route Not Found")
})
})
5 changes: 5 additions & 0 deletions test/e2e/scaffold/k8s.go
Expand Up @@ -276,3 +276,8 @@ func (s *Scaffold) newAPISIXTunnels() error {
s.addFinalizers(s.apisixHttpsTunnel.Close)
return nil
}

// Namespace returns the current working namespace.
func (s *Scaffold) Namespace() string {
return s.kubectlOptions.Namespace
}

0 comments on commit 44641ed

Please sign in to comment.