1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package zipfs
import (
"io/ioutil"
"os"
"testing"
"time"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
"github.com/hanwen/go-fuse/v2/internal/testutil"
)
const testTtl = 100 * time.Millisecond
func setupMzfs(t *testing.T) (mountPoint string, state *fuse.Server, cleanup func()) {
root := &MultiZipFs{}
mountPoint = testutil.TempDir()
dt := testTtl
opts := &fs.Options{
EntryTimeout: &dt,
AttrTimeout: &dt,
}
opts.Debug = testutil.VerboseTest()
server, err := fs.Mount(mountPoint, root, opts)
if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
return mountPoint, server, func() {
server.Unmount()
os.RemoveAll(mountPoint)
}
}
func TestMultiZipReadonly(t *testing.T) {
mountPoint, _, cleanup := setupMzfs(t)
defer cleanup()
_, err := os.Create(mountPoint + "/random")
if err == nil {
t.Error("Must fail writing in root.")
}
_, err = os.OpenFile(mountPoint+"/config/zipmount", os.O_WRONLY, 0)
if err == nil {
t.Error("Must fail without O_CREATE")
}
}
func TestMultiZipFs(t *testing.T) {
mountPoint, server, cleanup := setupMzfs(t)
defer cleanup()
zipFile := testZipFile()
entries, err := ioutil.ReadDir(mountPoint)
if err != nil {
t.Fatalf("ReadDir failed: %v", err)
}
if len(entries) != 1 || string(entries[0].Name()) != "config" {
t.Errorf("wrong names return. %v", entries)
}
err = os.Symlink(zipFile, mountPoint+"/config/zipmount")
if err != nil {
t.Fatalf("Symlink failed: %v", err)
}
fi, err := os.Lstat(mountPoint + "/zipmount")
if !fi.IsDir() {
t.Errorf("Expect directory at /zipmount")
}
entries, err = ioutil.ReadDir(mountPoint)
if err != nil {
t.Fatalf("ReadDir failed: %v", err)
}
if len(entries) != 2 {
t.Error("Expect 2 entries", entries)
}
val, err := os.Readlink(mountPoint + "/config/zipmount")
if err != nil {
t.Fatalf("Readlink failed: %v", err)
}
if val != zipFile {
t.Errorf("expected %v got %v", zipFile, val)
}
fi, err = os.Lstat(mountPoint + "/zipmount")
if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
if !fi.IsDir() {
t.Fatalf("expect directory for /zipmount, got %v", fi)
}
// Check that zipfs itself works.
fi, err = os.Stat(mountPoint + "/zipmount/subdir")
if err != nil {
t.Fatalf("Stat failed: %v", err)
}
if !fi.IsDir() {
t.Error("directory type", fi)
}
// Removing the config dir unmount
err = os.Remove(mountPoint + "/config/zipmount")
if err != nil {
t.Fatalf("Remove failed: %v", err)
}
// If FUSE supports invalid inode notifications we expect this node to be gone. Otherwise we'll just make sure that it's not reachable.
if server.KernelSettings().SupportsNotify(fuse.NOTIFY_INVAL_INODE) {
fi, err = os.Stat(mountPoint + "/zipmount")
if err == nil {
t.Errorf("stat should fail after unmount, got %#v", fi)
}
} else {
entries, err = ioutil.ReadDir(mountPoint)
if err != nil {
t.Fatalf("ReadDir failed: %v", err)
}
for _, e := range entries {
if e.Name() == "zipmount" {
t.Error("Should not have entry: ", e)
}
}
}
}
|