tractor.dev/toolkit-go@v0.0.0-20241010005851-214d91207d07/engine/fs/mountfs/mountfs_test.go (about) 1 package mountfs 2 3 import ( 4 "testing" 5 6 "tractor.dev/toolkit-go/engine/fs/fstest" 7 "tractor.dev/toolkit-go/engine/fs/memfs" 8 ) 9 10 func TestMountFS(t *testing.T) { 11 base := memfs.New() 12 mount := memfs.New() 13 14 fstest.WriteFS(t, base, map[string]string{ 15 "basefile": "basefile", 16 "mount/file": "basefile", 17 "mount/basefile": "basefile", 18 }) 19 20 fstest.WriteFS(t, mount, map[string]string{ 21 "sub/file": "mountfile", 22 "file": "mountfile", 23 }) 24 25 fsys := New(base, "mount", mount) 26 27 fstest.CheckFS(t, fsys, map[string]string{ 28 "basefile": "basefile", 29 "mount/file": "mountfile", 30 "mount/sub/file": "mountfile", 31 }) 32 33 } 34 35 func TestMountFSUnionRoot(t *testing.T) { 36 base := memfs.New() 37 mnt := memfs.New() 38 39 fstest.WriteFS(t, base, map[string]string{ 40 "basefile": "basefile", 41 "bothfile": "basefile", 42 }) 43 44 fstest.WriteFS(t, mnt, map[string]string{ 45 "bothfile": "mountfile", 46 "mountfile": "mountfile", 47 }) 48 49 fsys := New(base, "", mnt, Union()) 50 51 fstest.CheckFS(t, fsys, map[string]string{ 52 "basefile": "basefile", 53 "bothfile": "mountfile", 54 "mountfile": "mountfile", 55 }) 56 57 } 58 59 func TestMountFSUnionSub(t *testing.T) { 60 base := memfs.New() 61 mnt := memfs.New() 62 63 fstest.WriteFS(t, base, map[string]string{ 64 "sub/basefile": "basefile", 65 "sub/bothfile": "basefile", 66 }) 67 68 fstest.WriteFS(t, mnt, map[string]string{ 69 "bothfile": "mountfile", 70 "mountfile": "mountfile", 71 }) 72 73 fsys := New(base, "sub", mnt, Union()) 74 75 fstest.CheckFS(t, fsys, map[string]string{ 76 "sub/basefile": "basefile", 77 "sub/bothfile": "mountfile", 78 "sub/mountfile": "mountfile", 79 }) 80 81 }