-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_test.go
123 lines (105 loc) · 3.59 KB
/
config_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
package redkeep_test
import (
"io/ioutil"
"strings"
. "github.com/manyminds/redkeep"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var mongoMissingConfig = `
{
"watches": [
{
"trackCollection": "live.user",
"trackFields": ["username"],
"targetCollection": "live.comment",
"targetNormalizedField": "normalizedUser",
"triggerReference": "user",
"behaviourSettings": {
"cascadeDelete": false
}
}
]
}`
var watchesMissingConfig = `
{
"mongo": {
"connectionURI": "localhost:30000,localhost:30001,localhost:30002"
},
"watches": [
]
}
`
var emptyConfig = `
{
}
`
var templateForTestsConfig = `
{
"mongo": {
"connectionURI": "localhost:30000,localhost:30001,localhost:30002"
},
"watches": [
{
"trackCollection": "xAx",
"trackFields": ["xBx"],
"targetCollection": "xCx",
"targetNormalizedField": "xDx",
"triggerReference": "xEx"
}
]
}`
var _ = Describe("Config Testsuite", func() {
Context("it will load and validate a config file", func() {
It("will error with an empty config", func() {
_, err := NewConfiguration([]byte(emptyConfig))
Expect(err).To(HaveOccurred())
})
It("will error with missing mongo key", func() {
_, err := NewConfiguration([]byte(mongoMissingConfig))
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("Mongo configuration must be defined"))
})
It("will error with missing watches entries", func() {
_, err := NewConfiguration([]byte(watchesMissingConfig))
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("Please add atleast one entry in watches"))
})
It("will error with correct data but empty trackCollection", func() {
_, err := NewConfiguration([]byte(strings.Replace(templateForTestsConfig, "xAx", "", 1)))
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("TrackCollection must not be empty"))
})
It("will error with correct data but empty targetCollection", func() {
_, err := NewConfiguration([]byte(strings.Replace(templateForTestsConfig, "xCx", "", 1)))
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("TargetCollection must not be empty"))
})
It("will error with correct data but empty targetNormalizedField", func() {
_, err := NewConfiguration([]byte(strings.Replace(templateForTestsConfig, "xDx", "", 1)))
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("TargetNormalizedField must not be empty"))
})
It("will error with correct data but empty triggerReference", func() {
_, err := NewConfiguration([]byte(strings.Replace(templateForTestsConfig, "xEx", "", 1)))
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("TriggerReference must not be empty"))
})
It("will error with correct data but empty trigger", func() {
_, err := NewConfiguration([]byte(strings.Replace(templateForTestsConfig, "xBx", "", 1)))
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("TrackFields must exactly have one non-empty field, more are currently not supported"))
})
It("will error with correct data but multiple trackFields", func() {
_, err := NewConfiguration([]byte(strings.Replace(templateForTestsConfig, `xBx"`, `", "xXx"`, 1)))
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("TrackFields must exactly have one non-empty field, more are currently not supported"))
})
It("will load correctly", func() {
file, err := ioutil.ReadFile("./example-configuration.json")
Expect(err).ToNot(HaveOccurred())
_, err = NewConfiguration(file)
Expect(err).ToNot(HaveOccurred())
})
})
})