forked from SierraSoftworks/sentry-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodules_test.go
121 lines (99 loc) · 2.77 KB
/
modules_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
package sentry
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func ExampleModules() {
cl := NewClient(
// You can specify module versions when creating your
// client
Modules(map[string]string{
"redis": "v1",
"mgo": "v2",
}),
)
cl.Capture(
// And override or expand on them when sending an event
Modules(map[string]string{
"redis": "v2",
"sentry-go": "v1",
}),
)
}
func TestModules(t *testing.T) {
Convey("Modules", t, func() {
Convey("Modules()", func() {
data := map[string]string{
"redis": "1.0.0",
}
Convey("Should return nil if the data is nil", func() {
So(Modules(nil), ShouldBeNil)
})
Convey("Should return an Option", func() {
So(Modules(data), ShouldImplement, (*Option)(nil))
})
Convey("Should use the correct Class()", func() {
So(Modules(data).Class(), ShouldEqual, "modules")
})
Convey("Should implement Merge()", func() {
So(Modules(data), ShouldImplement, (*MergeableOption)(nil))
})
})
Convey("Merge()", func() {
data1 := map[string]string{
"redis": "1.0.0",
}
e1 := Modules(data1)
So(e1, ShouldNotBeNil)
e1m, ok := e1.(MergeableOption)
So(ok, ShouldBeTrue)
Convey("Should overwrite if it doesn't recognize the old option", func() {
So(e1m.Merge(&testOption{}), ShouldEqual, e1)
})
Convey("Should merge multiple modules entries", func() {
data2 := map[string]string{
"pgsql": "5.4.0",
}
e2 := Modules(data2)
So(e2, ShouldNotBeNil)
em := e1m.Merge(e2)
So(em, ShouldNotBeNil)
So(em, ShouldNotEqual, e1)
So(em, ShouldNotEqual, e2)
emm, ok := em.(*modulesOption)
So(ok, ShouldBeTrue)
So(emm.moduleVersions, ShouldContainKey, "redis")
So(emm.moduleVersions, ShouldContainKey, "pgsql")
})
Convey("Should overwrite old entries with new ones", func() {
data2 := map[string]string{
"redis": "0.8.0",
}
e2 := Modules(data2)
So(e2, ShouldNotBeNil)
em := e1m.Merge(e2)
So(em, ShouldNotBeNil)
So(em, ShouldNotEqual, e1)
So(em, ShouldNotEqual, e2)
emm, ok := em.(*modulesOption)
So(ok, ShouldBeTrue)
So(emm.moduleVersions, ShouldContainKey, "redis")
So(emm.moduleVersions["redis"], ShouldEqual, "1.0.0")
})
})
Convey("MarshalJSON", func() {
Convey("Should marshal the fields correctly", func() {
data := map[string]string{
"redis": "1.0.0",
}
serialized := testOptionsSerialize(Modules(data))
So(serialized, ShouldNotBeNil)
expected := map[string]interface{}{
"redis": "1.0.0",
}
So(serialized, ShouldHaveSameTypeAs, expected)
So(serialized, ShouldResemble, expected)
})
})
})
}