aboutsummaryrefslogtreecommitdiff
path: root/lib/memfs/memfs_test.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2021-01-09 02:31:36 +0700
committerShulhan <m.shulhan@gmail.com>2021-01-09 02:33:32 +0700
commit623450a25b14f24f448d660884a12f0030a1d87b (patch)
treeddaef5b9f1692cf51d1b1acb22d7d8a87f940630 /lib/memfs/memfs_test.go
parent2daf0d349a1224530f1915cb13ca8664a211150c (diff)
downloadpakakeh.go-623450a25b14f24f448d660884a12f0030a1d87b.tar.xz
memfs: allow AddFile to set internal path
Previously, AddFile set the internal path equal to path of file to be included. This may cause conflict if the file is already included due to the same sys path but different internal path. This commit add parameter internalPath to set custom internal path in the memfs map.
Diffstat (limited to 'lib/memfs/memfs_test.go')
-rw-r--r--lib/memfs/memfs_test.go58
1 files changed, 32 insertions, 26 deletions
diff --git a/lib/memfs/memfs_test.go b/lib/memfs/memfs_test.go
index f40212c0..e158a9ef 100644
--- a/lib/memfs/memfs_test.go
+++ b/lib/memfs/memfs_test.go
@@ -18,38 +18,42 @@ var (
func TestAddFile(t *testing.T) {
cases := []struct {
desc string
- path string
+ intPath string
+ extPath string
exp *Node
expError string
}{{
- desc: "With empty path",
+ desc: "With empty internal path",
}, {
- desc: "With path is not exist",
- path: "is/not/exist",
- expError: "memfs.AddFile: stat is: no such file or directory",
+ desc: "With external path is not exist",
+ intPath: "internal/file",
+ extPath: "is/not/exist",
+ expError: "memfs.AddFile: stat is/not/exist: no such file or directory",
}, {
- desc: "With file exist",
- path: "testdata/direct/add/file",
+ desc: "With file exist",
+ intPath: "internal/file",
+ extPath: "testdata/direct/add/file",
exp: &Node{
SysPath: "testdata/direct/add/file",
- Path: "testdata/direct/add/file",
+ Path: "internal/file",
name: "file",
ContentType: "text/plain; charset=utf-8",
size: 22,
V: []byte("Test direct add file.\n"),
- GenFuncName: "generate_testdata_direct_add_file",
+ GenFuncName: "generate_internal_file",
},
}, {
- desc: "With directories exist",
- path: "testdata/direct/add/file2",
+ desc: "With directories exist",
+ intPath: "internal/file2",
+ extPath: "testdata/direct/add/file2",
exp: &Node{
SysPath: "testdata/direct/add/file2",
- Path: "testdata/direct/add/file2",
+ Path: "internal/file2",
name: "file2",
ContentType: "text/plain; charset=utf-8",
size: 24,
V: []byte("Test direct add file 2.\n"),
- GenFuncName: "generate_testdata_direct_add_file2",
+ GenFuncName: "generate_internal_file2",
},
}}
@@ -64,7 +68,7 @@ func TestAddFile(t *testing.T) {
for _, c := range cases {
t.Log(c.desc)
- got, err := mfs.AddFile(c.path)
+ got, err := mfs.AddFile(c.intPath, c.extPath)
if err != nil {
test.Assert(t, "error", c.expError, err.Error(), true)
continue
@@ -79,21 +83,23 @@ func TestAddFile(t *testing.T) {
test.Assert(t, "AddFile", c.exp, got, true)
- if c.exp != nil {
- got, err := mfs.Get(c.path)
- if err != nil {
- t.Fatal(err)
- }
+ if c.exp == nil {
+ continue
+ }
- if got != nil {
- got.modTime = time.Time{}
- got.mode = 0
- got.Parent = nil
- got.Childs = nil
- }
+ got, err = mfs.Get(c.intPath)
+ if err != nil {
+ t.Fatal(err)
+ }
- test.Assert(t, "Get", c.exp, got, true)
+ if got != nil {
+ got.modTime = time.Time{}
+ got.mode = 0
+ got.Parent = nil
+ got.Childs = nil
}
+
+ test.Assert(t, "Get", c.exp, got, true)
}
}