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

Function TestCustomUnmarshalStruct

gin_test.go:962–976  ·  gin_test.go::TestCustomUnmarshalStruct
(t *testing.T)

Source from the content-addressed store, hash-verified

960}
961
962func TestCustomUnmarshalStruct(t *testing.T) {
963 route := Default()
964 var request struct {
965 Birthday Birthday `form:"birthday"`
966 }
967 route.GET("/test", func(ctx *Context) {
968 _ = ctx.BindQuery(&request)
969 ctx.JSON(200, request.Birthday)
970 })
971 req := httptest.NewRequest(http.MethodGet, "/test?birthday=2000-01-01", nil)
972 w := httptest.NewRecorder()
973 route.ServeHTTP(w, req)
974 assert.Equal(t, 200, w.Code)
975 assert.Equal(t, `"2000/01/01"`, w.Body.String())
976}
977
978// Test the fix for https://github.com/gin-gonic/gin/issues/4002
979func TestMethodNotAllowedNoRoute(t *testing.T) {

Callers

nothing calls this directly

Calls 6

BindQueryMethod · 0.80
DefaultFunction · 0.70
GETMethod · 0.65
StringMethod · 0.65
JSONMethod · 0.45
ServeHTTPMethod · 0.45

Tested by

no test coverage detected