Commit 0901f06b authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Add test for zipfs.

parent 7c3c1e41
package examplelib
import (
"github.com/hanwen/go-fuse/fuse"
"os"
"testing"
"fmt"
)
func CheckSuccess(e os.Error) {
if e != nil {
panic(fmt.Sprintf("Unexpected error: %v", e))
}
}
func TestZipFs(t *testing.T) {
wd, err := os.Getwd()
CheckSuccess(err)
zfs := NewZipFileFuse(wd + "/test.zip")
connector := fuse.NewPathFileSystemConnector(zfs)
mountPoint := fuse.MakeTempDir()
state := fuse.NewMountState(connector)
state.Mount(mountPoint)
go state.Loop(false)
d, err := os.Open(mountPoint, os.O_RDONLY, 0)
CheckSuccess(err)
names, err := d.Readdirnames(-1)
CheckSuccess(err)
err = d.Close()
CheckSuccess(err)
if len(names) != 2 {
t.Error("wrong length", names)
}
fi, err := os.Stat(mountPoint + "/subdir")
CheckSuccess(err)
if !fi.IsDirectory() {
t.Error("directory type", fi)
}
fi, err = os.Stat(mountPoint + "/file.txt")
CheckSuccess(err)
if !fi.IsRegular() {
t.Error("file type", fi)
}
f, err := os.Open(mountPoint + "/file.txt", os.O_RDONLY, 0)
CheckSuccess(err)
b := make([]byte, 1024)
n, err := f.Read(b)
b = b[:n]
if string(b[:n]) != "hello\n" {
t.Error("content fail", b[:n])
}
f.Close()
state.Unmount()
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment