2022-12-04 07:59:36 +00:00
|
|
|
package mfer
|
|
|
|
|
2022-12-04 09:19:21 +00:00
|
|
|
import (
|
2022-12-06 02:29:01 +00:00
|
|
|
"bytes"
|
2022-12-06 16:42:26 +00:00
|
|
|
"fmt"
|
2022-12-04 09:19:21 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-12-06 02:29:01 +00:00
|
|
|
"git.eeqj.de/sneak/mfer/internal/log"
|
2022-12-04 09:19:21 +00:00
|
|
|
"github.com/spf13/afero"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
2022-12-04 07:59:36 +00:00
|
|
|
|
|
|
|
// Add those variables as well
|
|
|
|
var (
|
2022-12-04 09:19:21 +00:00
|
|
|
existingFolder = "./testdata/a-folder-that-exists"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-12-06 16:42:26 +00:00
|
|
|
af *afero.Afero = &afero.Afero{Fs: afero.NewMemMapFs()}
|
|
|
|
big *afero.Afero = &afero.Afero{Fs: afero.NewMemMapFs()}
|
2022-12-04 07:59:36 +00:00
|
|
|
)
|
|
|
|
|
2022-12-04 09:19:21 +00:00
|
|
|
func init() {
|
2022-12-06 16:42:26 +00:00
|
|
|
log.EnableDebugLogging()
|
|
|
|
|
2022-12-04 09:19:21 +00:00
|
|
|
// create test files and directories
|
|
|
|
af.MkdirAll("/a/b/c", 0o755)
|
|
|
|
af.MkdirAll("/.hidden", 0o755)
|
2022-12-06 16:42:26 +00:00
|
|
|
af.WriteFile("/a/b/c/hello.txt", []byte("hello world\n\n\n\n"), 0o755)
|
|
|
|
af.WriteFile("/a/b/c/hello2.txt", []byte("hello world\n\n\n\n"), 0o755)
|
|
|
|
af.WriteFile("/.hidden/hello.txt", []byte("hello world\n"), 0o755)
|
|
|
|
af.WriteFile("/.hidden/hello2.txt", []byte("hello world\n"), 0o755)
|
|
|
|
|
|
|
|
big.MkdirAll("/home/user/Library", 0o755)
|
2022-12-08 18:25:30 +00:00
|
|
|
for i := range [25]int{} {
|
2022-12-06 16:42:26 +00:00
|
|
|
big.WriteFile(fmt.Sprintf("/home/user/Library/hello%d.txt", i), []byte("hello world\n"), 0o755)
|
|
|
|
}
|
2022-12-04 09:19:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPathHiddenFunc(t *testing.T) {
|
|
|
|
assert.False(t, pathIsHidden("/a/b/c/hello.txt"))
|
|
|
|
assert.True(t, pathIsHidden("/a/b/c/.hello.txt"))
|
|
|
|
assert.True(t, pathIsHidden("/a/.b/c/hello.txt"))
|
|
|
|
assert.True(t, pathIsHidden("/.a/b/c/hello.txt"))
|
|
|
|
assert.False(t, pathIsHidden("./a/b/c/hello.txt"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestManifestGenerationOne(t *testing.T) {
|
2022-12-05 22:59:08 +00:00
|
|
|
m, err := NewFromFS(&ManifestScanOptions{
|
2022-12-04 09:19:21 +00:00
|
|
|
IgnoreDotfiles: true,
|
2022-12-06 02:29:01 +00:00
|
|
|
}, af)
|
2022-12-04 09:19:21 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, m)
|
2022-12-06 13:43:07 +00:00
|
|
|
m.Scan()
|
2022-12-04 09:19:21 +00:00
|
|
|
assert.Equal(t, int64(2), m.GetFileCount())
|
|
|
|
assert.Equal(t, int64(30), m.GetTotalFileSize())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestManifestGenerationTwo(t *testing.T) {
|
2022-12-05 22:59:08 +00:00
|
|
|
m, err := NewFromFS(&ManifestScanOptions{
|
2022-12-04 09:19:21 +00:00
|
|
|
IgnoreDotfiles: false,
|
2022-12-06 02:29:01 +00:00
|
|
|
}, af)
|
2022-12-04 09:19:21 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, m)
|
2022-12-06 13:43:07 +00:00
|
|
|
m.Scan()
|
2022-12-04 09:19:21 +00:00
|
|
|
assert.Equal(t, int64(4), m.GetFileCount())
|
|
|
|
assert.Equal(t, int64(54), m.GetTotalFileSize())
|
2022-12-05 22:59:08 +00:00
|
|
|
err = m.generate()
|
|
|
|
assert.Nil(t, err)
|
2022-12-06 02:29:01 +00:00
|
|
|
var buf bytes.Buffer
|
|
|
|
err = m.WriteTo(&buf)
|
|
|
|
assert.Nil(t, err)
|
2022-12-06 13:43:07 +00:00
|
|
|
log.Dump(buf.Bytes())
|
2022-12-04 07:59:36 +00:00
|
|
|
}
|