-
Notifications
You must be signed in to change notification settings - Fork 12
/
sac_test.go
79 lines (60 loc) · 1.58 KB
/
sac_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
package aqua
import (
. "github.com/smartystreets/goconvey/convey"
"testing"
)
type sacStruct struct {
Field string
}
func TestSacSet(t *testing.T) {
Convey("Given a Sac, Then Set() method", t, func() {
s := NewSac()
Convey("should accept literals", func() {
s.Set("a-string", "bingo")
So(s.Data["a-string"], ShouldEqual, "bingo")
s.Set("an-int", 123)
So(s.Data["an-int"], ShouldEqual, 123)
})
Convey("should accept a Sac", func() {
b := NewSac().Set("sac-b", "value")
s.Set("sac-a", b)
m, ok := s.Data["sac-a"].(map[string]interface{})
So(ok, ShouldBeTrue)
So(m["sac-b"], ShouldEqual, "value")
})
Convey("should accept a map", func() {
m := make(map[string]interface{})
m["map"] = 123
s.Set("a-map", m)
m, ok := s.Data["a-map"].(map[string]interface{})
So(ok, ShouldBeTrue)
So(m["map"], ShouldEqual, 123)
})
Convey("should accept a struct", func() {
st := sacStruct{Field: "oh"}
s.Set("a-struct", st)
m, ok := s.Data["a-struct"].(map[string]interface{})
So(ok, ShouldBeTrue)
So(m["Field"], ShouldEqual, "oh")
})
})
}
func TestSacMerge(t *testing.T) {
Convey("Given a Sac, Then Merge() method", t, func() {
s := NewSac()
m1 := make(map[string]interface{})
m1["a"] = "A"
m2 := make(map[string]interface{})
m2["b"] = "B"
s.Merge(m1).Merge(m2).Merge(sacStruct{Field: "C"})
val, ok := s.Data["a"]
So(ok, ShouldBeTrue)
So(val, ShouldEqual, "A")
val, ok = s.Data["b"]
So(ok, ShouldBeTrue)
So(val, ShouldEqual, "B")
val, ok = s.Data["Field"]
So(ok, ShouldBeTrue)
So(val, ShouldEqual, "C")
})
}