This repository has been archived by the owner on Dec 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
/
client_test.go
106 lines (95 loc) · 2.59 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
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
99
100
101
102
103
104
105
106
package amqp
import (
"encoding/binary"
"testing"
)
func TestLinkOptions(t *testing.T) {
tests := []struct {
label string
opts []LinkOption
wantSource *source
wantProperties map[symbol]interface{}
}{
{
label: "no options",
},
{
label: "link-filters",
opts: []LinkOption{
LinkSelectorFilter("amqp.annotation.x-opt-offset > '100'"),
LinkProperty("x-opt-test1", "test1"),
LinkProperty("x-opt-test2", "test2"),
LinkProperty("x-opt-test1", "test3"),
LinkPropertyInt64("x-opt-test4", 1),
LinkSourceFilter("com.microsoft:session-filter", 0x00000137000000C, "123"),
},
wantSource: &source{
Filter: map[symbol]*describedType{
"apache.org:selector-filter:string": {
descriptor: binary.BigEndian.Uint64([]byte{0x00, 0x00, 0x46, 0x8C, 0x00, 0x00, 0x00, 0x04}),
value: "amqp.annotation.x-opt-offset > '100'",
},
"com.microsoft:session-filter": {
descriptor: binary.BigEndian.Uint64([]byte{0x00, 0x00, 0x00, 0x13, 0x70, 0x00, 0x00, 0x0C}),
value: "123",
},
},
},
wantProperties: map[symbol]interface{}{
"x-opt-test1": "test3",
"x-opt-test2": "test2",
"x-opt-test4": int64(1),
},
},
{
label: "more-link-filters",
opts: []LinkOption{
LinkSourceFilter("com.microsoft:session-filter", 0x00000137000000C, nil),
},
wantSource: &source{
Filter: map[symbol]*describedType{
"com.microsoft:session-filter": {
descriptor: binary.BigEndian.Uint64([]byte{0x00, 0x00, 0x00, 0x13, 0x70, 0x00, 0x00, 0x0C}),
value: nil,
},
},
},
},
{
label: "link-source-capabilities",
opts: []LinkOption{
LinkSourceCapabilities("cap1", "cap2", "cap3"),
},
wantSource: &source{
Capabilities: []symbol{"cap1", "cap2", "cap3"},
},
},
}
for _, tt := range tests {
t.Run(tt.label, func(t *testing.T) {
got, err := newLink(nil, nil, tt.opts)
if err != nil {
t.Fatal(err)
}
if !testEqual(got.source, tt.wantSource) {
t.Errorf("Source properties don't match expected:\n %s", testDiff(got.source, tt.wantSource))
}
if !testEqual(got.properties, tt.wantProperties) {
t.Errorf("Link properties don't match expected:\n %s", testDiff(got.properties, tt.wantProperties))
}
})
}
}
func TestSourceName(t *testing.T) {
expectedSourceName := "source-name"
opts := []LinkOption{
LinkName(expectedSourceName),
}
got, err := newLink(nil, nil, opts)
if err != nil {
t.Fatal(err)
}
if got.key.name != expectedSourceName {
t.Errorf("Link Source Name does not match expected: %v got: %v", expectedSourceName, got.key.name)
}
}