(t *testing.T)
| 172 | } |
| 173 | |
| 174 | func TestAPISearchVerifiable(t *testing.T) { |
| 175 | require.NotNil(t, verifyResSchema) |
| 176 | |
| 177 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 178 | if r.URL.Path != "/api/locks/verify" { |
| 179 | w.WriteHeader(404) |
| 180 | return |
| 181 | } |
| 182 | |
| 183 | assert.Equal(t, "POST", r.Method) |
| 184 | assert.Equal(t, lfshttp.MediaType, r.Header.Get("Accept")) |
| 185 | assert.Equal(t, lfshttp.RequestContentType, r.Header.Get("Content-Type")) |
| 186 | |
| 187 | body := lockVerifiableRequest{} |
| 188 | if assert.Nil(t, json.NewDecoder(r.Body).Decode(&body)) { |
| 189 | assert.Equal(t, "cursor", body.Cursor) |
| 190 | assert.Equal(t, 5, body.Limit) |
| 191 | } |
| 192 | |
| 193 | w.Header().Set("Content-Type", "application/json") |
| 194 | resLoader, resWriter := gojsonschema.NewWriterLoader(w) |
| 195 | err := json.NewEncoder(resWriter).Encode(&lockVerifiableList{ |
| 196 | Ours: []Lock{ |
| 197 | {Id: "1"}, |
| 198 | {Id: "2"}, |
| 199 | }, |
| 200 | Theirs: []Lock{ |
| 201 | {Id: "3"}, |
| 202 | }, |
| 203 | }) |
| 204 | assert.Nil(t, err) |
| 205 | assertSchema(t, verifyResSchema, resLoader) |
| 206 | })) |
| 207 | defer srv.Close() |
| 208 | |
| 209 | c, err := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{ |
| 210 | "lfs.url": srv.URL + "/api", |
| 211 | })) |
| 212 | require.Nil(t, err) |
| 213 | |
| 214 | lc := &httpLockClient{Client: c} |
| 215 | locks, status, err := lc.SearchVerifiable("", &lockVerifiableRequest{ |
| 216 | Cursor: "cursor", |
| 217 | Limit: 5, |
| 218 | }) |
| 219 | require.Nil(t, err) |
| 220 | assert.Equal(t, 200, status) |
| 221 | assert.Equal(t, 2, len(locks.Ours)) |
| 222 | assert.Equal(t, "1", locks.Ours[0].Id) |
| 223 | assert.Equal(t, "2", locks.Ours[1].Id) |
| 224 | assert.Equal(t, 1, len(locks.Theirs)) |
| 225 | assert.Equal(t, "3", locks.Theirs[0].Id) |
| 226 | } |
| 227 | |
| 228 | var ( |
| 229 | createReqSchema *sourcedSchema |
nothing calls this directly
no test coverage detected