-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcache_test.go
40 lines (35 loc) · 903 Bytes
/
cache_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package ffcss
import (
"io/fs"
"os"
"os/exec"
"testing"
"github.com/stretchr/testify/assert"
)
func fillCache() {
exec.Command("cp", "-r", "testdata/home/.cache", "testarea/home")
LogDebug("filled mock cache")
}
func TestCleanDownloadArea(t *testing.T) {
fillCache()
initialCacheDir, _ := os.ReadDir(CacheDir())
expectedCacheDir := make([]fs.DirEntry, 0)
for _, dirEntry := range initialCacheDir {
if dirEntry.Name() != ".download" {
expectedCacheDir = append(expectedCacheDir, dirEntry)
}
}
err := CleanDownloadArea()
assert.NoError(t, err)
actualCacheDir, err := os.ReadDir(CacheDir())
assert.NoError(t, err)
assert.Equal(t, expectedCacheDir, actualCacheDir)
}
func TestClearWholeCache(t *testing.T) {
fillCache()
err := ClearWholeCache()
assert.NoError(t, err)
actual, err := os.ReadDir(CacheDir())
assert.NoError(t, err)
assert.Equal(t, []fs.DirEntry{}, actual)
}