MCPcopy
hub / github.com/git-lfs/git-lfs / TestAPISearchVerifiable

Function TestAPISearchVerifiable

locking/api_test.go:174–226  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

172}
173
174func 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
228var (
229 createReqSchema *sourcedSchema

Callers

nothing calls this directly

Calls 9

SearchVerifiableMethod · 0.95
NewClientFunction · 0.92
NewContextFunction · 0.92
EncodeMethod · 0.80
assertSchemaFunction · 0.70
GetMethod · 0.65
SetMethod · 0.65
CloseMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected