(t *testing.T)
| 1224 | } |
| 1225 | |
| 1226 | func TestValueBinder_Bool(t *testing.T) { |
| 1227 | var testCases = []struct { |
| 1228 | name string |
| 1229 | whenURL string |
| 1230 | expectError string |
| 1231 | givenBindErrors []error |
| 1232 | givenFailFast bool |
| 1233 | whenMust bool |
| 1234 | expectValue bool |
| 1235 | }{ |
| 1236 | { |
| 1237 | name: "ok, binds value", |
| 1238 | whenURL: "/search?param=true¶m=1", |
| 1239 | expectValue: true, |
| 1240 | }, |
| 1241 | { |
| 1242 | name: "ok, params values empty, value is not changed", |
| 1243 | whenURL: "/search?nope=1", |
| 1244 | expectValue: false, |
| 1245 | }, |
| 1246 | { |
| 1247 | name: "nok, previous errors fail fast without binding value", |
| 1248 | givenFailFast: true, |
| 1249 | whenURL: "/search?param=1¶m=100", |
| 1250 | expectValue: false, |
| 1251 | expectError: "previous error", |
| 1252 | }, |
| 1253 | { |
| 1254 | name: "nok, conversion fails, value is not changed", |
| 1255 | whenURL: "/search?param=nope¶m=100", |
| 1256 | expectValue: false, |
| 1257 | expectError: "code=400, message=failed to bind field value to bool, err=strconv.ParseBool: parsing \"nope\": invalid syntax, field=param", |
| 1258 | }, |
| 1259 | { |
| 1260 | name: "ok (must), binds value", |
| 1261 | whenMust: true, |
| 1262 | whenURL: "/search?param=1¶m=100", |
| 1263 | expectValue: true, |
| 1264 | }, |
| 1265 | { |
| 1266 | name: "ok (must), params values empty, returns error, value is not changed", |
| 1267 | whenMust: true, |
| 1268 | whenURL: "/search?nope=1", |
| 1269 | expectValue: false, |
| 1270 | expectError: "code=400, message=required field value is empty, field=param", |
| 1271 | }, |
| 1272 | { |
| 1273 | name: "nok (must), previous errors fail fast without binding value", |
| 1274 | givenFailFast: true, |
| 1275 | whenMust: true, |
| 1276 | whenURL: "/search?param=1¶m=100", |
| 1277 | expectValue: false, |
| 1278 | expectError: "previous error", |
| 1279 | }, |
| 1280 | { |
| 1281 | name: "nok (must), conversion fails, value is not changed", |
| 1282 | whenMust: true, |
| 1283 | whenURL: "/search?param=nope¶m=100", |
nothing calls this directly
no test coverage detected
searching dependent graphs…