(t *testing.T)
| 88 | } |
| 89 | |
| 90 | func TestQueryParamsBinder_FailFast(t *testing.T) { |
| 91 | var testCases = []struct { |
| 92 | name string |
| 93 | whenURL string |
| 94 | expectError []string |
| 95 | givenFailFast bool |
| 96 | }{ |
| 97 | { |
| 98 | name: "ok, FailFast=true stops at first error", |
| 99 | whenURL: "/api/user/999?nr=en&id=nope", |
| 100 | givenFailFast: true, |
| 101 | expectError: []string{ |
| 102 | `code=400, message=failed to bind field value to int64, err=strconv.ParseInt: parsing "nope": invalid syntax, field=id`, |
| 103 | }, |
| 104 | }, |
| 105 | { |
| 106 | name: "ok, FailFast=false encounters all errors", |
| 107 | whenURL: "/api/user/999?nr=en&id=nope", |
| 108 | givenFailFast: false, |
| 109 | expectError: []string{ |
| 110 | `code=400, message=failed to bind field value to int64, err=strconv.ParseInt: parsing "nope": invalid syntax, field=id`, |
| 111 | `code=400, message=failed to bind field value to int64, err=strconv.ParseInt: parsing "en": invalid syntax, field=nr`, |
| 112 | }, |
| 113 | }, |
| 114 | } |
| 115 | |
| 116 | for _, tc := range testCases { |
| 117 | t.Run(tc.name, func(t *testing.T) { |
| 118 | c := createTestContext(tc.whenURL, nil, map[string]string{"id": "999"}) |
| 119 | b := QueryParamsBinder(c).FailFast(tc.givenFailFast) |
| 120 | id := int64(99) |
| 121 | nr := int64(88) |
| 122 | errs := b.Int64("id", &id). |
| 123 | Int64("nr", &nr). |
| 124 | BindErrors() |
| 125 | |
| 126 | assert.Len(t, errs, len(tc.expectError)) |
| 127 | for _, err := range errs { |
| 128 | assert.Contains(t, tc.expectError, err.Error()) |
| 129 | } |
| 130 | }) |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | func TestFormFieldBinder(t *testing.T) { |
| 135 | e := New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…