forked from manyminds/api2go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_test.go
98 lines (79 loc) · 1.75 KB
/
context_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
package api2go
import (
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Context", func() {
var c *APIContext
BeforeEach(func() {
c = &APIContext{}
})
Context("Set", func() {
It("sets key", func() {
c.Set("test", 1)
_, ok := c.keys["test"]
Expect(ok).To(BeTrue())
})
})
Context("Get", func() {
BeforeEach(func() {
c.Set("test", 2)
})
It("gets key", func() {
key, ok := c.Get("test")
Expect(ok).To(BeTrue())
Expect(key.(int)).To(Equal(2))
})
It("not okay if key does not exist", func() {
key, ok := c.Get("nope")
Expect(ok).To(BeFalse())
Expect(key).To(BeNil())
})
})
Context("Reset", func() {
BeforeEach(func() {
c.Set("test", 3)
})
It("reset removes keys", func() {
c.Reset()
_, ok := c.Get("test")
Expect(ok).To(BeFalse())
})
})
Context("Not yet implemented", func() {
It("Deadline", func() {
deadline, ok := c.Deadline()
Expect(deadline).To(Equal(time.Time{}))
Expect(ok).To(Equal(false))
})
It("Done", func() {
var chanel <-chan struct{}
Expect(c.Done()).To(Equal(chanel))
})
It("Err", func() {
Expect(c.Err()).To(BeNil())
})
})
Context("Value", func() {
It("Value returns a set value", func() {
c.Set("foo", "bar")
Expect(c.Value("foo")).To(Equal("bar"))
})
It("Returns nil if key was not a string", func() {
Expect(c.Value(1337)).To(BeNil())
})
})
Context("ContextQueryParams", func() {
It("returns them if set", func() {
queryParams := map[string][]string{
"foo": {"bar"},
}
c.Set("QueryParams", queryParams)
Expect(ContextQueryParams(c)).To(Equal(queryParams))
})
It("sets empty ones if not set", func() {
Expect(ContextQueryParams(c)).To(Equal(map[string][]string{}))
})
})
})