Commit 0afd029d authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 18b3a2f3
...@@ -7,6 +7,7 @@ package fs1 ...@@ -7,6 +7,7 @@ package fs1
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log"
"os" "os"
"os/exec" "os/exec"
"sort" "sort"
...@@ -173,17 +174,13 @@ func checkIndexEqual(t *testing.T, subject string, topPos1, topPos2 int64, fsi1, ...@@ -173,17 +174,13 @@ func checkIndexEqual(t *testing.T, subject string, topPos1, topPos2 int64, fsi1,
} }
func TestIndexSaveLoad(t *testing.T) { func TestIndexSaveLoad(t *testing.T) {
workdir, err := ioutil.TempDir("", "t-index") workdir := xworkdir(t)
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(workdir)
topPos := int64(786) topPos := int64(786)
fsi := fsIndexNew() fsi := fsIndexNew()
setIndex(fsi, indexTest1[:]) setIndex(fsi, indexTest1[:])
err = fsi.SaveFile(topPos, workdir + "/1.fs.index") err := fsi.SaveFile(topPos, workdir + "/1.fs.index")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -213,13 +210,65 @@ func TestIndexLoadFromPy(t *testing.T) { ...@@ -213,13 +210,65 @@ func TestIndexLoadFromPy(t *testing.T) {
checkIndexEqual(t, "index load", topPosPy, _1fs_indexTopPos, fsiPy, fsiExpect) checkIndexEqual(t, "index load", topPosPy, _1fs_indexTopPos, fsiPy, fsiExpect)
} }
var havePyZODB = false // test zodb/py can read index data as saved by us
func init() { func TestIndexSaveToPy(t *testing.T) {
needZODBPy(t)
workdir := xworkdir(t)
fsi := fsIndexNew()
setIndex(fsi, _1fs_indexEntryv[:])
err := fsi.SaveFile(_1fs_indexTopPos, workdir + "/1.fs.index")
if err != nil {
t.Fatal(err)
}
// now ask python part to compare testdata and save-by-us index
cmd := exec.Command("./indexcmp", "testdata/1.fs.index", workdir + "/1.fs.index")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
t.Fatalf("zodb/py read/compare index: %v", err)
}
}
var haveZODBPy = false
var workRoot string
func TestMain(m *testing.M) {
// check whether we have zodb/py
cmd := exec.Command("python2", "-c", "import ZODB") cmd := exec.Command("python2", "-c", "import ZODB")
err := cmd.Run() err := cmd.Run()
if err == nil { if err == nil {
havePyZODB = true haveZODBPy = true
}
// setup work root for all tests
workRoot, err = ioutil.TempDir("", "t-index")
if err != nil {
log.Fatal(err)
}
exit := m.Run()
os.RemoveAll(workRoot)
os.Exit(exit)
}
func needZODBPy(t *testing.T) {
if haveZODBPy {
return
} }
t.Skipf("zodb/py is not available")
}
//println("havePyZODB:", havePyZODB) // create temp dir inside workRoot
func xworkdir(t *testing.T) string {
work, err := ioutil.TempDir(workRoot, "")
if err != nil {
t.Fatal(err)
}
return work
} }
#!/usr/bin/env python2
"""compare two index files"""
from ZODB.fsIndex import fsIndex
import sys
def main():
path1, path2 = sys.argv[1:]
d1 = fsIndex.load(path1)
d2 = fsIndex.load(path2)
topPos1, fsi1 = d1["pos"], d1["index"]
topPos2, fsi2 = d2["pos"], d2["index"]
#print topPos1, topPos2
#print fsi1.items()
#print fsi2.items()
equal = (topPos1 == topPos2 and fsi1.items() == fsi2.items())
sys.exit(int(not equal))
if __name__ == '__main__':
main()
...@@ -8,6 +8,6 @@ var _1fs_indexEntryv = [...]indexEntry{ ...@@ -8,6 +8,6 @@ var _1fs_indexEntryv = [...]indexEntry{
{ 3, 8691}, { 3, 8691},
{ 4, 8543}, { 4, 8543},
{ 5, 7359}, { 5, 7359},
{ 6, 8839}, { 9, 8839},
{ 7, 7507}, { 7, 7507},
} }
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