Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generate an uid when post a route without id #1883

Merged
merged 1 commit into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/internal/handler/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (h *Handler) Create(c droplet.Context) (interface{}, error) {
}

if input.Script != nil {
if input.ID == "" {
if utils.InterfaceToString(input.ID) == "" {
input.ID = utils.GetFlakeUidStr()
}
script := &entity.Script{}
Expand Down
61 changes: 61 additions & 0 deletions api/test/e2enew/route/route_with_plugin_orchestration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/extensions/table"
"github.com/onsi/gomega"
"github.com/tidwall/gjson"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this file seems doesn't test script field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The request body was contained in dag-conf.json.Also include the script field.
You can see this file line 32.

bytes, err := ioutil.ReadFile("../../testdata/dag-conf.json")

"github.com/apisix/manager-api/test/e2enew/base"
)
Expand Down Expand Up @@ -108,4 +109,64 @@ var _ = ginkgo.Describe("route with plugin orchestration", func() {
Sleep: base.SleepTime,
}),
)

table.DescribeTable("test route with plugin orchestration (post method)",
func(tc base.HttpTestCase) {
base.RunTestCase(tc)
},
table.Entry("make sure the route is not created", base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello",
ExpectStatus: http.StatusNotFound,
ExpectBody: `{"error_msg":"404 Route Not Found"}`,
}),
)

var routeID string
ginkgo.It("create route with correct dag config by post", func() {
resp, code, err := base.HttpPost(base.ManagerAPIHost+"/apisix/admin/routes",
map[string]string{"Authorization": base.GetToken()}, dagConf)
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(code).Should(gomega.Equal(200))
routeID = gjson.Get(string(resp), "data.id").String()
})

ginkgo.It("test the route with plugin orchestration", func() {
base.RunTestCase(base.HttpTestCase{
Desc: "verify the route (should be blocked)",
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello",
Query: "t=root.exe",
ExpectStatus: http.StatusForbidden,
ExpectBody: `blocked`,
Sleep: base.SleepTime,
})
base.RunTestCase(base.HttpTestCase{
Desc: "verify the route (should not be blocked)",
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello",
ExpectStatus: http.StatusOK,
ExpectBody: `hello world`,
})
base.RunTestCase(base.HttpTestCase{
Desc: "delete the route by routeID",
Object: base.ManagerApiExpect(),
Method: http.MethodDelete,
Path: "/apisix/admin/routes/" + routeID,
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
})
base.RunTestCase(base.HttpTestCase{
Desc: "make sure the route has been deleted",
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello",
ExpectStatus: http.StatusNotFound,
ExpectBody: `{"error_msg":"404 Route Not Found"}`,
Sleep: base.SleepTime,
})
})
})