59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package mfer
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/davecgh/go-spew/spew"
|
|
"github.com/spf13/afero"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// Add those variables as well
|
|
var (
|
|
existingFolder = "./testdata/a-folder-that-exists"
|
|
)
|
|
|
|
var (
|
|
mf afero.Fs = afero.NewMemMapFs()
|
|
af *afero.Afero = &afero.Afero{Fs: mf}
|
|
)
|
|
|
|
func init() {
|
|
// create test files and directories
|
|
af.MkdirAll("/a/b/c", 0o755)
|
|
af.MkdirAll("/.hidden", 0o755)
|
|
afero.WriteFile(af, "/a/b/c/hello.txt", []byte("hello world\n\n\n\n"), 0o755)
|
|
afero.WriteFile(af, "/a/b/c/hello2.txt", []byte("hello world\n\n\n\n"), 0o755)
|
|
afero.WriteFile(af, "/.hidden/hello.txt", []byte("hello world\n"), 0o755)
|
|
afero.WriteFile(af, "/.hidden/hello2.txt", []byte("hello world\n"), 0o755)
|
|
}
|
|
|
|
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) {
|
|
m, err := NewFromFS(mf, &ManifestScanOptions{
|
|
IgnoreDotfiles: true,
|
|
})
|
|
assert.Nil(t, err)
|
|
assert.NotNil(t, m)
|
|
assert.Equal(t, int64(2), m.GetFileCount())
|
|
assert.Equal(t, int64(30), m.GetTotalFileSize())
|
|
}
|
|
|
|
func TestManifestGenerationTwo(t *testing.T) {
|
|
m, err := NewFromFS(mf, &ManifestScanOptions{
|
|
IgnoreDotfiles: false,
|
|
})
|
|
assert.Nil(t, err)
|
|
assert.NotNil(t, m)
|
|
spew.Dump(m)
|
|
assert.Equal(t, int64(4), m.GetFileCount())
|
|
assert.Equal(t, int64(54), m.GetTotalFileSize())
|
|
}
|