forked from deusdat/arangomigo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharangomigo_test.go
89 lines (71 loc) · 2.28 KB
/
arangomigo_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
package main
import (
"context"
"log"
"sort"
"testing"
driver "github.com/arangodb/go-driver"
"github.com/stretchr/testify/assert"
)
func TestFullMigration(t *testing.T) {
configFile := "testdata/complete/config.yaml"
conf, err := loadConf(configFile)
if e(err) {
log.Fatal(err)
}
ctx := context.Background()
cl, err := client(ctx, *conf)
if e(err) {
log.Fatal(err)
}
db, err := cl.Database(ctx, conf.Db)
if err == nil {
err := db.Remove(ctx)
if e(err) {
t.Fatal("Couldn't prepare for test")
}
}
_, err = cl.Database(ctx, conf.Db)
if !driver.IsNotFound(err) {
t.Fatal("Could not connect to the Database", err)
}
triggerMigration(configFile)
// Look to see if everything was made properly.
db, err = cl.Database(ctx, conf.Db)
assert.NoError(t, err, "Unable to find the database")
recipes, err := db.Collection(ctx, "recipes")
assert.NoError(t, err, "Could not find recipes collection")
// Should find the custom recipe inserted by AQL.
desiredKey := "hello"
r := recipe{}
md, err := recipes.ReadDocument(ctx, desiredKey, &r)
assert.Equal(t, md.Key, desiredKey, "Meta data should match desired key.")
assert.Equal(t, r.Key, desiredKey, "Document key should match desired key.")
assert.Equal(t, "Lots of mayo", r.WithEscaped, "Should have updated the escaped var.")
assert.Equal(t, "Fish", r.MeatType, "Should not have changed.")
assert.Equal(t, "Taco Fishy", r.Name)
// Can't really tell which indexes are available, just that recipes should have
// 6: 1 for the PK and 5 others.
idxs, err := recipes.Indexes(ctx)
assert.Equal(t, 6, len(idxs), "Recipes should have 6 indexes")
// Make sure wait for sync sticks.
colprop, err := recipes.Properties(ctx)
assert.True(t, colprop.WaitForSync, "Should wait for sync.")
g, err := db.Graph(ctx, "testing_graph")
assert.NoError(t, err, "Should have gotten a graph")
vcs, err := g.VertexCollections(ctx)
assert.NoError(t, err, "Should have gotten vertices")
// Vertices include those in edges and oraphans.
justNames := []string{}
for _, k := range vcs {
justNames = append(justNames, k.Name())
}
sort.Strings(justNames)
assert.Equal(t, []string{"another", "recipes", "users"}, justNames)
}
type recipe struct {
Name string
WithEscaped string
MeatType string
Key string `json:"_key"`
}