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

Function TestSearchLocksVerifiableWithCache

locking/locks_test.go:193–312  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

191}
192
193func TestSearchLocksVerifiableWithCache(t *testing.T) {
194 var err error
195 tempDir := t.TempDir()
196
197 remoteQueries := 0
198 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
199 remoteQueries++
200
201 assert.Equal(t, "POST", r.Method)
202 assert.Equal(t, "/api/locks/verify", r.URL.Path)
203
204 body := lockVerifiableRequest{}
205 if assert.Nil(t, json.NewDecoder(r.Body).Decode(&body)) {
206 w.Header().Set("Content-Type", "application/json")
207 list := lockVerifiableList{}
208 if body.Cursor == "1" {
209 list.Ours = []Lock{
210 Lock{Path: "folder/1/test1.dat", Id: "111"},
211 }
212 list.Theirs = []Lock{
213 Lock{Path: "folder/1/test2.dat", Id: "112"},
214 Lock{Path: "folder/1/test3.dat", Id: "113"},
215 }
216 } else {
217 list.Ours = []Lock{
218 Lock{Path: "folder/0/test1.dat", Id: "101"},
219 Lock{Path: "folder/0/test2.dat", Id: "102"},
220 }
221 list.Theirs = []Lock{
222 Lock{Path: "folder/0/test3.dat", Id: "103"},
223 }
224 list.NextCursor = "1"
225 }
226
227 err := json.NewEncoder(w).Encode(&list)
228 assert.Nil(t, err)
229 } else {
230 w.WriteHeader(500)
231 }
232 }))
233
234 defer srv.Close()
235
236 lfsclient, err := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{
237 "lfs.url": srv.URL + "/api",
238 "user.name": "Fred",
239 "user.email": "fred@bloggs.com",
240 }))
241 require.Nil(t, err)
242
243 client, err := NewClient("", lfsclient, config.New())
244 assert.Nil(t, client.SetupFileCache(tempDir))
245
246 client.RemoteRef = &git.Ref{Name: "refs/heads/master"}
247 cacheFile, err := client.prepareCacheDirectory("verifiable")
248 assert.Nil(t, err)
249
250 // Cache file should not exist

Callers

nothing calls this directly

Calls 14

SetupFileCacheMethod · 0.95
prepareCacheDirectoryMethod · 0.95
SearchLocksVerifiableMethod · 0.95
NewClientFunction · 0.92
NewContextFunction · 0.92
NewFunction · 0.92
LocksByIdTypeAlias · 0.85
EncodeMethod · 0.80
SizeMethod · 0.80
NewClientFunction · 0.70
SetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected