-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathgout_valid_test.go
More file actions
41 lines (34 loc) · 782 Bytes
/
gout_valid_test.go
File metadata and controls
41 lines (34 loc) · 782 Bytes
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
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)
}
}