(t *testing.T)
| 1498 | } |
| 1499 | |
| 1500 | func TestValueBinder_Float64s(t *testing.T) { |
| 1501 | var testCases = []struct { |
| 1502 | name string |
| 1503 | whenURL string |
| 1504 | expectError string |
| 1505 | givenBindErrors []error |
| 1506 | expectValue []float64 |
| 1507 | givenFailFast bool |
| 1508 | whenMust bool |
| 1509 | }{ |
| 1510 | { |
| 1511 | name: "ok, binds value", |
| 1512 | whenURL: "/search?param=4.3¶m=0", |
| 1513 | expectValue: []float64{4.3, 0}, |
| 1514 | }, |
| 1515 | { |
| 1516 | name: "ok, params values empty, value is not changed", |
| 1517 | whenURL: "/search?nope=1", |
| 1518 | expectValue: []float64(nil), |
| 1519 | }, |
| 1520 | { |
| 1521 | name: "nok, previous errors fail fast without binding value", |
| 1522 | givenFailFast: true, |
| 1523 | givenBindErrors: []error{errors.New("previous error")}, |
| 1524 | whenURL: "/search?param=1¶m=100", |
| 1525 | expectValue: []float64(nil), |
| 1526 | expectError: "previous error", |
| 1527 | }, |
| 1528 | { |
| 1529 | name: "nok, conversion fails, value is not changed", |
| 1530 | whenURL: "/search?param=nope¶m=100", |
| 1531 | expectValue: []float64(nil), |
| 1532 | expectError: "code=400, message=failed to bind field value to float64, err=strconv.ParseFloat: parsing \"nope\": invalid syntax, field=param", |
| 1533 | }, |
| 1534 | { |
| 1535 | name: "nok, conversion fails fast, value is not changed", |
| 1536 | givenFailFast: true, |
| 1537 | whenURL: "/search?param=0¶m=nope¶m=100", |
| 1538 | expectValue: []float64(nil), |
| 1539 | expectError: "code=400, message=failed to bind field value to float64, err=strconv.ParseFloat: parsing \"nope\": invalid syntax, field=param", |
| 1540 | }, |
| 1541 | { |
| 1542 | name: "ok (must), binds value", |
| 1543 | whenMust: true, |
| 1544 | whenURL: "/search?param=4.3¶m=0", |
| 1545 | expectValue: []float64{4.3, 0}, |
| 1546 | }, |
| 1547 | { |
| 1548 | name: "ok (must), params values empty, returns error, value is not changed", |
| 1549 | whenMust: true, |
| 1550 | whenURL: "/search?nope=1", |
| 1551 | expectValue: []float64(nil), |
| 1552 | expectError: "code=400, message=required field value is empty, field=param", |
| 1553 | }, |
| 1554 | { |
| 1555 | name: "nok (must), previous errors fail fast without binding value", |
| 1556 | givenFailFast: true, |
| 1557 | givenBindErrors: []error{errors.New("previous error")}, |
nothing calls this directly
no test coverage detected
searching dependent graphs…