(t *testing.T)
| 2191 | } |
| 2192 | |
| 2193 | func 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¶m=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¶m=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¶m=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¶m=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¶m=xxx", |
| 2246 | expectValue: big.Int{}, |
| 2247 | expectError: "previous error", |
| 2248 | }, |
| 2249 | { |
| 2250 | name: "nok (must), conversion fails, value is not changed", |
nothing calls this directly
no test coverage detected
searching dependent graphs…