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

Function TestValueBinder_TextUnmarshaler

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

Source from the content-addressed store, hash-verified

2282}
2283
2284func TestValueBinder_TextUnmarshaler(t *testing.T) {
2285 example := big.NewInt(999)
2286
2287 var testCases = []struct {
2288 name string
2289 whenURL string
2290 expectError string
2291 expectValue big.Int
2292 givenBindErrors []error
2293 givenFailFast bool
2294 whenMust bool
2295 }{
2296 {
2297 name: "ok, binds value",
2298 whenURL: "/search?param=999&param=998",
2299 expectValue: *example,
2300 },
2301 {
2302 name: "ok, params values empty, value is not changed",
2303 whenURL: "/search?nope=1",
2304 expectValue: big.Int{},
2305 },
2306 {
2307 name: "nok, previous errors fail fast without binding value",
2308 givenFailFast: true,
2309 whenURL: "/search?param=1&param=100",
2310 expectValue: big.Int{},
2311 expectError: "previous error",
2312 },
2313 {
2314 name: "nok, conversion fails, value is not changed",
2315 whenURL: "/search?param=nope&param=xxx",
2316 expectValue: big.Int{},
2317 expectError: "code=400, message=failed to bind field value to encoding.TextUnmarshaler interface, err=math/big: cannot unmarshal \"nope\" into a *big.Int, field=param",
2318 },
2319 {
2320 name: "ok (must), binds value",
2321 whenMust: true,
2322 whenURL: "/search?param=999&param=998",
2323 expectValue: *example,
2324 },
2325 {
2326 name: "ok (must), params values empty, returns error, value is not changed",
2327 whenMust: true,
2328 whenURL: "/search?nope=1",
2329 expectValue: big.Int{},
2330 expectError: "code=400, message=required field value is empty, field=param",
2331 },
2332 {
2333 name: "nok (must), previous errors fail fast without binding value",
2334 givenFailFast: true,
2335 whenMust: true,
2336 whenURL: "/search?param=1&param=xxx",
2337 expectValue: big.Int{},
2338 expectError: "previous error",
2339 },
2340 {
2341 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
MustTextUnmarshalerMethod · 0.80
TextUnmarshalerMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…