(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func 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 | } |
nothing calls this directly
no test coverage detected