36 Star 160 Fork 23

小蚂蚁/gout

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
gout_valid_test.go 782 Bytes
一键复制 编辑 原始数据 按行查看 历史
guonaihong 提交于 2021-08-26 20:36 . Valid (#310)
package gout
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
type testValid struct {
Val string `valid:"required"`
}
func Test_Valid(t *testing.T) {
total := int32(1)
router := setupMethod(&total)
ts := httptest.NewServer(http.HandlerFunc(router.ServeHTTP))
defer ts.Close()
testCases := []string{"bindjson", "bindxml", "bindyaml", "bindheader"}
for _, c := range testCases {
val := testValid{}
g := GET(ts.URL + "/someGet")
var err error
switch c {
case "bindjson":
err = g.BindJSON(&val).Do()
case "bindxml":
err = g.BindXML(&val).Do()
case "bindyaml":
err = g.BindYAML(&val).Do()
case "bindheader":
err = g.BindHeader(&val).Do()
}
//fmt.Printf("-->%v\n", err)
assert.Error(t, err)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/guonaihong/gout.git
git@gitee.com:guonaihong/gout.git
guonaihong
gout
gout
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385