This commit is contained in:
2023-07-27 15:33:43 -07:00
commit bf3d3db898
9 changed files with 478 additions and 0 deletions

43
vfs_test.go Normal file
View File

@@ -0,0 +1,43 @@
package vfs
import (
"github.com/stretchr/testify/assert"
"io"
"os"
"path"
"testing"
)
func TestVFS_Basic(t *testing.T) {
testcases := []struct {
name string
dirPath string
fileName string
content []byte
mode os.FileMode
}{
{"Simple Root", ".", "test.txt", []byte("some content"), 0666},
{"One Layer Path", "folder", "test.txt", []byte("some content"), 0666},
{"Multi-Layer Path", "folder/folder2/dang", "test.txt", []byte("some content"), 0666},
}
for _, testcase := range testcases {
vfs := NewVFS()
fullPath := path.Join(testcase.dirPath, testcase.fileName)
err := vfs.MkdirAll(testcase.dirPath, 0777)
assert.NoError(t, err)
err = vfs.WriteFile(fullPath, testcase.content, testcase.mode)
assert.NoError(t, err)
fp, err := vfs.Open(fullPath)
assert.NoError(t, err)
content, err := io.ReadAll(fp)
assert.NoError(t, err)
assert.Equal(t, content, testcase.content)
err = fp.Close()
assert.NoError(t, err)
}
}