-
Notifications
You must be signed in to change notification settings - Fork 5
/
utils_test.go
55 lines (49 loc) · 1.18 KB
/
utils_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
package gobis_test
import (
"github.com/mitchellh/mapstructure"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/orange-cloudfoundry/gobis"
)
type TestStruct struct {
Foo string `json:"foo"`
Bar int `json:"bar"`
}
type SecondTestStruct struct {
Zorro string `json:"zorro"`
}
var _ = Describe("Utils", func() {
Context("When passing one interface", func() {
It("should return the corresponding map", func() {
m := InterfaceToMap(TestStruct{
Foo: "bar",
Bar: 1,
})
var t TestStruct
err := mapstructure.Decode(m, &t)
Expect(err).ToNot(HaveOccurred())
Expect(t.Foo).Should(Equal("bar"))
Expect(t.Bar).Should(Equal(1))
})
})
Context("When passing multiple interface", func() {
It("should return the corresponding map by merging multiple interface", func() {
m := InterfaceToMap(
TestStruct{
Foo: "bar",
Bar: 1,
},
SecondTestStruct{
Zorro: "garcia",
},
)
var t TestStruct
err := mapstructure.Decode(m, &t)
Expect(err).ToNot(HaveOccurred())
var z SecondTestStruct
err = mapstructure.Decode(m, &z)
Expect(err).ToNot(HaveOccurred())
Expect(z.Zorro).Should(Equal("garcia"))
})
})
})