(t *testing.T)
| 2282 | } |
| 2283 | |
| 2284 | func 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¶m=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¶m=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¶m=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¶m=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¶m=xxx", |
| 2337 | expectValue: big.Int{}, |
| 2338 | expectError: "previous error", |
| 2339 | }, |
| 2340 | { |
| 2341 | name: "nok (must), conversion fails, value is not changed", |
nothing calls this directly
no test coverage detected
searching dependent graphs…