-
Notifications
You must be signed in to change notification settings - Fork 4
/
call_test.go
47 lines (36 loc) · 1.1 KB
/
call_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
package porthos
import (
"testing"
)
func TestCallWithDefaultTimeout(t *testing.T) {
c := newCall(&Client{defaultTTL: 10}, "doSomething")
timeout := c.getTimeout()
if timeout != 10 {
t.Errorf("Got an unexpected timeout: %d", timeout)
}
}
func TestCallWithSpecificTimeout(t *testing.T) {
c := newCall(&Client{defaultTTL: 10}, "doSomething").WithTimeout(20)
timeout := c.getTimeout()
if timeout != 20 {
t.Errorf("Got an unexpected timeout: %d", timeout)
}
}
func TestCallWithBody(t *testing.T) {
c := newCall(&Client{}, "doSomething").WithBody([]byte("test123"))
if string(c.body) != "test123" {
t.Errorf("Got an unexpected body: %s", string(c.body))
}
}
func TestCallWithArgs(t *testing.T) {
c := newCall(&Client{}, "doSomething").WithArgs(10, 20)
if string(c.body) != "[10,20]" {
t.Errorf("Got an unexpected body: %s", string(c.body))
}
}
func TestCallWithMap(t *testing.T) {
c := newCall(&Client{}, "doSomething").WithMap(map[string]interface{}{"fieldX": 5, "fieldY": 10})
if string(c.body) != `{"fieldX":5,"fieldY":10}` {
t.Errorf("Got an unexpected body: %s", string(c.body))
}
}