mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-09 22:44:05 +08:00
add upload unittest
This commit is contained in:
4
hrp/tests/test.env
Normal file
4
hrp/tests/test.env
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
UserName=test
|
||||||
|
Password=654321
|
||||||
|
PROJECT_KEY=AAABBBCCC
|
||||||
|
content_type=application/json; charset=UTF-8
|
||||||
38
hrp/tests/upload_test.go
Normal file
38
hrp/tests/upload_test.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package tests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCaseUploadFile(t *testing.T) {
|
||||||
|
testcase := &hrp.TestCase{
|
||||||
|
Config: hrp.NewConfig("test upload file to httpbin").
|
||||||
|
SetBaseURL("https://httpbin.org"),
|
||||||
|
TestSteps: []hrp.IStep{
|
||||||
|
hrp.NewStep("upload file").
|
||||||
|
WithVariables(map[string]interface{}{
|
||||||
|
"m_encoder": "${multipart_encoder($m_upload)}",
|
||||||
|
"m_upload": map[string]interface{}{"file": "test.env"},
|
||||||
|
}).
|
||||||
|
POST("/post").
|
||||||
|
WithHeaders(map[string]string{"Content-Type": "${multipart_content_type($m_encoder)}"}).
|
||||||
|
WithBody("$m_encoder").
|
||||||
|
Validate().
|
||||||
|
AssertEqual("status_code", 200, "check status code").
|
||||||
|
AssertStartsWith("body.files.file", "UserName=test", "check uploaded file"),
|
||||||
|
hrp.NewStep("upload file with keyword").
|
||||||
|
POST("/post").
|
||||||
|
WithUpload(map[string]interface{}{"file": "test.env"}).
|
||||||
|
Validate().
|
||||||
|
AssertEqual("status_code", 200, "check status code").
|
||||||
|
AssertStartsWith("body.files.file", "UserName=test", "check uploaded file"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := hrp.NewRunner(t).Run(testcase)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("run testcase error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user