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

Function TestValueBinder_JSONUnmarshaler

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

Source from the content-addressed store, hash-verified

2191}
2192
2193func TestValueBinder_JSONUnmarshaler(t *testing.T) {
2194 example := big.NewInt(999)
2195
2196 var testCases = []struct {
2197 name string
2198 whenURL string
2199 expectError string
2200 expectValue big.Int
2201 givenBindErrors []error
2202 givenFailFast bool
2203 whenMust bool
2204 }{
2205 {
2206 name: "ok, binds value",
2207 whenURL: "/search?param=999&param=998",
2208 expectValue: *example,
2209 },
2210 {
2211 name: "ok, params values empty, value is not changed",
2212 whenURL: "/search?nope=1",
2213 expectValue: big.Int{},
2214 },
2215 {
2216 name: "nok, previous errors fail fast without binding value",
2217 givenFailFast: true,
2218 whenURL: "/search?param=1&param=100",
2219 expectValue: big.Int{},
2220 expectError: "previous error",
2221 },
2222 {
2223 name: "nok, conversion fails, value is not changed",
2224 whenURL: "/search?param=nope&param=xxx",
2225 expectValue: big.Int{},
2226 expectError: "code=400, message=failed to bind field value to json.Unmarshaler interface, err=math/big: cannot unmarshal \"nope\" into a *big.Int, field=param",
2227 },
2228 {
2229 name: "ok (must), binds value",
2230 whenMust: true,
2231 whenURL: "/search?param=999&param=998",
2232 expectValue: *example,
2233 },
2234 {
2235 name: "ok (must), params values empty, returns error, value is not changed",
2236 whenMust: true,
2237 whenURL: "/search?nope=1",
2238 expectValue: big.Int{},
2239 expectError: "code=400, message=required field value is empty, field=param",
2240 },
2241 {
2242 name: "nok (must), previous errors fail fast without binding value",
2243 givenFailFast: true,
2244 whenMust: true,
2245 whenURL: "/search?param=1&param=xxx",
2246 expectValue: big.Int{},
2247 expectError: "previous error",
2248 },
2249 {
2250 name: "nok (must), conversion fails, value is not changed",

Callers

nothing calls this directly

Calls 6

createTestContextFunction · 0.85
QueryParamsBinderFunction · 0.85
FailFastMethod · 0.80
BindErrorMethod · 0.80
MustJSONUnmarshalerMethod · 0.80
JSONUnmarshalerMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…