(t *testing.T)
| 132 | } |
| 133 | |
| 134 | func TestFormFieldBinder(t *testing.T) { |
| 135 | e := New() |
| 136 | body := `texta=foo&slice=5` |
| 137 | req := httptest.NewRequest(http.MethodPost, "/api/search?id=1&nr=2&slice=3&slice=4", strings.NewReader(body)) |
| 138 | req.Header.Set(HeaderContentLength, strconv.Itoa(len(body))) |
| 139 | req.Header.Set(HeaderContentType, MIMEApplicationForm) |
| 140 | |
| 141 | rec := httptest.NewRecorder() |
| 142 | c := e.NewContext(req, rec) |
| 143 | |
| 144 | b := FormFieldBinder(c) |
| 145 | |
| 146 | var texta string |
| 147 | id := int64(99) |
| 148 | nr := int64(88) |
| 149 | var slice = make([]int64, 0) |
| 150 | var notExisting = make([]int64, 0) |
| 151 | err := b. |
| 152 | Int64s("slice", &slice). |
| 153 | Int64("id", &id). |
| 154 | Int64("nr", &nr). |
| 155 | String("texta", &texta). |
| 156 | Int64s("notExisting", ¬Existing). |
| 157 | BindError() |
| 158 | |
| 159 | assert.NoError(t, err) |
| 160 | assert.Equal(t, "foo", texta) |
| 161 | assert.Equal(t, int64(1), id) |
| 162 | assert.Equal(t, int64(2), nr) |
| 163 | assert.Equal(t, []int64{5, 3, 4}, slice) |
| 164 | assert.Equal(t, []int64{}, notExisting) |
| 165 | } |
| 166 | |
| 167 | func TestValueBinder_errorStopsBinding(t *testing.T) { |
| 168 | // this test documents "feature" that binding multiple params can change destination if it was bound before |
nothing calls this directly
no test coverage detected
searching dependent graphs…