-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext_test.go
More file actions
65 lines (50 loc) · 1.17 KB
/
context_test.go
File metadata and controls
65 lines (50 loc) · 1.17 KB
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
package natsby
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestNext(t *testing.T) {
setOutHandlerCalled := false
setOutHandler := func(c *Context) {
setOutHandlerCalled = true
}
c := Context{
handlers: HandlersChain{setOutHandler},
}
c.reset()
c.Next()
assert.Equal(t, true, setOutHandlerCalled)
}
func TestNextWithLatencyDuration(t *testing.T) {
setOutHandlerCalled := false
setOutHandler := func(c *Context) {
setOutHandlerCalled = true
}
c := Context{
handlers: HandlersChain{setOutHandler},
}
c.reset()
latency := c.NextWithLatencyDuration()
assert.Equal(t, true, setOutHandlerCalled)
var d time.Duration
assert.IsType(t, d, latency)
}
func TestKeys(t *testing.T) {
c := Context{}
c.Set("test", "hello")
out := c.Get("test").(string)
assert.Equal(t, "hello", out)
}
func TestGetByteReplyPayload(t *testing.T) {
c := &Context{}
var payload []byte
payload, ok := c.GetByteReplyPayload()
assert.Equal(t, ok, false)
assert.Equal(t, []byte(""), payload)
c.didReply = true
c.ByteReplyPayload = []byte("reply")
payload, ok = c.GetByteReplyPayload()
assert.Equal(t, ok, true)
assert.Equal(t, []byte("reply"), payload)
}