-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathneo4j_test.go
100 lines (85 loc) · 2.1 KB
/
neo4j_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package neo4j
import (
"os"
"testing"
"github.com/housinganywhere/migrate/file"
"github.com/housinganywhere/migrate/migrate/direction"
pipep "github.com/housinganywhere/migrate/pipe"
"github.com/jmcvetta/neoism"
)
// TestMigrate runs some additional tests on Migrate().
// Basic testing is already done in migrate/migrate_test.go
func TestMigrate(t *testing.T) {
t.Skip("TODO: fix test: neo4j_test.go:26: Get http://neo4j:test@/db/data/: http: no Host in request URL")
host := os.Getenv("NEO4J_PORT_7474_TCP_ADDR")
port := os.Getenv("NEO4J_PORT_7474_TCP_PORT")
driverUrl := "http://neo4j:test@" + host + ":" + port + "/db/data"
// prepare clean database
db, err := neoism.Connect(driverUrl)
if err != nil {
t.Fatal(err)
}
cq := neoism.CypherQuery{
Statement: `DROP INDEX ON :Yolo(name)`,
}
// If an error dropping the index then ignore it
db.Cypher(&cq)
driverUrl = "neo4j://neo4j:test@" + host + ":" + port + "/db/data"
d := &Driver{}
if err := d.Initialize(driverUrl); err != nil {
t.Fatal(err)
}
files := []file.File{
{
Path: "/foobar",
FileName: "001_foobar.up.cql",
Version: 1,
Name: "foobar",
Direction: direction.Up,
Content: []byte(`
CREATE INDEX ON :Yolo(name)
`),
},
{
Path: "/foobar",
FileName: "001_foobar.down.cql",
Version: 1,
Name: "foobar",
Direction: direction.Down,
Content: []byte(`
DROP INDEX ON :Yolo(name)
`),
},
{
Path: "/foobar",
FileName: "002_foobar.up.cql",
Version: 2,
Name: "foobar",
Direction: direction.Up,
Content: []byte(`
CREATE INDEX :Yolo(name) THIS WILL CAUSE AN ERROR
`),
},
}
pipe := pipep.New()
go d.Migrate(files[0], pipe)
errs := pipep.ReadErrors(pipe)
if len(errs) > 0 {
t.Fatal(errs)
}
pipe = pipep.New()
go d.Migrate(files[1], pipe)
errs = pipep.ReadErrors(pipe)
if len(errs) > 0 {
t.Fatal(errs)
}
pipe = pipep.New()
go d.Migrate(files[2], pipe)
errs = pipep.ReadErrors(pipe)
if len(errs) == 0 {
t.Error("Expected test case to fail")
}
if err := d.Close(); err != nil {
t.Fatal(err)
}
}