-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_announce_test.go
180 lines (163 loc) · 5.77 KB
/
client_announce_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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package nsm
import (
"context"
"testing"
"github.com/scgolang/osc"
)
func TestClientAnnounceReplyMissingArguments(t *testing.T) {
// mockNsmd sets an environment variable to point the client to it's listening address
// This mock also sends an invalid announce reply (missing arguments)
nsmd := newMockNsmd(t, mockNsmdConfig{
listenAddr: "127.0.0.1:0",
announceReply: osc.Message{
Address: AddressReply,
Arguments: osc.Arguments{
osc.String(AddressServerAnnounce),
},
},
})
defer func() { _ = nsmd.Close() }() // Best effort.
if _, err := NewClient(context.Background(), testConfig()); err == nil {
t.Fatal("expected error, got nil")
} else {
if expected, got := `initialize client: announce app: handle announce reply: expected 4 arguments in announce reply, got 1`, err.Error(); expected != got {
t.Fatalf("expected %s, got %s", expected, got)
}
}
}
func TestClientAnnounceReplyWrongAddress(t *testing.T) {
// mockNsmd sets an environment variable to point the client to it's listening address
// This mock also sends an invalid announce reply (missing arguments)
nsmd := newMockNsmd(t, mockNsmdConfig{
listenAddr: "127.0.0.1:0",
announceReply: osc.Message{
Address: AddressReply,
Arguments: osc.Arguments{
osc.String("/foo/bar"),
osc.Int(3),
osc.Int(3),
osc.Int(3),
},
},
})
defer func() { _ = nsmd.Close() }() // Best effort.
if _, err := NewClient(context.Background(), testConfig()); err == nil {
t.Fatal("expected error, got nil")
} else {
if expected, got := `initialize client: announce app: handle announce reply: expected /nsm/server/announce, got /foo/bar`, err.Error(); expected != got {
t.Fatalf("expected %s, got %s", expected, got)
}
}
}
func TestClientAnnounceReplyFirstArgumentWrongType(t *testing.T) {
// mockNsmd sets an environment variable to point the client to it's listening address
// This mock also sends an invalid announce reply (missing arguments)
nsmd := newMockNsmd(t, mockNsmdConfig{
listenAddr: "127.0.0.1:0",
announceReply: osc.Message{
Address: AddressReply,
Arguments: osc.Arguments{
osc.Int(3),
osc.Int(3),
osc.Int(3),
osc.Int(3),
},
},
})
defer func() { _ = nsmd.Close() }() // Best effort.
if _, err := NewClient(context.Background(), testConfig()); err == nil {
t.Fatal("expected error, got nil")
} else {
if expected, got := `initialize client: announce app: handle announce reply: read reply first argument: invalid type tag`, err.Error(); expected != got {
t.Fatalf("expected %s, got %s", expected, got)
}
}
}
func TestClientAnnounceReplySecondArgumentWrongType(t *testing.T) {
// mockNsmd sets an environment variable to point the client to it's listening address
// This mock also sends an invalid announce reply (missing arguments)
nsmd := newMockNsmd(t, mockNsmdConfig{
listenAddr: "127.0.0.1:0",
announceReply: osc.Message{
Address: AddressReply,
Arguments: osc.Arguments{
osc.String(AddressServerAnnounce),
osc.Int(3),
osc.Int(3),
osc.Int(3),
},
},
})
defer func() { _ = nsmd.Close() }() // Best effort.
if _, err := NewClient(context.Background(), testConfig()); err == nil {
t.Fatal("expected error, got nil")
} else {
if expected, got := `initialize client: announce app: handle announce reply: read reply message: invalid type tag`, err.Error(); expected != got {
t.Fatalf("expected %s, got %s", expected, got)
}
}
}
func TestClientAnnounceReplyThirdArgumentWrongType(t *testing.T) {
// mockNsmd sets an environment variable to point the client to it's listening address
// This mock also sends an invalid announce reply (missing arguments)
nsmd := newMockNsmd(t, mockNsmdConfig{
listenAddr: "127.0.0.1:0",
announceReply: osc.Message{
Address: AddressReply,
Arguments: osc.Arguments{
osc.String(AddressServerAnnounce),
osc.String("This reply message is false."),
osc.Int(3),
osc.Int(3),
},
},
})
defer func() { _ = nsmd.Close() }() // Best effort.
if _, err := NewClient(context.Background(), testConfig()); err == nil {
t.Fatal("expected error, got nil")
} else {
if expected, got := `initialize client: announce app: handle announce reply: read session manager name: invalid type tag`, err.Error(); expected != got {
t.Fatalf("expected %s, got %s", expected, got)
}
}
}
func TestClientAnnounceReplyFourthArgumentWrongType(t *testing.T) {
// mockNsmd sets an environment variable to point the client to it's listening address
// This mock also sends an invalid announce reply (missing arguments)
nsmd := newMockNsmd(t, mockNsmdConfig{
listenAddr: "127.0.0.1:0",
announceReply: osc.Message{
Address: AddressReply,
Arguments: osc.Arguments{
osc.String(AddressServerAnnounce),
osc.String("This reply message is false."),
osc.String("Mr. Session Manager"),
osc.Int(3),
},
},
})
defer func() { _ = nsmd.Close() }() // Best effort.
if _, err := NewClient(context.Background(), testConfig()); err == nil {
t.Fatal("expected error, got nil")
} else {
if expected, got := `initialize client: announce app: handle announce reply: read session manager capabilities: invalid type tag`, err.Error(); expected != got {
t.Fatalf("expected %s, got %s", expected, got)
}
}
}
func TestClientAnnounceSendError(t *testing.T) {
var (
// mockNsmd sets an environment variable to point the client to it's listening address
nsmd = newMockNsmd(t, mockNsmdConfig{listenAddr: "127.0.0.1:0"})
config = testConfig()
)
defer func() { _ = nsmd.Close() }() // Best effort.
config.failSend = 1
_, err := NewClient(context.Background(), config)
if err == nil {
t.Fatal("expected error, got nil")
}
if expected, got := `initialize client: announce app: send announce message: fail send`, err.Error(); expected != got {
t.Fatalf("expected %s, got %s", expected, got)
}
}