MCPcopy Index your code
hub / github.com/labstack/echo / TestFormFieldBinder

Function TestFormFieldBinder

binder_test.go:134–165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

132}
133
134func TestFormFieldBinder(t *testing.T) {
135 e := New()
136 body := `texta=foo&slice=5`
137 req := httptest.NewRequest(http.MethodPost, "/api/search?id=1&nr=2&slice=3&slice=4", strings.NewReader(body))
138 req.Header.Set(HeaderContentLength, strconv.Itoa(len(body)))
139 req.Header.Set(HeaderContentType, MIMEApplicationForm)
140
141 rec := httptest.NewRecorder()
142 c := e.NewContext(req, rec)
143
144 b := FormFieldBinder(c)
145
146 var texta string
147 id := int64(99)
148 nr := int64(88)
149 var slice = make([]int64, 0)
150 var notExisting = make([]int64, 0)
151 err := b.
152 Int64s("slice", &slice).
153 Int64("id", &id).
154 Int64("nr", &nr).
155 String("texta", &texta).
156 Int64s("notExisting", &notExisting).
157 BindError()
158
159 assert.NoError(t, err)
160 assert.Equal(t, "foo", texta)
161 assert.Equal(t, int64(1), id)
162 assert.Equal(t, int64(2), nr)
163 assert.Equal(t, []int64{5, 3, 4}, slice)
164 assert.Equal(t, []int64{}, notExisting)
165}
166
167func TestValueBinder_errorStopsBinding(t *testing.T) {
168 // this test documents "feature" that binding multiple params can change destination if it was bound before

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
FormFieldBinderFunction · 0.85
SetMethod · 0.80
NewContextMethod · 0.80
BindErrorMethod · 0.80
Int64sMethod · 0.80
Int64Method · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…