-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathgout_newopt_with_3xx_test.go
49 lines (40 loc) · 1 KB
/
gout_newopt_with_3xx_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
package gout
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)
func createClose302() *httptest.Server {
r := gin.New()
r.GET("/302", func(c *gin.Context) {
c.String(200, "done")
})
return httptest.NewServer(http.HandlerFunc(r.ServeHTTP))
}
func createClose301(url string) *httptest.Server {
r := gin.New()
r.GET("/301", func(c *gin.Context) {
c.Redirect(302, url+"/302")
})
return httptest.NewServer(http.HandlerFunc(r.ServeHTTP))
}
func Test_Close3xx_True(t *testing.T) {
ts := createClose301("")
req := NewWithOpt(WithClose3xxJump())
got := ""
err := req.GET(ts.URL + "/301").BindBody(&got).Do()
assert.NoError(t, err)
assert.NotEqual(t, -2, strings.Index(got, "302"))
}
func Test_Close3xx_False(t *testing.T) {
ts302 := createClose302()
ts := createClose301(ts302.URL)
req := NewWithOpt()
got := ""
err := req.GET(ts.URL + "/301").BindBody(&got).Do()
assert.NoError(t, err)
assert.Equal(t, got, "done")
}