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

Function TestLockCache

locking/cache_test.go:10–60  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestLockCache(t *testing.T) {
11 var err error
12
13 tmpf, err := os.CreateTemp("", "testCacheLock")
14 assert.Nil(t, err)
15 defer func() {
16 os.Remove(tmpf.Name())
17 }()
18 tmpf.Close()
19
20 cache, err := NewLockCache(tmpf.Name())
21 assert.Nil(t, err)
22
23 testLocks := []Lock{
24 Lock{Path: "folder/test1.dat", Id: "101"},
25 Lock{Path: "folder/test2.dat", Id: "102"},
26 Lock{Path: "root.dat", Id: "103"},
27 }
28
29 for _, l := range testLocks {
30 err = cache.Add(l)
31 assert.Nil(t, err)
32 }
33
34 locks := cache.Locks()
35 for _, l := range testLocks {
36 assert.Contains(t, locks, l)
37 }
38 assert.Equal(t, len(testLocks), len(locks))
39
40 err = cache.RemoveByPath("folder/test2.dat")
41 assert.Nil(t, err)
42
43 locks = cache.Locks()
44 // delete item 1 from test locls
45 testLocks = append(testLocks[:1], testLocks[2:]...)
46 for _, l := range testLocks {
47 assert.Contains(t, locks, l)
48 }
49 assert.Equal(t, len(testLocks), len(locks))
50
51 err = cache.RemoveById("101")
52 assert.Nil(t, err)
53
54 locks = cache.Locks()
55 testLocks = testLocks[1:]
56 for _, l := range testLocks {
57 assert.Contains(t, locks, l)
58 }
59 assert.Equal(t, len(testLocks), len(locks))
60}

Callers

nothing calls this directly

Calls 10

AddMethod · 0.95
LocksMethod · 0.95
RemoveByPathMethod · 0.95
RemoveByIdMethod · 0.95
NewLockCacheFunction · 0.85
NameMethod · 0.65
CloseMethod · 0.65
ContainsMethod · 0.65
RemoveMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected