Commit 557a3b96 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 4ca61cd7
......@@ -150,11 +150,11 @@ type Txn struct {
Data []*zodb.DataInfo
}
// LoadDB loads whole content of a ZODB database.
// LoadDBHistory loads whole content of a ZODB database.
//
// it returns full history of all transactions with committed data.
func LoadDB(zurl string) (_ []Txn, err error) {
xerr.Contextf(&err, "loaddb %s", zurl)
func LoadDBHistory(zurl string) (_ []Txn, err error) {
xerr.Contextf(&err, "loadDBHistory %s", zurl)
ctx := context.Background()
zstor, err := zodb.Open(ctx, zurl, &zodb.OpenOptions{ReadOnly: true})
if err != nil {
......@@ -300,11 +300,7 @@ func DrvTestLoad(t *testing.T, zdrv zodb.IStorageDriver, txnvOk []Txn) {
// DrvTestWatch verifies that storage driver watcher can observe commits done from outside.
func DrvTestWatch(t *testing.T, zurl string, zdrvOpen zodb.DriverOpener) {
t.Helper()
X := func(err error) {
if err != nil {
t.Fatal(err)
}
}
X := FatalIf(t)
NeedPy(t, "zodbtools")
......@@ -400,6 +396,15 @@ func DrvTestWatch(t *testing.T, zurl string, zdrvOpen zodb.DriverOpener) {
}
// FatalIf(t) returns function f(err), which call t.Fatal if err != nil.
func FatalIf(t *testing.T) func(error) {
return func(err error) {
if err != nil {
t.Fatal(err)
}
}
}
// b is syntactic sugar for byte literals.
//
......@@ -412,6 +417,9 @@ func b(data string) []byte {
// bcopy makes a clone of byte slice.
func bcopy(data []byte) []byte {
if data == nil {
return nil
}
d2 := make([]byte, len(data))
copy(d2, data)
return d2
......
......@@ -76,6 +76,9 @@ func TestLoad(t *testing.T) {
fs, _ := xfsopen(t, "testdata/1.fs")
defer exc.XRun(fs.Close)
// NOTE don't use xtesting.LoadDBHistory here - it is itself tested
// with the assumption that fs1.Load and fs1.Iterate works correctly.
// Use what testdata generator gave use with what to expect.
txnv := []xtesting.Txn{}
for _, dbe := range _1fs_dbEntryv {
txn := xtesting.Txn{Header: &zodb.TxnInfo{
......
......@@ -163,7 +163,7 @@ func withZEOSrv(t *testing.T, f func(t *testing.T, zsrv ZEOSrv), optv ...tOption
// withFS1 runs f under environment with new FileStorage database.
withFS1 := func(t *testing.T, f func(fs1path string)) {
t.Helper()
X := mkFatalIf(t)
X := xtesting.FatalIf(t)
work := xtempdir(t)
defer os.RemoveAll(work)
fs1path := work + "/1.fs"
......@@ -186,7 +186,7 @@ func withZEOSrv(t *testing.T, f func(t *testing.T, zsrv ZEOSrv), optv ...tOption
}
xtesting.NeedPy(t, needpy...)
withFS1(t, func(fs1path string) {
X := mkFatalIf(t)
X := xtesting.FatalIf(t)
zpy, err := StartZEOPySrv(fs1path, ZEOPyOptions{msgpack: msgpack}); X(err)
defer func() {
......@@ -206,7 +206,7 @@ func withZEO(t *testing.T, f func(t *testing.T, zdrv *zeo), optv ...tOptions) {
t.Helper()
withZEOSrv(t, func(t *testing.T, zsrv ZEOSrv) {
t.Helper()
X := mkFatalIf(t)
X := xtesting.FatalIf(t)
zdrv, _, err := zeoOpen(zsrv.Addr(), &zodb.DriverOptions{ReadOnly: true}); X(err)
defer func() {
err := zdrv.Close(); X(err)
......@@ -217,7 +217,7 @@ func withZEO(t *testing.T, f func(t *testing.T, zdrv *zeo), optv ...tOptions) {
}
func TestHandshake(t *testing.T) {
X := mkFatalIf(t)
X := xtesting.FatalIf(t)
withZEOSrv(t, func(t *testing.T, zsrv ZEOSrv) {
ctx := context.Background()
net := xnet.NetPlain("unix")
......@@ -237,7 +237,7 @@ func TestLoad(t *testing.T) {
X := exc.Raiseif
data := "../fs1/testdata/1.fs"
txnvOk, err := xtesting.LoadDB(data); X(err)
txnvOk, err := xtesting.LoadDBHistory(data); X(err)
withZEO(t, func(t *testing.T, z *zeo) {
xtesting.DrvTestLoad(t, z, txnvOk)
......@@ -276,11 +276,3 @@ func xtempdir(t *testing.T) string {
}
return tmpd
}
func mkFatalIf(t *testing.T) func(error) {
return func(err error) {
if err != nil {
t.Fatal(err)
}
}
}
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