Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import (
- // "io/ioutil"
- "net/http"
- "path/filepath"
- // "strings"
- "time"
- "github.com/onsi/ginkgo"
- "github.com/onsi/gomega"
- "github.com/tidwall/gjson"
- "github.com/apisix/manager-api/test/e2enew/base"
- )
- var _ = ginkgo.Describe("import default tests", func() {
- ginkgo.It("should pass if not error", func() {
- path, err := filepath.Abs("../../testdata/import/default.yaml")
- gomega.Expect(err).To(gomega.BeNil())
- headers := map[string]string{
- "Authorization": base.GetToken(),
- }
- files := []base.UploadFile{
- {Name: "file", Filepath: path},
- }
- _, status, err := base.HttpPostFile(base.ManagerAPIHost+"/apisix/admin/import/routes", nil, files, headers)
- gomega.Expect(err).To(gomega.BeNil())
- gomega.Expect(status).To(gomega.Equal(http.StatusOK))
- // sleep for data sync
- time.Sleep(base.SleepTime)
- respBody, _, err := base.HttpGet(base.ManagerAPIHost+"/apisix/admin/routes", headers)
- gomega.Expect(err).To(gomega.BeNil())
- list := gjson.Get(string(respBody), "data.rows").Value().([]interface{})
- var entries []base.HttpTestCase
- for _, item := range list {
- route := item.(map[string]interface{})
- entries = append(entries,
- base.HttpTestCase{
- Desc: "route patch for update status(online)",
- Object: base.ManagerApiExpect(),
- Method: http.MethodPatch,
- Path: "/apisix/admin/routes/" + route["id"].(string),
- Body: `{"status":1}`,
- Headers: map[string]string{"Authorization": base.GetToken()},
- ExpectStatus: http.StatusOK,
- Sleep: base.SleepTime,
- })
- }
- // table.DescribeTable("tests route patch for update status(online)",
- // func(tc base.HttpTestCase) {
- // base.RunTestCase(tc)
- // },
- // entries...,
- // )
- //verify route
- // ginkgo.It("verify the route just imported", func() {
- entries = append(entries,
- base.HttpTestCase{
- Object: base.ManagerApiExpect(),
- Method: http.MethodGet,
- Path: "/hello",
- ExpectStatus: http.StatusOK,
- ExpectBody: "hello world",
- Sleep: base.SleepTime,
- })
- //delete test data
- for _, item := range list {
- route := item.(map[string]interface{})
- entries = append(entries, base.HttpTestCase{
- Desc: "delete route",
- Object: base.ManagerApiExpect(),
- Method: http.MethodDelete,
- Path: "/apisix/admin/routes/" + route["id"].(string),
- Headers: map[string]string{"Authorization": base.GetToken()},
- ExpectStatus: http.StatusOK,
- })
- }
- // table.DescribeTable("tests delete route",
- // func(tc base.HttpTestCase) {
- // base.RunTestCase(tc)
- // },
- // entries...,
- // )
- for _, tcase := range entries {
- base.RunTestCase(tcase)
- }
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment