Commit b20eddfe authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3c3d7063
...@@ -46,6 +46,12 @@ func fsDump(w io.Writer, path string, ntxn int) (err error) { ...@@ -46,6 +46,12 @@ func fsDump(w io.Writer, path string, ntxn int) (err error) {
if err != nil { if err != nil {
return err return err
} }
defer func() {
err2 := f.Close()
if err == nil {
err = err2
}
}()
// get file size as topPos // get file size as topPos
fi, err := f.Stat() fi, err := f.Stat()
......
...@@ -3,3 +3,43 @@ ...@@ -3,3 +3,43 @@
package main package main
//go:generate sh -c "python2 -m ZODB.scripts.fstail -n 1000000 ../../testdata/1.fs >testdata/1.fsdump.ok" //go:generate sh -c "python2 -m ZODB.scripts.fstail -n 1000000 ../../testdata/1.fs >testdata/1.fsdump.ok"
import (
"bytes"
"io/ioutil"
"testing"
"github.com/sergi/go-diff/diffmatchpatch"
)
// XXX -> xtesting ?
func loadFile(t *testing.T, path string) string {
data, err := ioutil.ReadFile(path)
if err != nil {
t.Fatal(err)
}
return string(data)
}
// XXX -> xtesting ?
// XXX dup in zodbdump_test.go
func diff(a, b string) string {
dmp := diffmatchpatch.New()
diffv := dmp.DiffMain(a, b, /*checklines=*/false)
return dmp.DiffPrettyText(diffv)
}
func TestFsDump(t *testing.T) {
buf := bytes.Buffer{}
err := fsDump(&buf, "../../testdata/1.fs", 1000000)
if err != nil {
t.Fatal(err)
}
dumpOk := loadFile(t, "testdata/1.fsdump.ok")
if dumpOk != buf.String() {
t.Errorf("dump different:\n%v", diff(dumpOk, buf.String()))
}
}
...@@ -18,6 +18,8 @@ import ( ...@@ -18,6 +18,8 @@ import (
) )
// diff computes difference for two strings a and b // diff computes difference for two strings a and b
// XXX -> xtesting ?
// XXX dup in fstail_test.go
func diff(a, b string) string { func diff(a, b string) string {
dmp := diffmatchpatch.New() dmp := diffmatchpatch.New()
diffv := dmp.DiffMain(a, b, /*checklines=*/false) diffv := dmp.DiffMain(a, b, /*checklines=*/false)
...@@ -42,6 +44,7 @@ func loadZdumpPy(t *testing.T, path string) string { ...@@ -42,6 +44,7 @@ func loadZdumpPy(t *testing.T, path string) string {
r0c := regexp.MustCompile(`\\x0c`) r0c := regexp.MustCompile(`\\x0c`)
dump = r0b.ReplaceAllLiteral(dump, []byte(`\v`)) dump = r0b.ReplaceAllLiteral(dump, []byte(`\v`))
dump = r0c.ReplaceAllLiteral(dump, []byte(`\f`)) dump = r0c.ReplaceAllLiteral(dump, []byte(`\f`))
return string(dump) return string(dump)
} }
......
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