Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
6ff08620
Commit
6ff08620
authored
Mar 15, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
bcb991a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
13 deletions
+60
-13
go/zodb/storage/demo/demo_test.go
go/zodb/storage/demo/demo_test.go
+60
-13
No files found.
go/zodb/storage/demo/demo_test.go
View file @
6ff08620
...
...
@@ -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
}
// withDemo
Storage tests f with all kind of demo overlay
s.
func
withDemo
Storage
(
t
*
testing
.
T
,
f
func
(
t
*
testing
.
T
,
dsrv
*
Storage
/*XXX -> Srv ?*/
),
optv
...
tOptions
)
{
// withDemo
Data tests f with all kind of demo data split
s.
func
withDemo
Data
(
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
,
d
drv
)
})
}
...
...
@@ -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
,
d
drv
,
txnvOk
)
},
tOptions
{
Preload
:
data
,
})
}
func
TestWatch
(
t
*
testing
.
T
)
{
withDemo
Srv
(
t
,
func
(
t
*
testing
.
T
,
dsrv
DemoSrv
)
{
xtesting
.
DrvTestWatch
(
t
,
d
srv
.
URL
(),
openByURL
)
withDemo
Data
(
t
,
func
(
t
*
testing
.
T
,
ddat
*
DemoData
)
{
xtesting
.
DrvTestWatch
(
t
,
d
dat
.
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"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment