Jaycean commented on a change in pull request #1465:
URL: https://github.com/apache/apisix-dashboard/pull/1465#discussion_r580805498



##########
File path: api/test/e2enew/base/http.go
##########
@@ -92,3 +104,44 @@ func BatchTestServerPort(times int) map[string]int {
 
        return res
 }
+
+func GetReader(reqParams map[string]string, contentType string, files 
[]UploadFile) (io.Reader, string, error) {
+       if strings.Index(contentType, "json") > -1 {
+               bytesData, _ := json.Marshal(reqParams)
+               return bytes.NewReader(bytesData), contentType, nil
+       }
+       if files != nil {
+               body := &bytes.Buffer{}
+               writer := multipart.NewWriter(body)
+               for _, uploadFile := range files {
+                       file, err := os.Open(uploadFile.Filepath)
+                       if err != nil {
+                               return nil, "", err
+                       }
+                       part, err := writer.CreateFormFile(uploadFile.Name, 
filepath.Base(uploadFile.Filepath))
+                       if err != nil {
+                               return nil, "", err
+                       }
+                       _, err = io.Copy(part, file)
+                       defer file.Close()
+               }
+               for k, v := range reqParams {
+                       if err := writer.WriteField(k, v); err != nil {
+                               return nil, "", err
+                       }
+               }
+               if err := writer.Close(); err != nil {
+                       return nil, "", err
+               }
+               return body, writer.FormDataContentType(), nil
+       }
+
+       urlValues := url.Values{}
+       for key, val := range reqParams {
+               urlValues.Set(key, val)
+       }
+
+       reqBody := urlValues.Encode()
+
+       return strings.NewReader(reqBody), contentType, nil

Review comment:
       http.go In the getReader function, It from the old E2E/ http.go.
   
   My idea is that E2E will be rewritten with the new ginkgo, so I migrate it 
directly here without modifying the code.
   
   My understanding here is to deal with a variety of data formats, such as 
form-data, JSON, files.
   
   The incoming params may be in a variety of situations. Here is the third one 
url.Values set reqParams map[string]string




----------------------------------------------------------------
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