-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_postwithfilesystemform_test.go
42 lines (38 loc) · 1.49 KB
/
test_postwithfilesystemform_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"os"
"strings"
"testing"
curl "github.com/cdwiegand/go-curling/context"
curltestharness "github.com/cdwiegand/go-curling/tests"
"github.com/stretchr/testify/assert"
)
func Test_PostWithFilesystemForm_CurlContext(t *testing.T) {
testRun := curltestharness.BuildTestRun(t)
testRun.ContextBuilder = func(testrun *curltestharness.TestRun) *curl.CurlContext {
os.WriteFile(testrun.GetNextInputFile(), []byte("one"), 0666)
return &curl.CurlContext{
Urls: []string{"https://httpbin.org/post"},
HttpVerb: "POST",
BodyOutput: testrun.EnsureAtLeastOneOutputFiles(),
Data_Standard: []string{"test=@" + testrun.ListInputFiles[0]},
}
}
testRun.SuccessHandler = helper_PostWithFilesystemForm_success
testRun.RunTestRun()
}
func Test_PostWithFilesystemForm_CmdLine(t *testing.T) {
testRun := curltestharness.BuildTestRun(t)
testRun.CmdLineBuilder = func(testrun *curltestharness.TestRun) []string {
os.WriteFile(testrun.GetNextInputFile(), []byte("one"), 0666)
return []string{"https://httpbin.org/post", "-X", "POST", "-d", "test=@" + testrun.ListInputFiles[0], "-o", testrun.GetOneOutputFile()}
}
testRun.SuccessHandler = helper_PostWithFilesystemForm_success
testRun.RunTestRun()
}
func helper_PostWithFilesystemForm_success(json map[string]interface{}, testrun *curltestharness.TestRun) {
t := testrun.Testing
assert.NotNil(t, json["form"])
form := json["form"].(map[string]interface{})
assert.True(t, strings.HasPrefix(form["test"].(string), "@"))
}