36 Star 157 Fork 23

小蚂蚁 / gout

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
gout_newopt_with_3xx_test.go 1.00 KB
一键复制 编辑 原始数据 按行查看 历史
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")
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/guonaihong/gout.git
git@gitee.com:guonaihong/gout.git
guonaihong
gout
gout
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891