-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_headers_test.go
56 lines (48 loc) · 1.77 KB
/
test_headers_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
package main
import (
"testing"
curl "github.com/cdwiegand/go-curling/context"
curltestharness "github.com/cdwiegand/go-curling/tests"
"github.com/stretchr/testify/assert"
)
func Test_Headers_CurlContext(t *testing.T) {
testRun := curltestharness.BuildTestRun(t)
testRun.ContextBuilder = func(testrun *curltestharness.TestRun) *curl.CurlContext {
return &curl.CurlContext{
Urls: []string{"https://httpbin.org/headers"},
Headers: []string{"X-Hello: World", "X-Good: Times"},
BodyOutput: testrun.EnsureAtLeastOneOutputFiles(),
}
}
testRun.SuccessHandler = helpers_Headers_success
testRun.RunTestRun()
// second form:
testRun = curltestharness.BuildTestRun(t)
headersDict := make(map[string]string)
headersDict["X-Hello"] = "World"
headersDict["X-Good"] = "Times"
testRun.ContextBuilder = func(testrun *curltestharness.TestRun) *curl.CurlContext {
return &curl.CurlContext{
Urls: []string{"https://httpbin.org/headers"},
HeadersDict: headersDict,
BodyOutput: testrun.EnsureAtLeastOneOutputFiles(),
}
}
testRun.SuccessHandler = helpers_Headers_success
testRun.RunTestRun()
}
func Test_Headers_CmdLine(t *testing.T) {
testRun := curltestharness.BuildTestRun(t)
testRun.CmdLineBuilder = func(testrun *curltestharness.TestRun) []string {
return []string{"https://httpbin.org/headers", "-H", "X-Hello: World", "--header", "X-Good: Times", "-o", testrun.GetOneOutputFile()}
}
testRun.SuccessHandler = helpers_Headers_success
testRun.RunTestRun()
}
func helpers_Headers_success(json map[string]interface{}, testrun *curltestharness.TestRun) {
t := testrun.Testing
assert.NotNil(t, json["headers"])
args := json["headers"].(map[string]interface{})
assert.EqualValues(t, "World", args["X-Hello"])
assert.EqualValues(t, "Times", args["X-Good"])
}