liuxiran commented on a change in pull request #1102:
URL: https://github.com/apache/apisix-dashboard/pull/1102#discussion_r561648621



##########
File path: api/test/e2e/import_test.go
##########
@@ -0,0 +1,248 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package e2e
+
+import (
+       "github.com/stretchr/testify/assert"
+       "github.com/tidwall/gjson"
+       "io/ioutil"
+       "net/http"
+       "path/filepath"
+       "testing"
+       "time"
+)
+
+func TestImport_default(t *testing.T) {
+       path, err := filepath.Abs("../testdata/import-test-default.yaml")
+       assert.Nil(t, err)
+
+       headers := map[string]string{
+               "Authorization": token,
+       }
+       files := []UploadFile{
+               {Name: "file", Filepath: path},
+       }
+       PostFile(ManagerAPIHost+"/apisix/admin/import", nil, files, headers)
+
+       // sleep for data sync
+       time.Sleep(sleepTime)
+
+       request, _ := http.NewRequest("GET", 
ManagerAPIHost+"/apisix/admin/routes", nil)
+       request.Header.Add("Authorization", token)
+       resp, err := http.DefaultClient.Do(request)
+       assert.Nil(t, err)
+       defer resp.Body.Close()
+       respBody, _ := ioutil.ReadAll(resp.Body)
+       list := gjson.Get(string(respBody), "data.rows").Value().([]interface{})
+
+       var tests []HttpTestCase
+       for _, item := range list {
+               route := item.(map[string]interface{})
+               tc := HttpTestCase{
+                       Desc:         "route patch for update status(online)",
+                       Object:       ManagerApiExpect(t),
+                       Method:       http.MethodPatch,
+                       Path:         "/apisix/admin/routes/" + 
route["id"].(string),
+                       Body:         `{"status":1}`,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+                       Sleep:        sleepTime,
+               }
+               tests = append(tests, tc)
+       }
+
+       // verify route
+       tests = append(tests, HttpTestCase{
+               Desc:         "verify the route just imported",
+               Object:       APISIXExpect(t),
+               Method:       http.MethodGet,
+               Path:         "/hello",
+               ExpectStatus: http.StatusOK,
+               ExpectBody:   "hello world",
+               Sleep:        sleepTime,
+       })
+
+       // delete test data
+       for _, item := range list {
+               route := item.(map[string]interface{})
+               tc := HttpTestCase{
+                       Desc:         "delete route",
+                       Object:       ManagerApiExpect(t),
+                       Method:       http.MethodDelete,
+                       Path:         "/apisix/admin/routes/" + 
route["id"].(string),
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               }
+               tests = append(tests, tc)
+       }
+
+       for _, tc := range tests {
+               testCaseCheck(tc, t)
+       }
+}
+
+func TestImport_json(t *testing.T) {
+       path, err := filepath.Abs("../testdata/import-test.json")
+       assert.Nil(t, err)
+
+       headers := map[string]string{
+               "Authorization": token,
+       }
+       files := []UploadFile{
+               {Name: "file", Filepath: path},
+       }
+       PostFile(ManagerAPIHost+"/apisix/admin/import", nil, files, headers)
+
+       // sleep for data sync
+       time.Sleep(sleepTime)
+
+       request, _ := http.NewRequest("GET", 
ManagerAPIHost+"/apisix/admin/routes", nil)
+       request.Header.Add("Authorization", token)
+       resp, err := http.DefaultClient.Do(request)
+       assert.Nil(t, err)
+       defer resp.Body.Close()
+       respBody, _ := ioutil.ReadAll(resp.Body)
+       list := gjson.Get(string(respBody), "data.rows").Value().([]interface{})
+
+       var tests []HttpTestCase
+       for _, item := range list {
+               route := item.(map[string]interface{})
+               tc := HttpTestCase{
+                       Desc:         "route patch for update status(online)",
+                       Object:       ManagerApiExpect(t),
+                       Method:       http.MethodPatch,
+                       Path:         "/apisix/admin/routes/" + 
route["id"].(string),
+                       Body:         `{"status":1}`,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+                       Sleep:        sleepTime,
+               }
+               tests = append(tests, tc)
+       }
+
+       // verify route
+       tests = append(tests, HttpTestCase{
+               Desc:         "verify the route just imported",
+               Object:       APISIXExpect(t),
+               Method:       http.MethodGet,
+               Path:         "/hello",
+               ExpectStatus: http.StatusOK,
+               ExpectBody:   "hello world",
+               Sleep:        sleepTime,
+       })
+
+       // delete test data
+       for _, item := range list {
+               route := item.(map[string]interface{})
+               tc := HttpTestCase{
+                       Desc:         "delete route",
+                       Object:       ManagerApiExpect(t),
+                       Method:       http.MethodDelete,
+                       Path:         "/apisix/admin/routes/" + 
route["id"].(string),
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               }
+               tests = append(tests, tc)
+       }
+
+       for _, tc := range tests {
+               testCaseCheck(tc, t)
+       }
+}
+
+func TestImport_with_plugins(t *testing.T) {
+       path, err := filepath.Abs("../testdata/import-test-plugins.yaml")

Review comment:
       I have a question @nic-chen 
   It seems that the API in this file includes a required header params 
`id`(/testdata/import-test-plugins.yaml L48-57), but the route imported from 
this file did not  has header params validation. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to