-
Notifications
You must be signed in to change notification settings - Fork 1
/
mongostore_test.go
134 lines (104 loc) · 3.65 KB
/
mongostore_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
package registry
import "testing"
func TestNewMongoStore(t *testing.T) {
var MONGODB_URL string = "127.0.0.1"
var MONGODB_DB string = "binder_registery_tests"
var MONGODB_COL string = "templates"
store := NewMongoStore(MONGODB_URL, MONGODB_DB, MONGODB_COL)
if (store.err != nil) {
t.Error("NewMongoStore raised error:", store.err);
}
if (store.connection.FullName != (MONGODB_DB + "." + MONGODB_COL)) {
t.Error("Connected to wrong database:", store.connection.FullName)
}
}
func TestMongoRegisterTemplate(t *testing.T) {
var MONGODB_URL string = "127.0.0.1"
var MONGODB_DB string = "binder_registery_tests"
var MONGODB_COL string = "templates"
store := NewMongoStore(MONGODB_URL, MONGODB_DB, MONGODB_COL)
tmpl := Template{
Name: "MongoTest",
ImageName: "jupyter/mongo_test",
}
registered, err := store.RegisterTemplate(tmpl)
if (err != nil) {
t.Error("Error when registering template: ", err)
}
if (registered == Template{}) {
t.Error("Template was not registered properly")
}
equals(t, registered.Name, tmpl.Name)
equals(t, registered.ImageName, tmpl.ImageName)
}
func TestMongoGetTemplate(t * testing.T) {
var MONGODB_URL string = "127.0.0.1"
var MONGODB_DB string = "binder_registery_tests"
var MONGODB_COL string = "templates"
store := NewMongoStore(MONGODB_URL, MONGODB_DB, MONGODB_COL)
name := "MongoTest"
tmpl, err := store.GetTemplate(name)
if (err != nil) {
t.Error("Error when getting template: ", err)
}
equals(t, tmpl.Name, name)
}
func TestMongoListTemplates(t *testing.T) {
var MONGODB_URL string = "127.0.0.1"
var MONGODB_DB string = "binder_registery_tests"
var MONGODB_COL string = "templates"
store := NewMongoStore(MONGODB_URL, MONGODB_DB, MONGODB_COL)
results, err := store.ListTemplates()
if (err != nil) {
t.Error("Error when listing templates: ", err)
}
if (len(results) == 0) {
t.Error("ListTemplates did not find any tempaltes!")
}
}
func TestMongoDeleteTemplate(t *testing.T) {
var MONGODB_URL string = "127.0.0.1"
var MONGODB_DB string = "binder_registery_tests"
var MONGODB_COL string = "templates"
store := NewMongoStore(MONGODB_URL, MONGODB_DB, MONGODB_COL)
tmpl := Template{
Name: "DeleteMePlease",
ImageName: "jupyter/delete_me",
}
_, err := store.RegisterTemplate(tmpl)
if (err == nil) {
err := store.DeleteTemplate(tmpl.Name)
if (err != nil) {
t.Error("Error when deleting template: ", err)
} else {
tmpl, err = store.GetTemplate(tmpl.Name)
if (err == nil && tmpl != Template{}) {
t.Error("Template was not successfully deleted")
}
}
}
}
func TestMongoUpdateTemplate(t *testing.T) {
var MONGODB_URL string = "127.0.0.1"
var MONGODB_DB string = "binder_registery_tests"
var MONGODB_COL string = "templates"
store := NewMongoStore(MONGODB_URL, MONGODB_DB, MONGODB_COL)
tmpl := Template{
Name: "UpdateMePlease",
ImageName: "jupyter/update_me",
}
_, err := store.RegisterTemplate(tmpl)
if (err == nil) {
updates := make(map[string]string)
updates["name"] = "Updated!"
err := store.UpdateTemplate(tmpl.Name, updates)
if (err != nil) {
t.Error("Error when updating template: ", err)
} else {
updated, err := store.GetTemplate("Updated!")
if (err == nil && updated == Template{}) {
t.Error("Template was not successfully updated!")
}
}
}
}