Commit 6ff08620 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent bcb991a3
......@@ -22,24 +22,39 @@ package demo
import (
"bytes"
"context"
"io/ioutil"
"fmt"
"net/url"
"os"
"regexp"
"testing"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/neo/go/internal/xtesting"
"lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/zodb/zodbtools"
)
// DemoData represents data for a demo: storage.
type DemoData struct {
base string // path for base.fs
δ string // ----/---- δ.fs
}
func (ddat *DemoData) URL() string {
return fmt.Sprintf("demo:(%s)/(%s)", ddat.base, ddat.δ)
}
// tOptions represents options for testing.
// TODO -> xtesting
type tOptions struct {
Preload string // preload database with data from this location
}
// withDemoStorage tests f with all kind of demo overlays.
func withDemoStorage(t *testing.T, f func(t *testing.T, dsrv *Storage/*XXX -> Srv ?*/), optv ...tOptions) {
// withDemoData tests f with all kind of demo data splits.
func withDemoData(t *testing.T, f func(t *testing.T, ddat *DemoData), optv ...tOptions) {
t.Helper()
X := xtesting.FatalIf(t)
......@@ -89,14 +104,16 @@ func withDemoStorage(t *testing.T, f func(t *testing.T, dsrv *Storage/*XXX -> Sr
work1 := work + "/" + δstart.String()
err := os.Mkdir(work1, 0x777); X(err)
_, err = xtesting.ZPyRestore(work1+"/base.fs", zdumpBase); X(err)
base := work1+"/base.fs"
δ := work1+"/δ.fs"
_, err = xtesting.ZPyRestore(base, zdumpBase); X(err)
// XXX vvv change to demo:(base)/(δ)
// XXX + explain why (restoring copy without original present fails)
_, err = xtesting.ZPyRestore(work1+"/δ.fs", zdumpδ); X(err)
_, err = xtesting.ZPyRestore(δ, zdumpδ); X(err)
d = openDemo(base, δ); X(err)
defer d.Close()
f(t, d)
ddat := &DemoData{base, δ}
f(t, ddat)
})
}
for i := 0; i < len(txnv); i++ {
......@@ -106,10 +123,25 @@ func withDemoStorage(t *testing.T, f func(t *testing.T, dsrv *Storage/*XXX -> Sr
test1(zodb.TidMax, zdump, "")
}
// withDemo tests f with demo: client connected to all kind of demo data splits.
func withDemo(t *testing.T, f func(t *testing.T, ddat *DemoData, ddrv *Storage), optv ...tOptions) {
t.Helper()
withDemoData(t, func(t *testing.T, ddat *DemoData) {
t.Helper()
X := xtesting.FatalIf(t)
ddrv, _, err := demoOpen(ddat.URL(), &zodb.DriverOptions{ReadOnly: true}); X(err)
defer func() {
err := ddrv.Close(); X(err)
}()
f(t, ddat, ddrv)
}, optv...)
}
func TestEmptyDB(t *testing.T) {
withDemo(t, func(t *testing.T, dsrv ZEOSrv, d *Storage) {
xtesting.DrvTestEmptyDB(t, d)
withDemo(t, func(t *testing.T, _ *DemoData, ddrv *Storage) {
xtesting.DrvTestEmptyDB(t, ddrv)
})
}
......@@ -119,20 +151,35 @@ func TestLoad(t *testing.T) {
data := "../fs1/testdata/1.fs"
txnvOk, err := xtesting.LoadDBHistory(data); X(err)
withDemo(t, func(t *testing.T, zsrv ZEOSrv, d *Storage) {
xtesting.DrvTestLoad(t, d, txnvOk)
withDemo(t, func(t *testing.T, _ *DemoData, ddrv *Storage) {
xtesting.DrvTestLoad(t, ddrv, txnvOk)
}, tOptions{
Preload: data,
})
}
func TestWatch(t *testing.T) {
withDemoSrv(t, func(t *testing.T, dsrv DemoSrv) {
xtesting.DrvTestWatch(t, dsrv.URL(), openByURL)
withDemoData(t, func(t *testing.T, ddat *DemoData) {
xtesting.DrvTestWatch(t, ddat.URL(), openByURL)
})
}
func demoOpen(zurl string, opt *zodb.DriverOptions) (_ *Storage, at0 zodb.Tid, err error) {
defer xerr.Contextf(&err, "opendemo %s", zurl)
u, err := url.Parse(zurl)
if err != nil {
return nil, 0, err
}
d, at0, err := openByURL(context.Background(), u, opt)
if err != nil {
return nil, 0, err
}
return d.(*Storage), at0, nil
}
func xtempdir(t *testing.T) string {
t.Helper()
tmpd, err := ioutil.TempDir("", "demo")
......
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