代码拉取完成,页面将自动刷新
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")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。