MCPcopy Create free account
hub / github.com/devfeel/dotweb / TestBinder_Bind_default

Function TestBinder_Bind_default

bind_test.go:199–252  ·  view source on GitHub ↗

else

(t *testing.T)

Source from the content-addressed store, hash-verified

197
198// else
199func TestBinder_Bind_default(t *testing.T) {
200
201 binder := newBinder()
202
203 if binder == nil {
204 t.Error("binder can not be nil!")
205 }
206
207 // init DotServer
208 app := New()
209
210 if app == nil {
211 t.Error("app can not be nil!")
212 }
213
214 // expected
215 expected := &Person{
216 Hair: "Brown",
217 HasGlass: true,
218 Age: 10,
219 Legs: []string{"Left", "Right"},
220 }
221 param := &InitContextParam{
222 t,
223 expected,
224 "",
225 test.ToDefault,
226 }
227
228 // init param
229 context := initContext(param)
230
231 form := make(map[string][]string)
232 form["Hair"] = []string{"Brown"}
233 form["HasGlass"] = []string{"true"}
234 form["Age"] = []string{"10"}
235 form["Legs"] = []string{"Left", "Right"}
236
237 context.request.Form = form
238 // actual
239 person := &Person{}
240
241 err := binder.Bind(person, context)
242
243 // check error must nil
244 test.Nil(t, err)
245
246 // check expected
247 test.Equal(t, expected, person)
248
249 t.Log("person:", person)
250 t.Log("expected:", expected)
251
252}
253
254// else
255func TestBinder_Bind_default_error(t *testing.T) {

Callers

nothing calls this directly

Calls 7

NilFunction · 0.92
EqualFunction · 0.92
newBinderFunction · 0.85
NewFunction · 0.85
initContextFunction · 0.85
ErrorMethod · 0.65
BindMethod · 0.65

Tested by

no test coverage detected