MCPcopy
hub / github.com/gin-gonic/gin / TestContextShouldBindWithTOML

Function TestContextShouldBindWithTOML

context_test.go:2445–2460  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2443}
2444
2445func TestContextShouldBindWithTOML(t *testing.T) {
2446 w := httptest.NewRecorder()
2447 c, _ := CreateTestContext(w)
2448
2449 c.Request, _ = http.NewRequest(http.MethodPost, "/", strings.NewReader("foo='bar'\nbar= 'foo'"))
2450 c.Request.Header.Add("Content-Type", MIMETOML) // set fake content-type
2451
2452 var obj struct {
2453 Foo string `toml:"foo"`
2454 Bar string `toml:"bar"`
2455 }
2456 require.NoError(t, c.ShouldBindTOML(&obj))
2457 assert.Equal(t, "foo", obj.Bar)
2458 assert.Equal(t, "bar", obj.Foo)
2459 assert.Equal(t, 0, w.Body.Len())
2460}
2461
2462func TestContextBadAutoShouldBind(t *testing.T) {
2463 w := httptest.NewRecorder()

Callers

nothing calls this directly

Calls 2

CreateTestContextFunction · 0.85
ShouldBindTOMLMethod · 0.80

Tested by

no test coverage detected