/
niceSOFT
/
git-lfs
Обзор
Документация
Войти
/
niceSOFT
/
git-lfs
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
locking/cache_test.go
60 строк
1 KB
Eng Zer Jun
Replace deprecated `io/ioutil` functions
10 янв 2024, 22:48
Не верифицирован
10 янв 2024, 22:48
2ebe3ba
Код
Авторство
О чём код?
package locking import ( "os" "testing" "github.com/stretchr/testify/assert" ) func TestLockCache(t *testing.T) { var err error tmpf, err := os.CreateTemp("", "testCacheLock") assert.Nil(t, err) defer func() { os.Remove(tmpf.Name()) }() tmpf.Close() cache, err := NewLockCache(tmpf.Name()) assert.Nil(t, err) testLocks := []Lock{ Lock{Path: "folder/test1.dat", Id: "101"}, Lock{Path: "folder/test2.dat", Id: "102"}, Lock{Path: "root.dat", Id: "103"}, } for _, l := range testLocks { err = cache.Add(l) assert.Nil(t, err) } locks := cache.Locks() for _, l := range testLocks { assert.Contains(t, locks, l) } assert.Equal(t, len(testLocks), len(locks)) err = cache.RemoveByPath("folder/test2.dat") assert.Nil(t, err) locks = cache.Locks() // delete item 1 from test locls testLocks = append(testLocks[:1], testLocks[2:]...) for _, l := range testLocks { assert.Contains(t, locks, l) } assert.Equal(t, len(testLocks), len(locks)) err = cache.RemoveById("101") assert.Nil(t, err) locks = cache.Locks() testLocks = testLocks[1:] for _, l := range testLocks { assert.Contains(t, locks, l) } assert.Equal(t, len(testLocks), len(locks)) }