Add basic support for mongo testing

This is not intended to be for general consumption at this stage; it
requires that the tester has a mongod instance running and because of
the time taken to load the db, $GOROOT/src/cmd/go/test.go must be
modified to allow for tests longer than 10 minutes. A future CL may
allow db probing and the use of an existing cayley test dataset.
This commit is contained in:
kortschak 2014-08-27 23:01:12 +09:30
parent dccf38cba6
commit d8866478df

View file

@ -20,7 +20,6 @@ import (
"compress/gzip" "compress/gzip"
"flag" "flag"
"fmt" "fmt"
"github.com/google/cayley/quad"
"io" "io"
"os" "os"
"reflect" "reflect"
@ -33,6 +32,7 @@ import (
"github.com/google/cayley/config" "github.com/google/cayley/config"
"github.com/google/cayley/db" "github.com/google/cayley/db"
"github.com/google/cayley/graph" "github.com/google/cayley/graph"
"github.com/google/cayley/quad"
"github.com/google/cayley/query/gremlin" "github.com/google/cayley/query/gremlin"
) )
@ -373,8 +373,6 @@ var (
create sync.Once create sync.Once
deleteAndRecreate sync.Once deleteAndRecreate sync.Once
cfg = &config.Config{ cfg = &config.Config{
DatabasePath: "30kmoviedata.nq.gz",
DatabaseType: "memstore",
ReplicationType: "single", ReplicationType: "single",
Timeout: 300 * time.Second, Timeout: 300 * time.Second,
} }
@ -383,17 +381,17 @@ var (
) )
func prepare(t testing.TB) { func prepare(t testing.TB) {
cfg.DatabaseType = *backend
switch *backend { switch *backend {
case "memstore": case "memstore":
break cfg.DatabasePath = "30kmoviedata.nq.gz"
case "leveldb": case "leveldb", "bolt":
fallthrough cfg.DatabasePath = "/tmp/cayley_test_" + *backend
case "bolt":
cfg.DatabaseType = *backend
cfg.DatabasePath = fmt.Sprint("/tmp/cayley_test_", *backend)
cfg.DatabaseOptions = map[string]interface{}{ cfg.DatabaseOptions = map[string]interface{}{
"nosync": true, // It's a test. If we need to load, do it fast. "nosync": true, // It's a test. If we need to load, do it fast.
} }
case "mongo":
cfg.DatabasePath = "localhost:27017"
default: default:
t.Fatalf("Untestable backend store %s", *backend) t.Fatalf("Untestable backend store %s", *backend)
} }