fix tests for new method names

This commit is contained in:
Jeremy Jay 2014-07-18 14:09:57 -04:00
parent 0641309a8f
commit a6dc5c9532
5 changed files with 49 additions and 45 deletions

View file

@ -102,12 +102,13 @@ func TestCreateDatabase(t *testing.T) {
} }
t.Log(tmpDir) t.Log(tmpDir)
if created := CreateNewLevelDB(tmpDir); !created { err = createNewLevelDB(tmpDir, nil)
if err != nil {
t.Fatal("Failed to create LevelDB database.") t.Fatal("Failed to create LevelDB database.")
} }
ts := NewTripleStore(tmpDir, nil) ts, err := newTripleStore(tmpDir, nil)
if ts == nil { if ts == nil || err != nil {
t.Error("Failed to create leveldb TripleStore.") t.Error("Failed to create leveldb TripleStore.")
} }
if s := ts.Size(); s != 0 { if s := ts.Size(); s != 0 {
@ -115,21 +116,10 @@ func TestCreateDatabase(t *testing.T) {
} }
ts.Close() ts.Close()
if created := CreateNewLevelDB("/dev/null/some terrible path"); created { err = createNewLevelDB("/dev/null/some terrible path", nil)
if err == nil {
t.Errorf("Created LevelDB database for bad path.") t.Errorf("Created LevelDB database for bad path.")
} }
// TODO(kortschak) Invalidate this test by using error returns rather than panics.
var panicked bool
func() {
defer func() {
r := recover()
panicked = r != nil
}()
NewTripleStore("/dev/null/some terrible path", nil)
}()
if !panicked {
t.Error("NewTripleStore failed to panic with bad path.")
}
os.RemoveAll(tmpDir) os.RemoveAll(tmpDir)
} }
@ -142,14 +132,13 @@ func TestLoadDatabase(t *testing.T) {
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
t.Log(tmpDir) t.Log(tmpDir)
if created := CreateNewLevelDB(tmpDir); !created { err = createNewLevelDB(tmpDir, nil)
if err != nil {
t.Fatal("Failed to create LevelDB database.") t.Fatal("Failed to create LevelDB database.")
} }
var ts *TripleStore ts, err := newTripleStore(tmpDir, nil)
if ts == nil || err != nil {
ts = NewTripleStore(tmpDir, nil)
if ts == nil {
t.Error("Failed to create leveldb TripleStore.") t.Error("Failed to create leveldb TripleStore.")
} }
@ -164,19 +153,25 @@ func TestLoadDatabase(t *testing.T) {
} }
ts.Close() ts.Close()
if created := CreateNewLevelDB(tmpDir); !created { err = createNewLevelDB(tmpDir, nil)
if err != nil {
t.Fatal("Failed to create LevelDB database.") t.Fatal("Failed to create LevelDB database.")
} }
ts = NewTripleStore(tmpDir, nil) ts, err = newTripleStore(tmpDir, nil)
if ts == nil { if ts == nil || err != nil {
t.Error("Failed to create leveldb TripleStore.") t.Error("Failed to create leveldb TripleStore.")
} }
ts2, didConvert := ts.(*TripleStore)
if !didConvert {
t.Errorf("Could not convert from generic to LevelDB TripleStore")
}
ts.AddTripleSet(makeTripleSet()) ts.AddTripleSet(makeTripleSet())
if s := ts.Size(); s != 11 { if s := ts.Size(); s != 11 {
t.Errorf("Unexpected triplestore size, got:%d expect:11", s) t.Errorf("Unexpected triplestore size, got:%d expect:11", s)
} }
if s := ts.SizeOf(ts.ValueOf("B")); s != 5 { if s := ts2.SizeOf(ts.ValueOf("B")); s != 5 {
t.Errorf("Unexpected triplestore size, got:%d expect:5", s) t.Errorf("Unexpected triplestore size, got:%d expect:5", s)
} }
@ -184,7 +179,7 @@ func TestLoadDatabase(t *testing.T) {
if s := ts.Size(); s != 10 { if s := ts.Size(); s != 10 {
t.Errorf("Unexpected triplestore size after RemoveTriple, got:%d expect:10", s) t.Errorf("Unexpected triplestore size after RemoveTriple, got:%d expect:10", s)
} }
if s := ts.SizeOf(ts.ValueOf("B")); s != 4 { if s := ts2.SizeOf(ts.ValueOf("B")); s != 4 {
t.Errorf("Unexpected triplestore size, got:%d expect:4", s) t.Errorf("Unexpected triplestore size, got:%d expect:4", s)
} }
@ -199,12 +194,15 @@ func TestIterator(t *testing.T) {
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
t.Log(tmpDir) t.Log(tmpDir)
if created := CreateNewLevelDB(tmpDir); !created { err = createNewLevelDB(tmpDir, nil)
if err != nil {
t.Fatal("Failed to create LevelDB database.") t.Fatal("Failed to create LevelDB database.")
} }
var ts *TripleStore ts, err := newTripleStore(tmpDir, nil)
ts = NewTripleStore(tmpDir, nil) if ts == nil || err != nil {
t.Error("Failed to create leveldb TripleStore.")
}
ts.AddTripleSet(makeTripleSet()) ts.AddTripleSet(makeTripleSet())
var it graph.Iterator var it graph.Iterator
@ -289,12 +287,15 @@ func TestSetIterator(t *testing.T) {
tmpDir, _ := ioutil.TempDir(os.TempDir(), "cayley_test") tmpDir, _ := ioutil.TempDir(os.TempDir(), "cayley_test")
t.Log(tmpDir) t.Log(tmpDir)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
ok := CreateNewLevelDB(tmpDir) err := createNewLevelDB(tmpDir, nil)
if !ok { if err != nil {
t.Fatalf("Failed to create working directory") t.Fatalf("Failed to create working directory")
} }
ts := NewTripleStore(tmpDir, nil) ts, err := newTripleStore(tmpDir, nil)
if ts == nil || err != nil {
t.Error("Failed to create leveldb TripleStore.")
}
defer ts.Close() defer ts.Close()
ts.AddTripleSet(makeTripleSet()) ts.AddTripleSet(makeTripleSet())
@ -401,11 +402,14 @@ func TestOptimize(t *testing.T) {
tmpDir, _ := ioutil.TempDir(os.TempDir(), "cayley_test") tmpDir, _ := ioutil.TempDir(os.TempDir(), "cayley_test")
t.Log(tmpDir) t.Log(tmpDir)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
ok := CreateNewLevelDB(tmpDir) err := createNewLevelDB(tmpDir, nil)
if !ok { if err != nil {
t.Fatalf("Failed to create working directory") t.Fatalf("Failed to create working directory")
} }
ts := NewTripleStore(tmpDir, nil) ts, err := newTripleStore(tmpDir, nil)
if ts == nil || err != nil {
t.Error("Failed to create leveldb TripleStore.")
}
ts.AddTripleSet(makeTripleSet()) ts.AddTripleSet(makeTripleSet())
// With an linksto-fixed pair // With an linksto-fixed pair

View file

@ -52,7 +52,7 @@ var simpleGraph = []*graph.Triple{
func makeTestStore(data []*graph.Triple) (*TripleStore, []pair) { func makeTestStore(data []*graph.Triple) (*TripleStore, []pair) {
seen := make(map[string]struct{}) seen := make(map[string]struct{})
ts := NewTripleStore() ts := newTripleStore()
var ( var (
val int64 val int64
ind []pair ind []pair

View file

@ -18,7 +18,7 @@ import (
"testing" "testing"
"github.com/google/cayley/graph" "github.com/google/cayley/graph"
"github.com/google/cayley/graph/memstore" _ "github.com/google/cayley/graph/memstore"
) )
func TestBadParse(t *testing.T) { func TestBadParse(t *testing.T) {
@ -52,7 +52,7 @@ var testQueries = []struct {
} }
func TestMemstoreBackedSexp(t *testing.T) { func TestMemstoreBackedSexp(t *testing.T) {
ts := memstore.NewTripleStore() ts, _ := graph.NewTripleStore("memstore", "", nil)
it := BuildIteratorTreeForQuery(ts, "()") it := BuildIteratorTreeForQuery(ts, "()")
if it.Type() != graph.Null { if it.Type() != graph.Null {
t.Errorf(`Incorrect type for empty query, got:%q expect: "null"`, it.Type()) t.Errorf(`Incorrect type for empty query, got:%q expect: "null"`, it.Type())
@ -76,7 +76,7 @@ func TestMemstoreBackedSexp(t *testing.T) {
} }
func TestTreeConstraintParse(t *testing.T) { func TestTreeConstraintParse(t *testing.T) {
ts := memstore.NewTripleStore() ts, _ := graph.NewTripleStore("memstore", "", nil)
ts.AddTriple(&graph.Triple{"i", "like", "food", ""}) ts.AddTriple(&graph.Triple{"i", "like", "food", ""})
ts.AddTriple(&graph.Triple{"food", "is", "good", ""}) ts.AddTriple(&graph.Triple{"food", "is", "good", ""})
query := "(\"i\"\n" + query := "(\"i\"\n" +
@ -96,7 +96,7 @@ func TestTreeConstraintParse(t *testing.T) {
} }
func TestTreeConstraintTagParse(t *testing.T) { func TestTreeConstraintTagParse(t *testing.T) {
ts := memstore.NewTripleStore() ts, _ := graph.NewTripleStore("memstore", "", nil)
ts.AddTriple(&graph.Triple{"i", "like", "food", ""}) ts.AddTriple(&graph.Triple{"i", "like", "food", ""})
ts.AddTriple(&graph.Triple{"food", "is", "good", ""}) ts.AddTriple(&graph.Triple{"food", "is", "good", ""})
query := "(\"i\"\n" + query := "(\"i\"\n" +
@ -116,7 +116,7 @@ func TestTreeConstraintTagParse(t *testing.T) {
} }
func TestMultipleConstraintParse(t *testing.T) { func TestMultipleConstraintParse(t *testing.T) {
ts := memstore.NewTripleStore() ts, _ := graph.NewTripleStore("memstore", "", nil)
for _, tv := range []*graph.Triple{ for _, tv := range []*graph.Triple{
{"i", "like", "food", ""}, {"i", "like", "food", ""},
{"i", "like", "beer", ""}, {"i", "like", "beer", ""},

View file

@ -20,7 +20,7 @@ import (
"testing" "testing"
"github.com/google/cayley/graph" "github.com/google/cayley/graph"
"github.com/google/cayley/graph/memstore" _ "github.com/google/cayley/graph/memstore"
) )
// This is a simple test graph. // This is a simple test graph.
@ -51,7 +51,7 @@ var simpleGraph = []*graph.Triple{
} }
func makeTestSession(data []*graph.Triple) *Session { func makeTestSession(data []*graph.Triple) *Session {
ts := memstore.NewTripleStore() ts, _ := graph.NewTripleStore("memstore", "", nil)
for _, t := range data { for _, t := range data {
ts.AddTriple(t) ts.AddTriple(t)
} }

View file

@ -20,7 +20,7 @@ import (
"testing" "testing"
"github.com/google/cayley/graph" "github.com/google/cayley/graph"
"github.com/google/cayley/graph/memstore" _ "github.com/google/cayley/graph/memstore"
) )
// This is a simple test graph. // This is a simple test graph.
@ -51,7 +51,7 @@ var simpleGraph = []*graph.Triple{
} }
func makeTestSession(data []*graph.Triple) *Session { func makeTestSession(data []*graph.Triple) *Session {
ts := memstore.NewTripleStore() ts, _ := graph.NewTripleStore("memstore", "", nil)
for _, t := range data { for _, t := range data {
ts.AddTriple(t) ts.AddTriple(t)
} }