-
Notifications
You must be signed in to change notification settings - Fork 229
/
message_test.go
110 lines (107 loc) · 2.28 KB
/
message_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
107
108
109
110
package dbus
import "testing"
func TestMessage_validateHeader(t *testing.T) {
tcs := []struct {
msg Message
err error
}{
{
msg: Message{
Flags: 0xFF,
},
err: InvalidMessageError("invalid flags"),
},
{
msg: Message{
Type: 0xFF,
},
err: InvalidMessageError("invalid message type"),
},
{
msg: Message{
Type: TypeMethodCall,
Headers: map[HeaderField]Variant{
0xFF: MakeVariant("foo"),
},
},
err: InvalidMessageError("invalid header"),
},
{
msg: Message{
Type: TypeMethodCall,
Headers: map[HeaderField]Variant{
FieldPath: MakeVariant(42),
},
},
err: InvalidMessageError("invalid type of header field"),
},
{
msg: Message{
Type: TypeMethodCall,
},
err: InvalidMessageError("missing required header"),
},
{
msg: Message{
Type: TypeMethodCall,
Headers: map[HeaderField]Variant{
FieldPath: MakeVariant(ObjectPath("break")),
FieldMember: MakeVariant("foo.bar"),
},
},
err: InvalidMessageError("invalid path name"),
},
{
msg: Message{
Type: TypeMethodCall,
Headers: map[HeaderField]Variant{
FieldPath: MakeVariant(ObjectPath("/")),
FieldMember: MakeVariant("2"),
},
},
err: InvalidMessageError("invalid member name"),
},
{
msg: Message{
Type: TypeMethodCall,
Headers: map[HeaderField]Variant{
FieldPath: MakeVariant(ObjectPath("/")),
FieldMember: MakeVariant("foo.bar"),
FieldInterface: MakeVariant("break"),
},
},
err: InvalidMessageError("invalid interface name"),
},
{
msg: Message{
Type: TypeError,
Headers: map[HeaderField]Variant{
FieldReplySerial: MakeVariant(uint32(0)),
FieldErrorName: MakeVariant("break"),
},
},
err: InvalidMessageError("invalid error name"),
},
{
msg: Message{
Type: TypeError,
Headers: map[HeaderField]Variant{
FieldReplySerial: MakeVariant(uint32(0)),
FieldErrorName: MakeVariant("error.name"),
},
Body: []interface{}{
"break",
},
},
err: InvalidMessageError("missing signature"),
},
}
for _, tc := range tcs {
t.Run(tc.err.Error(), func(t *testing.T) {
err := tc.msg.validateHeader()
if err != tc.err {
t.Errorf("expected error %q, got %q", tc.err, err)
}
})
}
}