示例#1
0
func testfn(t *testing.T, fn func(t fstest.Fataler, fss ...zx.Tree)) {
	fstest.Repeats = 1
	fs, err := mfs.New("example mfs")
	if err != nil {
		dbg.Fatal("lfs: %s", err)
	}
	xfs, _ := fs.AuthFor(&auth.Info{Uid: dbg.Usr, SpeaksFor: dbg.Usr, Ok: true})
	tr := New(xfs)
	tc := make(chan string)
	dc := make(chan bool)
	go func() {
		for x := range tc {
			printf("%s\n", x)
		}
		dc <- true
	}()
	fstest.MkZXTree(t, tr)
	fs.Dbg = testing.Verbose()
	if fs.Dbg {
		defer fs.Dump(os.Stdout)
	}
	tr.C = tc
	if fn != nil {
		fn(t, tr)
	}
	tr.Close(nil)
	close(tc)
	<-dc
}
示例#2
0
func testfn(t *testing.T, fns ...func(t fstest.Fataler, fss ...zx.Tree)) {
	bufs.Size = 1 * 1024
	os.RemoveAll(tlfsdir)
	defer os.RemoveAll(tlfsdir)
	if err := os.Mkdir(tlfsdir, 0755); err != nil {
		t.Fatalf("lfs: %s", err)
	}
	os.Args[0] = "mdfs_test"
	dfs, err := lfs.New("	cache", tlfsdir, lfs.RW)
	if err != nil {
		t.Fatalf("lfs: %s", err)
	}
	dfs.SaveAttrs(true)
	mfs, err := New("example mfs", dfs)
	if err != nil {
		t.Fatalf("lfs: %s", err)
	}
	xfs, _ := mfs.AuthFor(&auth.Info{Uid: dbg.Usr, SpeaksFor: dbg.Usr, Ok: true})
	fs := xfs.(zx.RWTree)
	fstest.MkZXTree(t, fs)
	mfs.Dbg = testing.Verbose()
	dfs.Dbg = testing.Verbose()
	var fn func(t fstest.Fataler, fss ...zx.Tree)
	if len(fns) > 0 {
		fn = fns[0]
	}
	if fn != nil {
		if mfs.Dbg {
			defer func() {
				mfs.Dump(os.Stdout)
				dfs.Dump(os.Stdout)
			}()
		}
		for _, fn := range fns {
			fn(t, fs)
		}
	} else {
		d1, _ := zx.Stat(mfs, "/")
		printf("mfs st:\t%s\n", d1)
		d1, _ = zx.Stat(dfs, "/")
		printf("lfs st:\t%s\n", d1)
		// recreate, to test a reload
		mfs, err = New("example mfs", dfs)
		if err != nil {
			t.Fatalf("lfs: %s", err)
		}
		mfs.Dbg = testing.Verbose()
		xfs, _ = mfs.AuthFor(&auth.Info{Uid: dbg.Usr, SpeaksFor: dbg.Usr, Ok: true})
		fs = xfs.(zx.RWTree)
		if mfs.Dbg {
			defer func() {
				mfs.Dump(os.Stdout)
				dfs.Dump(os.Stdout)
			}()
		}
	}
	mfs.Dbg = false
	dfs.Dbg = false
	fstest.SameDump(t, mfs, dfs)
}
示例#3
0
func mkmfstrees(t *testing.T) (zx.RWTree, zx.RWTree) {
	lfs1, err := mfs.New(tdir)
	if err != nil {
		t.Fatalf("mfs: %s", err)
	}
	fstest.MkZXTree(t, lfs1)
	d, err := zx.Stat(lfs1, "/")
	if err != nil {
		t.Fatalf("mfs: %s", err)
	}
	zx.RegisterProcTree(lfs1, d["tpath"])
	lfs1.Dbg = testing.Verbose() && moreverb
	return lfs1, lfs1
}
示例#4
0
func testfn(t *testing.T, fns ...func(t fstest.Fataler, fss ...zx.Tree)) {
	bufs.Size = 1 * 1024
	mfs, err := New("example mfs")
	if err != nil {
		t.Fatalf("lfs: %s", err)
	}
	xfs, _ := mfs.AuthFor(&auth.Info{Uid: dbg.Usr, SpeaksFor: dbg.Usr, Ok: true})
	fs := xfs.(zx.RWTree)
	fstest.MkZXTree(t, fs)
	mfs.Dbg = testing.Verbose()
	if mfs.Dbg {
		defer mfs.Dump(os.Stdout)
	}
	for _, fn := range fns {
		if fn != nil {
			fn(t, fs)
		}
	}
}
示例#5
0
func TestSendRecv(t *testing.T) {
	os.Args[0] = "mfs_test"
	fs1, err := New("example mfs1")
	if err != nil {
		t.Fatalf("lfs: %s", err)
	}
	fs1.Dbg = testing.Verbose()
	fstest.MkZXTree(t, fs1)
	fs2, err := New("example mfs2")
	if err != nil {
		t.Fatalf("lfs: %s", err)
	}
	if fs1.Dbg {
		defer fs2.Dump(os.Stdout)
		defer fs1.Dump(os.Stdout)
	}
	fstest.SendRecv(t, fs1, fs2)

}
示例#6
0
func TestSendRecv(t *testing.T) {
	t.Skip("TODO: this does not work but we are no longer sending trees")
	os.RemoveAll(tlfsdir + "2")
	os.RemoveAll(tlfsdir)
	if err := os.Mkdir(tlfsdir, 0755); err != nil {
		t.Fatalf("lfs: %s", err)
	}
	if err := os.Mkdir(tlfsdir+"2", 0755); err != nil {
		t.Fatalf("lfs: %s", err)
	}
	defer os.RemoveAll(tlfsdir + "2")
	defer os.RemoveAll(tlfsdir)
	os.Args[0] = "mdfs_test"

	dfs1, err := lfs.New("	cache1", tlfsdir, lfs.RW)
	if err != nil {
		t.Fatalf("lfs: %s", err)
	}
	dfs1.SaveAttrs(true)
	fs1, err := New("example mfs1", dfs1)
	if err != nil {
		t.Fatalf("mdfs: %s", err)
	}
	fs1.Dbg = testing.Verbose()

	fstest.MkZXTree(t, fs1)
	dfs2, err := lfs.New("	cache2", tlfsdir+"2", lfs.RW)
	if err != nil {
		t.Fatalf("lfs: %s", err)
	}
	dfs2.SaveAttrs(true)
	fs2, err := New("example mfs2", dfs2)
	if err != nil {
		t.Fatalf("mdfs: %s", err)
	}
	if fs1.Dbg {
		defer fs2.Dump(os.Stdout)
		defer fs1.Dump(os.Stdout)
	}
	fstest.SendRecv(t, fs1, fs2)

}