forked from deusdat/arangomigo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharangomigo_test.go
197 lines (156 loc) · 5.02 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package arangomigo
import (
"context"
"log"
"sort"
"testing"
driver "github.com/arangodb/go-driver"
"github.com/stretchr/testify/assert"
)
func TestConfigLoad(t *testing.T) {
configFile := "testdata/complete/config.yaml"
conf, err := loadConf(configFile)
if e(err) {
log.Fatal(err)
}
if len(conf.MigrationsPath) != 1 {
log.Fatal("Invalid migration path")
}
}
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(*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.IsNotFoundGeneral(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
// 7: 1 for the PK and 6 others.
idxs, err := recipes.Indexes(ctx)
assert.Equal(t, 9, len(idxs), "Recipes should have 9 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")
viewExists, viewExistsErr := db.ViewExists(ctx, "testing_searchalias_view")
assert.NoError(t, viewExistsErr, "Should have got a search-alias view")
assert.True(t, viewExists, "Should have got testing_searchalias_view")
view, err := db.View(ctx, "testing_searchalias_view")
assert.NoError(t, err, "Should have got view")
v, err := view.ArangoSearchViewAlias()
assert.NoError(t, err, "Should have got view as search-alias view")
viewProperties, err := v.Properties(ctx)
assert.NoError(t, err, "Should have got search-alias view properties")
assert.Len(t, viewProperties.Indexes, 1, "Should have 1 index")
// 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)
}
func TestMultiPathMigration(t *testing.T) {
configFile := "testdata/complete2/config.yaml"
conf, err := loadConf(configFile)
if e(err) {
log.Fatal(err)
}
ctx := context.Background()
cl, err := client(*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.
// Can't really tell which indexes are available, just that recipes should
// have just 1 for the PK.
idxs, err := recipes.Indexes(ctx)
assert.Equal(t, 1, len(idxs), "Recipes should have 1 index")
// Make sure wait for sync sticks.
colprop, err := recipes.Properties(ctx)
assert.NotNil(t, colprop, "Should have the collection properties")
assert.False(t, colprop.WaitForSync, "Should wait for sync.")
}
func TestSkipSSLVerify(t *testing.T) {
configFile := "testdata/skip_ssl_verify/config.yaml"
conf, err := loadConf(configFile)
if e(err) {
log.Fatal(err)
}
ctx := context.Background()
cl, err := client(*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")
}
type recipe struct {
Name string
WithEscaped string
MeatType string
Key string `json:"_key"`
}