-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_noredirect_test.go
47 lines (41 loc) · 1.68 KB
/
test_noredirect_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
package main
import (
"testing"
curl "github.com/cdwiegand/go-curling/context"
curltestharness "github.com/cdwiegand/go-curling/tests"
)
func Test_NoRedirectTest_CurlContext(t *testing.T) {
testRun := curltestharness.BuildTestRun(t)
testRun.ContextBuilder = func(testrun *curltestharness.TestRun) *curl.CurlContext {
return &curl.CurlContext{
Urls: []string{"https://httpbin.org/redirect-to?url=https://httpbin.org/get%3Ftest%3Done"},
BodyOutput: testrun.EnsureAtLeastOneOutputFiles(),
FollowRedirects: false,
}
}
testRun.SuccessHandler = helper_NoRedirectTest_Success
testRun.RunTestRun()
}
func Test_NoRedirectTest_CmdLine(t *testing.T) {
testRun := curltestharness.BuildTestRun(t)
testRun.GetOneOutputFile() // so we can use one output file
testRun.CmdLineBuilder = func(testrun *curltestharness.TestRun) []string {
// adding -L so we act like curl and follow the redirect
return []string{"https://httpbin.org/redirect-to?url=https://httpbin.org/get%3Ftest%3Done", "-o", testrun.ListOutputFiles[0]}
}
testRun.SuccessHandler = helper_NoRedirectTest_Success
testRun.RunTestRun()
}
func helper_NoRedirectTest_Success(json map[string]interface{}, testrun *curltestharness.TestRun) {
t := testrun.Testing
if len(testrun.Responses.Responses) != 1 {
t.Error("Should only have gotten 1 response")
}
firstResponse := testrun.Responses.Responses[0]
if firstResponse.HttpResponse.StatusCode < 300 || firstResponse.HttpResponse.StatusCode > 399 {
t.Errorf("Should have 3xx response code, got %d", firstResponse.HttpResponse.StatusCode)
}
if firstResponse.HttpResponse.Header.Get("Location") == "" {
t.Errorf("Should have a Location header, did not get one")
}
}