/usr/share/gocode/src/github.com/hanwen/go-fuse/zipfs/zipfs_test.go is in golang-github-hanwen-go-fuse-dev 0.0~git20171124.0.14c3015-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | // 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"
"path/filepath"
"runtime"
"syscall"
"testing"
"time"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/internal/testutil"
)
func testZipFile() string {
_, file, _, ok := runtime.Caller(0)
if !ok {
panic("need runtime.Caller()'s file name to discover testdata")
}
dir, _ := filepath.Split(file)
return filepath.Join(dir, "test.zip")
}
func setupZipfs(t *testing.T) (mountPoint string, cleanup func()) {
root, err := NewArchiveFileSystem(testZipFile())
if err != nil {
t.Fatalf("NewArchiveFileSystem failed: %v", err)
}
mountPoint = testutil.TempDir()
state, _, err := nodefs.MountRoot(mountPoint, root, &nodefs.Options{
Debug: testutil.VerboseTest(),
})
go state.Serve()
state.WaitMount()
return mountPoint, func() {
state.Unmount()
os.RemoveAll(mountPoint)
}
}
func TestZipFs(t *testing.T) {
mountPoint, clean := setupZipfs(t)
defer clean()
entries, err := ioutil.ReadDir(mountPoint)
if err != nil {
t.Fatalf("ReadDir failed: %v", err)
}
if len(entries) != 2 {
t.Error("wrong length", entries)
}
fi, err := os.Stat(mountPoint + "/subdir")
if err != nil {
t.Fatalf("Stat failed: %v", err)
}
if !fi.IsDir() {
t.Error("directory type", fi)
}
fi, err = os.Stat(mountPoint + "/file.txt")
if err != nil {
t.Fatalf("Stat failed: %v", err)
}
if fi.Mode() != 0664 {
t.Fatalf("File mode 0%o != 0664", fi.Mode())
}
if st := fi.Sys().(*syscall.Stat_t); st.Blocks != 1 {
t.Errorf("got block count %d, want 1", st.Blocks)
}
mtime, err := time.Parse(time.RFC3339, "2011-02-22T12:56:12Z")
if err != nil {
panic(err)
}
if !fi.ModTime().Equal(mtime) {
t.Fatalf("File mtime %v != %v", fi.ModTime(), mtime)
}
if fi.IsDir() {
t.Error("file type", fi)
}
f, err := os.Open(mountPoint + "/file.txt")
if err != nil {
t.Fatalf("Open failed: %v", err)
}
b := make([]byte, 1024)
n, err := f.Read(b)
b = b[:n]
if string(b) != "hello\n" {
t.Error("content fail", b[:n])
}
f.Close()
}
func TestLinkCount(t *testing.T) {
mp, clean := setupZipfs(t)
defer clean()
fi, err := os.Stat(mp + "/file.txt")
if err != nil {
t.Fatalf("Stat failed: %v", err)
}
if fuse.ToStatT(fi).Nlink != 1 {
t.Fatal("wrong link count", fuse.ToStatT(fi).Nlink)
}
}
|