This repository has been archived by the owner on Jan 31, 2019. It is now read-only.
/
irc_test.rb
218 lines (183 loc) · 6.67 KB
/
irc_test.rb
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
require File.expand_path('../helper', __FILE__)
require 'stringio'
class IRCTest < Service::TestCase
class FakeIRC < Service::IRC
def readable_io
@readable_io ||= StringIO.new(" 004 n ")
end
def writable_io
@writable_io ||= StringIO.new
end
def irc_puts(*args)
writable_io.puts *args
end
def irc_gets
readable_io.gets
end
def irc_eof?
true
end
def shorten_url(*args)
'short'
end
end
def test_push
svc = service({'room' => 'r', 'nick' => 'n'}, payload)
svc.receive_push
msgs = svc.writable_io.string.split("\n")
assert_equal "NICK n", msgs.shift
assert_match "USER n", msgs.shift
assert_equal "JOIN #r", msgs.shift.strip
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_equal "PART #r", msgs.shift.strip
assert_equal "QUIT", msgs.shift.strip
assert_nil msgs.shift
end
def test_push_with_empty_branch_regex
svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => ''}, payload)
svc.receive_push
msgs = svc.writable_io.string.split("\n")
assert_equal "NICK n", msgs.shift
assert_match "USER n", msgs.shift
assert_equal "JOIN #r", msgs.shift.strip
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_equal "PART #r", msgs.shift.strip
assert_equal "QUIT", msgs.shift.strip
assert_nil msgs.shift
end
def test_push_with_single_matching_branch_regex
svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => 'mast*'}, payload)
svc.receive_push
msgs = svc.writable_io.string.split("\n")
assert_equal "NICK n", msgs.shift
assert_match "USER n", msgs.shift
assert_equal "JOIN #r", msgs.shift.strip
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_equal "PART #r", msgs.shift.strip
assert_equal "QUIT", msgs.shift.strip
assert_nil msgs.shift
end
def test_push_with_single_mismatching_branch_regex
svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => '^ticket*'}, payload)
svc.receive_push
msgs = svc.writable_io.string.split("\n")
assert_nil msgs.shift
end
def test_push_with_multiple_branch_regexes_where_all_match
svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => 'mast*,^ticket*'}, payload)
svc.receive_push
msgs = svc.writable_io.string.split("\n")
assert_equal "NICK n", msgs.shift
assert_match "USER n", msgs.shift
assert_equal "JOIN #r", msgs.shift.strip
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_equal "PART #r", msgs.shift.strip
assert_equal "QUIT", msgs.shift.strip
assert_nil msgs.shift
end
def test_push_with_multiple_branch_regexes_where_one_matches
svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => 'mast*,^ticket*'}, payload)
svc.receive_push
msgs = svc.writable_io.string.split("\n")
assert_equal "NICK n", msgs.shift
assert_match "USER n", msgs.shift
assert_equal "JOIN #r", msgs.shift.strip
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_equal "PART #r", msgs.shift.strip
assert_equal "QUIT", msgs.shift.strip
assert_nil msgs.shift
end
def test_push_with_multiple_branch_regexes_where_none_match
svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => '^feature*,^ticket*'}, payload)
svc.receive_push
msgs = svc.writable_io.string.split("\n")
assert_nil msgs.shift
end
def test_push_with_nickserv
svc = service({'room' => 'r', 'nick' => 'n', 'nickservidentify' => 'booya'},
payload)
svc.receive_push
msgs = svc.writable_io.string.split("\n")
assert_equal "NICK n", msgs.shift
assert_equal "MSG NICKSERV IDENTIFY booya", msgs.shift
assert_match "USER n", msgs.shift
assert_equal "JOIN #r", msgs.shift.strip
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_equal "PART #r", msgs.shift.strip
assert_equal "QUIT", msgs.shift.strip
assert_nil msgs.shift
end
def test_pull_request
svc = service(:pull_request, {'room' => 'r', 'nick' => 'n'}, pull_payload)
svc.receive_pull_request
msgs = svc.writable_io.string.split("\n")
assert_equal "NICK n", msgs.shift
assert_match "USER n", msgs.shift
assert_equal "JOIN #r", msgs.shift.strip
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_equal "PART #r", msgs.shift.strip
assert_equal "QUIT", msgs.shift.strip
assert_nil msgs.shift
end
def test_issues
svc = service(:issues, {'room' => 'r', 'nick' => 'n'}, issues_payload)
svc.receive_issues
msgs = svc.writable_io.string.split("\n")
assert_equal "NICK n", msgs.shift
assert_match "USER n", msgs.shift
assert_equal "JOIN #r", msgs.shift.strip
assert_match /PRIVMSG #r.*grit/, msgs.shift
assert_equal "PART #r", msgs.shift.strip
assert_equal "QUIT", msgs.shift.strip
assert_nil msgs.shift
end
def test_default_port_with_ssl
svc = service({'ssl' => '1'}, payload)
assert_equal 9999, svc.port
end
def test_default_port_no_ssl
svc = service({'ssl' => '0'}, payload)
assert_equal 6667, svc.port
end
def test_overridden_port
svc = service({'port' => '1234'}, payload)
assert_equal 1234, svc.port
end
def test_no_colors
# Default should include color
svc = service(:pull_request, {'room' => 'r', 'nick' => 'n'}, pull_payload)
svc.receive_pull_request
msgs = svc.writable_io.string.split("\n")
privmsg = msgs[3] # skip NICK, USER, JOIN
assert_match /PRIVMSG #r.*grit/, privmsg
assert_match /\003/, privmsg
# no_colors should strip color
svc = service(:pull_request, {'room' => 'r', 'nick' => 'n', 'no_colors' => '1'}, pull_payload)
svc.receive_pull_request
msgs = svc.writable_io.string.split("\n")
privmsg = msgs[3] # skip NICK, USER, JOIN
assert_match /PRIVMSG #r.*grit/, privmsg
assert_no_match /\003/, privmsg
end
def service(*args)
super FakeIRC, *args
end
end