MCPcopy
hub / github.com/labstack/echo / TestBindUnmarshalParam

Function TestBindUnmarshalParam

bind_test.go:309–334  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

307}
308
309func TestBindUnmarshalParam(t *testing.T) {
310 e := New()
311 req := httptest.NewRequest(http.MethodGet, "/?ts=2016-12-06T19:09:05Z&sa=one,two,three&ta=2016-12-06T19:09:05Z&ta=2016-12-06T19:09:05Z&ST=baz", nil)
312 rec := httptest.NewRecorder()
313 c := e.NewContext(req, rec)
314 result := struct {
315 T Timestamp `query:"ts"`
316 ST Struct
317 StWithTag struct {
318 Foo string `query:"st"`
319 }
320 TA []Timestamp `query:"ta"`
321 SA StringArray `query:"sa"`
322 }{}
323 err := c.Bind(&result)
324 ts := Timestamp(time.Date(2016, 12, 6, 19, 9, 5, 0, time.UTC))
325
326 if assert.NoError(t, err) {
327 // assert.Equal( Timestamp(reflect.TypeOf(&Timestamp{}), time.Date(2016, 12, 6, 19, 9, 5, 0, time.UTC)), result.T)
328 assert.Equal(t, ts, result.T)
329 assert.Equal(t, StringArray([]string{"one", "two", "three"}), result.SA)
330 assert.Equal(t, []Timestamp{ts, ts}, result.TA)
331 assert.Equal(t, Struct{""}, result.ST) // child struct does not have a field with matching tag
332 assert.Equal(t, "baz", result.StWithTag.Foo) // child struct has field with matching tag
333 }
334}
335
336func TestBindUnmarshalText(t *testing.T) {
337 e := New()

Callers

nothing calls this directly

Calls 5

BindMethod · 0.95
NewFunction · 0.85
TimestampTypeAlias · 0.85
StringArrayTypeAlias · 0.85
NewContextMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…