bisakh

ginkgo-error

Mar 15th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.78 KB | None | 0 0
  1. import (
  2.     // "io/ioutil"
  3.     "net/http"
  4.     "path/filepath"
  5.     // "strings"
  6.     "time"
  7.  
  8.     "github.com/onsi/ginkgo"
  9.     "github.com/onsi/gomega"
  10.     "github.com/tidwall/gjson"
  11.  
  12.     "github.com/apisix/manager-api/test/e2enew/base"
  13. )
  14.  
  15. var _ = ginkgo.Describe("import default tests", func() {
  16.     ginkgo.It("should pass if not error", func() {
  17.         path, err := filepath.Abs("../../testdata/import/default.yaml")
  18.         gomega.Expect(err).To(gomega.BeNil())
  19.  
  20.         headers := map[string]string{
  21.             "Authorization": base.GetToken(),
  22.         }
  23.         files := []base.UploadFile{
  24.             {Name: "file", Filepath: path},
  25.         }
  26.  
  27.         _, status, err := base.HttpPostFile(base.ManagerAPIHost+"/apisix/admin/import/routes", nil, files, headers)
  28.         gomega.Expect(err).To(gomega.BeNil())
  29.         gomega.Expect(status).To(gomega.Equal(http.StatusOK))
  30.  
  31.         // sleep for data sync
  32.         time.Sleep(base.SleepTime)
  33.  
  34.         respBody, _, err := base.HttpGet(base.ManagerAPIHost+"/apisix/admin/routes", headers)
  35.         gomega.Expect(err).To(gomega.BeNil())
  36.  
  37.         list := gjson.Get(string(respBody), "data.rows").Value().([]interface{})
  38.  
  39.         var entries []base.HttpTestCase
  40.         for _, item := range list {
  41.             route := item.(map[string]interface{})
  42.             entries = append(entries,
  43.                 base.HttpTestCase{
  44.                     Desc:         "route patch for update status(online)",
  45.                     Object:       base.ManagerApiExpect(),
  46.                     Method:       http.MethodPatch,
  47.                     Path:         "/apisix/admin/routes/" + route["id"].(string),
  48.                     Body:         `{"status":1}`,
  49.                     Headers:      map[string]string{"Authorization": base.GetToken()},
  50.                     ExpectStatus: http.StatusOK,
  51.                     Sleep:        base.SleepTime,
  52.                 })
  53.         }
  54.  
  55.         // table.DescribeTable("tests route patch for update status(online)",
  56.         //  func(tc base.HttpTestCase) {
  57.         //      base.RunTestCase(tc)
  58.         //  },
  59.         //  entries...,
  60.         // )
  61.  
  62.         //verify route
  63.         // ginkgo.It("verify the route just imported", func() {
  64.         entries = append(entries,
  65.             base.HttpTestCase{
  66.                 Object:       base.ManagerApiExpect(),
  67.                 Method:       http.MethodGet,
  68.                 Path:         "/hello",
  69.                 ExpectStatus: http.StatusOK,
  70.                 ExpectBody:   "hello world",
  71.                 Sleep:        base.SleepTime,
  72.             })
  73.  
  74.         //delete test data
  75.         for _, item := range list {
  76.             route := item.(map[string]interface{})
  77.             entries = append(entries, base.HttpTestCase{
  78.                 Desc:         "delete route",
  79.                 Object:       base.ManagerApiExpect(),
  80.                 Method:       http.MethodDelete,
  81.                 Path:         "/apisix/admin/routes/" + route["id"].(string),
  82.                 Headers:      map[string]string{"Authorization": base.GetToken()},
  83.                 ExpectStatus: http.StatusOK,
  84.             })
  85.         }
  86.  
  87.         // table.DescribeTable("tests delete route",
  88.         //  func(tc base.HttpTestCase) {
  89.         //      base.RunTestCase(tc)
  90.         //  },
  91.         //  entries...,
  92.         // )
  93.  
  94.         for _, tcase := range entries {
  95.             base.RunTestCase(tcase)
  96.         }
  97.  
  98.     })
  99. })
  100.  
Advertisement
Add Comment
Please, Sign In to add comment