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

.

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