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

Function TestRefreshCache

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

Source from the content-addressed store, hash-verified

128}
129
130func TestRefreshCache(t *testing.T) {
131 var err error
132 tempDir := t.TempDir()
133
134 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
135 assert.Equal(t, "POST", r.Method)
136 assert.Equal(t, "/api/locks/verify", r.URL.Path)
137
138 w.Header().Set("Content-Type", "application/json")
139 err = json.NewEncoder(w).Encode(lockVerifiableList{
140 Theirs: []Lock{
141 Lock{Id: "99", Path: "folder/test3.dat", Owner: &User{Name: "Alice"}},
142 Lock{Id: "199", Path: "other/test1.dat", Owner: &User{Name: "Charles"}},
143 },
144 Ours: []Lock{
145 Lock{Id: "101", Path: "folder/test1.dat", Owner: &User{Name: "Fred"}},
146 Lock{Id: "102", Path: "folder/test2.dat", Owner: &User{Name: "Fred"}},
147 Lock{Id: "103", Path: "root.dat", Owner: &User{Name: "Fred"}},
148 },
149 })
150 assert.Nil(t, err)
151 }))
152
153 defer func() {
154 srv.Close()
155 }()
156
157 lfsclient, err := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{
158 "lfs.url": srv.URL + "/api",
159 "user.name": "Fred",
160 "user.email": "fred@bloggs.com",
161 }))
162 require.Nil(t, err)
163
164 client, err := NewClient("", lfsclient, config.New())
165 assert.Nil(t, err)
166 assert.Nil(t, client.SetupFileCache(tempDir))
167
168 // Should start with no cached items
169 locks, err := client.SearchLocks(nil, 0, true, false)
170 assert.Nil(t, err)
171 assert.Empty(t, locks)
172
173 client.RemoteRef = &git.Ref{Name: "refs/heads/master"}
174 _, _, err = client.SearchLocksVerifiable(100, false)
175 assert.Nil(t, err)
176
177 locks, err = client.SearchLocks(nil, 0, true, false)
178 assert.Nil(t, err)
179 // Need to include zero time in structure for equal to work
180 zeroTime := time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)
181
182 // Sort locks for stable comparison
183 sort.Sort(LocksById(locks))
184 assert.Equal(t, []Lock{
185 Lock{Path: "folder/test1.dat", Id: "101", Owner: &User{Name: "Fred"}, LockedAt: zeroTime},
186 Lock{Path: "folder/test2.dat", Id: "102", Owner: &User{Name: "Fred"}, LockedAt: zeroTime},
187 Lock{Path: "root.dat", Id: "103", Owner: &User{Name: "Fred"}, LockedAt: zeroTime},

Callers

nothing calls this directly

Calls 13

SetupFileCacheMethod · 0.95
SearchLocksMethod · 0.95
SearchLocksVerifiableMethod · 0.95
NewClientFunction · 0.92
NewContextFunction · 0.92
NewFunction · 0.92
LocksByIdTypeAlias · 0.85
EncodeMethod · 0.80
NewClientFunction · 0.70
SetMethod · 0.65
CloseMethod · 0.65
TempDirMethod · 0.45

Tested by

no test coverage detected