Skip to content

Commit

Permalink
fix: remove cases external service dependency (#2697)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 committed Dec 21, 2022
1 parent d168119 commit 8d6d1c7
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 108 deletions.
6 changes: 6 additions & 0 deletions api/test/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ services:
apisix_dashboard_e2e:
ipv4_address: 172.16.238.21

upstream_httpbin:
image: kennethreitz/httpbin
networks:
apisix_dashboard_e2e:
ipv4_address: 172.16.238.22

apisix:
hostname: apisix_server1
image: apache/apisix:2.15.1-debian
Expand Down
1 change: 1 addition & 0 deletions api/test/e2e/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (

UpstreamIp = "upstream"
UpstreamGrpcIp = "upstream_grpc"
UpstreamHTTPBinIp = "upstream_httpbin"
APISIXHost = "http://127.0.0.1:9080"
APISIXAdminAPIHost = "http://127.0.0.1:9180"
APISIXInternalUrl = "http://apisix:9080"
Expand Down
197 changes: 89 additions & 108 deletions api/test/e2e/upstream/upstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,114 +329,95 @@ var _ = Describe("Upstream", func() {
})
})

var _ = Describe("Upstream update with domain", func() {
It("create upstream success", func() {
createUpstreamBody := make(map[string]interface{})
createUpstreamBody["name"] = "upstream1"
createUpstreamBody["nodes"] = []map[string]interface{}{
{
"host": base.UpstreamIp,
"port": 1980,
"weight": 1,
"priority": 10,
},
}
createUpstreamBody["type"] = "roundrobin"
_createUpstreamBody, err := json.Marshal(createUpstreamBody)
Expect(err).To(BeNil())
base.RunTestCase(base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodPut,
Path: "/apisix/admin/upstreams/1",
Body: string(_createUpstreamBody),
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
ExpectBody: `"code":0`,
})
})
It("create route using the upstream(use proxy rewriteproxy rewrite plugin)", func() {
base.RunTestCase(base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodPut,
Path: "/apisix/admin/routes/1",
Body: `{
"name": "route1",
"uri": "/*",
"upstream_id": "1",
"plugins": {
"proxy-rewrite": {
"uri": "/",
"scheme": "https"
}
}
}`,
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
Sleep: base.SleepTime,
})
})
It("update upstream with domain", func() {
createUpstreamBody := make(map[string]interface{})
createUpstreamBody["nodes"] = []map[string]interface{}{
{
"host": "www.google.com",
"port": 443,
"weight": 1,
"priority": 10,
},
}
createUpstreamBody["type"] = "roundrobin"
createUpstreamBody["pass_host"] = "node"
_createUpstreamBody, err := json.Marshal(createUpstreamBody)
Expect(err).To(BeNil())
base.RunTestCase(base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodPut,
Path: "/apisix/admin/upstreams/1",
Body: string(_createUpstreamBody),
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
})
})
It("hit the route using upstream 1", func() {
base.RunTestCase(base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/",
ExpectStatus: http.StatusOK,
ExpectBody: "google",
Sleep: base.SleepTime,
})
})
It("delete route", func() {
base.RunTestCase(base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodDelete,
Path: "/apisix/admin/routes/1",
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
})
})
It("delete upstream", func() {
base.RunTestCase(base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodDelete,
Path: "/apisix/admin/upstreams/1",
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
})
})
It("hit the route just deleted", func() {
base.RunTestCase(base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/get",
ExpectStatus: http.StatusNotFound,
ExpectBody: "{\"error_msg\":\"404 Route Not Found\"}\n",
Sleep: base.SleepTime,
})
})
})
var _ = DescribeTable("Upstream update with domain",
func(tc base.HttpTestCase) {
base.RunTestCase(tc)
},
Entry("create upstream success", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodPut,
Path: "/apisix/admin/upstreams/1",
Body: `{
"name": "upstream1",
"nodes": [{
"host": "` + base.UpstreamIp + `",
"port": 1980,
"weight": 1,
"priority": 10
}],
"type": "roundrobin"
}`,
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
ExpectBody: `"code":0`,
Sleep: base.SleepTime,
}),
Entry("create route using the upstream(use proxy rewriteproxy rewrite plugin)", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodPut,
Path: "/apisix/admin/routes/1",
Body: `{
"name": "route1",
"uri": "/*",
"upstream_id": "1"
}`,
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
Sleep: base.SleepTime,
}),
Entry("update upstream with domain", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodPut,
Path: "/apisix/admin/upstreams/1",
Body: `{
"name": "upstream1",
"nodes": [{
"host": "` + base.UpstreamHTTPBinIp + `",
"port": 80,
"weight": 1,
"priority": 10
}],
"type": "roundrobin",
"pass_host": "node"
}`,
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
Sleep: base.SleepTime,
}),
Entry("hit the route using upstream 1", base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Headers: map[string]string{
"Host": "iamhttpbin.org",
},
Path: "/anything",
ExpectStatus: http.StatusOK,
ExpectBody: "http://iamhttpbin.org/anything",
Sleep: base.SleepTime,
}),
Entry("delete route", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodDelete,
Path: "/apisix/admin/routes/1",
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
}),
Entry("delete upstream", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodDelete,
Path: "/apisix/admin/upstreams/1",
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
}),
Entry("hit the route just deleted", base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/get",
ExpectStatus: http.StatusNotFound,
ExpectBody: `{"error_msg":"404 Route Not Found"}`,
Sleep: base.SleepTime,
}),
)

var _ = Describe("Upstream chash remote addr", func() {
It("create chash upstream with key (remote_addr)", func() {
Expand Down

0 comments on commit 8d6d1c7

Please sign in to comment.