Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Jiang <[email protected]>
  • Loading branch information
jwrookie committed Apr 12, 2022
1 parent 2058b92 commit f73c75c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 16 deletions.
4 changes: 2 additions & 2 deletions api/internal/core/entity/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ func TestMapKV2Node(t *testing.T) {
wantRes *Node
}{
{
name: "address typo error",
name: "invalid upstream node",
key: "127.0.0.1:0:0",
wantErr: true,
errMessage: "address typo error",
errMessage: "invalid upstream node",
},
{
name: "when address contains port convert should succeed",
Expand Down
67 changes: 53 additions & 14 deletions api/test/e2enew/upstream/upstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,60 @@ var _ = ginkgo.Describe("Upstream", func() {
})
})
ginkgo.It("create upstream3 success when pass host is 'node' and nodes without port", func() {
createUpstreamBody := make(map[string]interface{})
createUpstreamBody["name"] = "upstream3"
createUpstreamBody["nodes"] = map[string]float64{base.UpstreamIp: 100}
createUpstreamBody["type"] = "roundrobin"
createUpstreamBody["pass_host"] = "node"
ginkgo.By("create upstream3", func() {
createUpstreamBody := make(map[string]interface{})
createUpstreamBody["name"] = "upstream3"
createUpstreamBody["nodes"] = map[string]float64{base.UpstreamIp: 100}
createUpstreamBody["type"] = "roundrobin"
createUpstreamBody["pass_host"] = "node"

_createUpstreamBody, err := json.Marshal(createUpstreamBody)
gomega.Expect(err).To(gomega.BeNil())
base.RunTestCase(base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodPut,
Path: "/apisix/admin/upstreams/3",
Body: string(_createUpstreamBody),
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
_createUpstreamBody, err := json.Marshal(createUpstreamBody)
gomega.Expect(err).To(gomega.BeNil())
base.RunTestCase(base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodPut,
Path: "/apisix/admin/upstreams/3",
Body: string(_createUpstreamBody),
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
})
})

ginkgo.By("create route using the upstream3", func() {
base.RunTestCase(base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodPut,
Path: "/apisix/admin/routes/1",
Body: `{
"name": "route1",
"uri": "/hello",
"upstream_id": "3"
}`,
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
Sleep: base.SleepTime,
})
})

ginkgo.By("hit the route just created", func() {
base.RunTestCase(base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello",
ExpectStatus: http.StatusOK,
ExpectBody: "hello",
Sleep: base.SleepTime,
})
})

ginkgo.By("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,
})
})
})
ginkgo.It("create upstream failed, name existed", func() {
Expand Down

0 comments on commit f73c75c

Please sign in to comment.