-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
69 lines (52 loc) · 1.8 KB
/
client_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
package pts
import (
"testing"
)
func TestClient(t *testing.T) {
t.Run("Simple New Client", func(t *testing.T) {
properties := map[string]interface{}{
"foo": "bar",
"bool": true,
}
client := NewClient(func(message []byte) error { return nil }, properties)
if val, _ := client.Get("foo"); val != properties["foo"] {
t.Errorf("client.Get(\"foo\") = %s, want %s", val, properties["foo"])
}
if val, _ := client.Get("bool"); val != properties["bool"] {
t.Errorf("client.Get(\"foo\") = %b, want %b", val, properties["foo"])
}
})
t.Run("Client Set/Get", func(t *testing.T) {
testKey := "barFoo"
testVal := "fooBar"
client := NewClient(func(message []byte) error { return nil }, map[string]interface{}{})
client.Set(testKey, testVal)
if val, _ := client.Get(testKey); val != testVal {
t.Errorf("client.Get(\"%s\") = %s, want %s", testKey, val, testVal)
}
})
t.Run("Client MustGet", func(t *testing.T) {
testKey := "barFoo"
testKeyNotExistent := "barFooNotThere"
testVal := "fooBar"
client := NewClient(func(message []byte) error { return nil }, map[string]interface{}{})
client.Set(testKey, testVal)
if val := client.MustGet(testKey); val != testVal {
t.Errorf("client.MustGet(\"%s\") = %s, want %s", testKey, val, testVal)
}
defer func() { recover() }()
client.MustGet(testKeyNotExistent)
t.Errorf("client.MustGet(%s) did not panic, but it should have", testKeyNotExistent)
})
t.Run("Client Get Missing", func(t *testing.T) {
testKey := "barFoo"
client := NewClient(func(message []byte) error { return nil }, map[string]interface{}{})
if val, ok := client.Get(testKey); ok != false || val != nil {
boolStr := "false"
if ok {
boolStr = "true"
}
t.Errorf("client.Get(\"%s\") = (%s, %s), want (false, nil)", testKey, val, boolStr)
}
})
}