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

Function TestRemoteLocksWithCache

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

Source from the content-addressed store, hash-verified

24func (a LocksById) Less(i, j int) bool { return a[i].Id < a[j].Id }
25
26func TestRemoteLocksWithCache(t *testing.T) {
27 var err error
28 tempDir := t.TempDir()
29
30 remoteQueries := 0
31 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
32 remoteQueries++
33
34 assert.Equal(t, "GET", r.Method)
35 assert.Equal(t, "/api/locks", r.URL.Path)
36
37 w.Header().Set("Content-Type", "application/json")
38 err = json.NewEncoder(w).Encode(&lockList{
39 Locks: []Lock{
40 Lock{Id: "100", Path: "folder/test1.dat", Owner: &User{Name: "Alice"}},
41 Lock{Id: "101", Path: "folder/test2.dat", Owner: &User{Name: "Charles"}},
42 Lock{Id: "102", Path: "folder/test3.dat", Owner: &User{Name: "Fred"}},
43 },
44 })
45 assert.Nil(t, err)
46 }))
47
48 defer func() {
49 srv.Close()
50 }()
51
52 lfsclient, err := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{
53 "lfs.url": srv.URL + "/api",
54 "user.name": "Fred",
55 "user.email": "fred@bloggs.com",
56 }))
57 require.Nil(t, err)
58
59 client, err := NewClient("", lfsclient, config.New())
60 assert.Nil(t, err)
61 assert.Nil(t, client.SetupFileCache(tempDir))
62
63 client.RemoteRef = &git.Ref{Name: "refs/heads/master"}
64 cacheFile, err := client.prepareCacheDirectory("remote")
65 assert.Nil(t, err)
66
67 // Cache file should not exist
68 fi, err := os.Stat(cacheFile)
69 assert.True(t, os.IsNotExist(err))
70
71 // Querying non-existing cache file will report nothing
72 locks, err := client.SearchLocks(nil, 0, false, true)
73 assert.NotNil(t, err)
74 assert.Empty(t, locks)
75 assert.Equal(t, 0, remoteQueries)
76
77 // Need to include zero time in structure for equal to work
78 zeroTime := time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)
79
80 // REMOTE QUERY: No cache file will be created when querying with a filter
81 locks, err = client.SearchLocks(map[string]string{
82 "key": "value",
83 }, 0, false, false)

Callers

nothing calls this directly

Calls 14

SetupFileCacheMethod · 0.95
prepareCacheDirectoryMethod · 0.95
SearchLocksMethod · 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