-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_postwithfilesystembinaryform_test.go
72 lines (67 loc) · 2.89 KB
/
test_postwithfilesystembinaryform_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"os"
"testing"
curl "github.com/cdwiegand/go-curling/context"
curltestharness "github.com/cdwiegand/go-curling/tests"
"github.com/stretchr/testify/assert"
)
func Test_PostWithFilesystemBinaryForm_CurlContext(t *testing.T) {
testRun := curltestharness.BuildTestRun(t)
testRun.ContextBuilder = func(testrun *curltestharness.TestRun) *curl.CurlContext {
os.WriteFile(testrun.GetNextInputFile(), []byte("a&b=c"), 0666)
return &curl.CurlContext{
Urls: []string{"https://httpbin.org/post"},
HttpVerb: "POST",
BodyOutput: testrun.EnsureAtLeastOneOutputFiles(),
Data_Binary: []string{"test=@" + testrun.ListInputFiles[0]},
}
}
testRun.SuccessHandler = helper_PostWithFilesystemBinaryForm_success
testRun.RunTestRun()
}
func Test_PostWithFilesystemBinaryForm_CurlContext_directFile(t *testing.T) {
testRun := curltestharness.BuildTestRun(t)
testRun.ContextBuilder = func(testrun *curltestharness.TestRun) *curl.CurlContext {
os.WriteFile(testrun.GetNextInputFile(), []byte("test=a&b=c"), 0666)
return &curl.CurlContext{
Urls: []string{"https://httpbin.org/post"},
HttpVerb: "POST",
BodyOutput: testrun.EnsureAtLeastOneOutputFiles(),
Data_Binary: []string{"@" + testrun.ListInputFiles[0]},
}
}
testRun.SuccessHandler = helper_PostWithFilesystemBinaryForm_success_directFile
testRun.RunTestRun()
}
func Test_PostWithFilesystemBinaryForm_CmdLine(t *testing.T) {
testRun := curltestharness.BuildTestRun(t)
testRun.CmdLineBuilder = func(testrun *curltestharness.TestRun) []string {
os.WriteFile(testrun.GetNextInputFile(), []byte("a&b=c"), 0666)
return []string{"https://httpbin.org/post", "-X", "POST", "--data-binary", "test=@" + testrun.ListInputFiles[0], "-o", testrun.GetOneOutputFile()}
}
testRun.SuccessHandler = helper_PostWithFilesystemBinaryForm_success
testRun.RunTestRun()
}
func Test_PostWithFilesystemBinaryForm_CmdLine_directFile(t *testing.T) {
testRun := curltestharness.BuildTestRun(t)
testRun.CmdLineBuilder = func(testrun *curltestharness.TestRun) []string {
os.WriteFile(testrun.GetNextInputFile(), []byte("test=a&b=c"), 0666)
return []string{"https://httpbin.org/post", "-X", "POST", "--data-binary", "@" + testrun.ListInputFiles[0], "-o", testrun.GetOneOutputFile()}
}
testRun.SuccessHandler = helper_PostWithFilesystemBinaryForm_success_directFile
testRun.RunTestRun()
}
func helper_PostWithFilesystemBinaryForm_success(json map[string]interface{}, testrun *curltestharness.TestRun) {
t := testrun.Testing
assert.NotNil(t, json["form"])
form := json["form"].(map[string]any)
assert.True(t, form["test"].(string)[0] == '@')
}
func helper_PostWithFilesystemBinaryForm_success_directFile(json map[string]interface{}, testrun *curltestharness.TestRun) {
t := testrun.Testing
assert.NotNil(t, json["form"])
form := json["form"].(map[string]any)
assert.EqualValues(t, "a", form["test"])
assert.EqualValues(t, "c", form["b"])
}