29 lines
607 B
Go
29 lines
607 B
Go
package requests
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"474420502.top/eson/gjson"
|
|
)
|
|
|
|
func TestUploadFile(t *testing.T) {
|
|
ses := NewSession()
|
|
wf := ses.Put("http://httpbin.org/put")
|
|
|
|
ufile, err := UploadFileFromPath("go.mod")
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
wf.SetBodyAuto(ufile, TypeUploadFile)
|
|
resp, _ := wf.Execute()
|
|
if _, ok := gjson.Get(resp.Content(), "files").Map()["file0"]; !ok {
|
|
t.Error("file error", resp.Content())
|
|
}
|
|
|
|
wf.SetBodyAuto("go.mod", TypeUploadFile)
|
|
resp, _ = wf.Execute()
|
|
if _, ok := gjson.Get(resp.Content(), "files").Map()["file0"]; !ok {
|
|
t.Error("file error", resp.Content())
|
|
}
|
|
}
|