init
This commit is contained in:
43
vfs_test.go
Normal file
43
vfs_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user