forked from github/janky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjanky_test.rb
348 lines (266 loc) · 9.3 KB
/
janky_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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
require File.expand_path("../test_helper", __FILE__)
class JankyTest < Test::Unit::TestCase
def setup
Janky.setup(environment)
Janky.enable_mock!
Janky.reset!
DatabaseCleaner.clean_with(:truncation)
Janky::ChatService.rooms = {1 => "enterprise", 2 => "builds"}
Janky::ChatService.default_room_name = "builds"
hubot_setup("github/github")
end
test "green build" do
Janky::Builder.green!
gh_post_receive("github")
Janky::Builder.start!
Janky::Builder.complete!
assert Janky::Notifier.success?("github", "master")
end
test "fail build" do
Janky::Builder.red!
gh_post_receive("github")
Janky::Builder.start!
Janky::Builder.complete!
assert Janky::Notifier.failure?("github", "master")
end
test "pending build" do
Janky::Builder.green!
gh_post_receive("github")
assert Janky::Notifier.empty?
Janky::Builder.start!
Janky::Builder.complete!
assert Janky::Notifier.success?("github", "master")
end
test "builds multiple repo with the same uri" do
Janky::Builder.green!
hubot_setup("github/github", "fi")
gh_post_receive("github")
Janky::Builder.start!
Janky::Builder.complete!
assert Janky::Notifier.success?("github", "master")
assert Janky::Notifier.success?("fi", "master")
end
test "notifies room that triggered the build" do
Janky::Builder.green!
gh_post_receive("github")
Janky::Builder.start!
Janky::Builder.complete!
assert Janky::Notifier.success?("github", "master", "builds")
hubot_build("github", "master", "enterprise")
Janky::Builder.start!
Janky::Builder.complete!
assert Janky::Notifier.success?("github", "master", "enterprise")
end
test "dup commit same branch" do
Janky::Builder.green!
gh_post_receive("github", "master", "sha1")
Janky::Builder.start!
Janky::Builder.complete!
assert Janky::Notifier.notifications.shift
gh_post_receive("github", "master", "sha1")
Janky::Builder.start!
Janky::Builder.complete!
assert Janky::Notifier.notifications.empty?
end
test "dup commit different branch" do
Janky::Builder.green!
gh_post_receive("github", "master", "sha1")
Janky::Builder.start!
Janky::Builder.complete!
assert Janky::Notifier.notifications.shift
gh_post_receive("github", "issues-dashboard", "sha1")
Janky::Builder.start!
Janky::Builder.complete!
assert Janky::Notifier.notifications.empty?
end
test "dup commit currently building" do
Janky::Builder.green!
gh_post_receive("github", "master", "sha1")
Janky::Builder.start!
gh_post_receive("github", "issues-dashboard", "sha1")
Janky::Builder.complete!
assert_equal 1, Janky::Notifier.notifications.size
assert Janky::Notifier.success?("github", "master")
end
test "dup commit currently red" do
Janky::Builder.red!
gh_post_receive("github", "master", "sha1")
Janky::Builder.start!
Janky::Builder.complete!
assert Janky::Notifier.notifications.shift
gh_post_receive("github", "master", "sha1")
assert Janky::Notifier.notifications.empty?
end
test "dup commit disabled repo" do
hubot_setup("github/github", "fi")
hubot_toggle("fi")
gh_post_receive("github", "master")
Janky::Builder.start!
Janky::Builder.complete!
Janky::Notifier.reset!
hubot_build("fi", "master")
Janky::Builder.start!
Janky::Builder.complete!
assert Janky::Notifier.success?("fi", "master")
end
test "web dashboard" do
assert get("/").ok?
assert get("/janky").not_found?
gh_post_receive("github")
assert get("/").ok?
assert get("/github").ok?
Janky::Builder.start!
assert get("/").ok?
Janky::Builder.complete!
assert get("/").ok?
assert get("/github").ok?
assert get("/github/master").ok?
assert get("/github/strato").ok?
assert get("#{Janky::Build.last.id}/output").ok?
end
test "hubot setup" do
Janky::GitHub.repo_make_private("github/github")
assert hubot_setup("github/github").body.
include?("git@github.com:github/github")
Janky::GitHub.repo_make_public("github/github")
assert hubot_setup("github/github").body.
include?("git://github.com/github/github")
assert_equal 1, hubot_status.body.split("\n").size
hubot_setup("github/janky")
assert_equal 2, hubot_status.body.split("\n").size
Janky::GitHub.repo_make_unauthorized("github/enterprise")
assert hubot_setup("github/enterprise").body.
include?("Couldn't access github/enterprise")
assert_equal 201, hubot_setup("janky").status
end
test "hubot toggle" do
hubot_toggle("github")
gh_post_receive("github", "master", "deadbeef")
Janky::Builder.start!
Janky::Builder.complete!
assert Janky::Notifier.empty?
hubot_toggle("github")
gh_post_receive("github", "master", "cream")
Janky::Builder.start!
Janky::Builder.complete!
assert Janky::Notifier.success?("github", "master")
end
test "hubot status" do
gh_post_receive("github")
Janky::Builder.start!
Janky::Builder.complete!
status = hubot_status.body
assert status.include?("github")
assert status.include?("green")
assert status.include?("builds")
hubot_build("github", "master")
assert hubot_status.body.include?("green")
Janky::Builder.start!
assert hubot_status.body.include?("building")
hubot_setup("github/janky")
assert hubot_status.body.include?("no build")
hubot_setup("github/team")
gh_post_receive("team")
assert hubot_status.ok?
end
test "build user" do
gh_post_receive("github", "master", "HEAD", "the dude")
Janky::Builder.start!
Janky::Builder.complete!
response = hubot_status("github", "master")
data = Yajl.load(response.body)
assert_equal 1, data.size
build = data[0]
assert_equal "the dude", build["user"]
hubot_build("github", "master", nil, "the boyscout")
Janky::Builder.start!
Janky::Builder.complete!
response = hubot_status("github", "master")
data = Yajl.load(response.body)
assert_equal 2, data.size
build = data[0]
assert_equal "the boyscout", build["user"]
end
test "hubot status repo" do
gh_post_receive("github")
payload = Yajl.load(hubot_status("github", "master").body)
assert_equal 1, payload.size
build = payload[0]
assert build["queued"]
assert build["pending"]
assert !build["building"]
Janky::Builder.start!
Janky::Builder.complete!
hubot_build("github", "master")
Janky::Builder.start!
Janky::Builder.complete!
payload = Yajl.load(hubot_status("github", "master").body)
assert_equal 2, payload.size
end
test "hubot build" do
gh_post_receive("github", "master")
Janky::Builder.start!
Janky::Builder.complete!
assert hubot_build("github", "rails3").not_found?
end
test "getting latest commit" do
gh_post_receive("github", "master")
Janky::Builder.start!
Janky::Builder.complete!
assert_not_equal "deadbeef", hubot_latest_build_sha("github", "master")
Janky::GitHub.set_branch_head("github/github", "master", "deadbeef")
hubot_build("github", "master")
Janky::Builder.start!
Janky::Builder.complete!
assert_equal "deadbeef", hubot_latest_build_sha("github", "master")
assert_equal "deadbeef", Janky::Build.last.sha1
assert_equal "Test Author <test@github.com>", Janky::Build.last.commit_author
assert_equal "Test Message", Janky::Build.last.commit_message
assert_equal "https://github.com/github/github/commit/deadbeef", Janky::Build.last.commit_url
end
test "hubot rooms" do
response = hubot_request("GET", "/_hubot/rooms")
rooms = Yajl.load(response.body)
assert_equal ["builds", "enterprise"], rooms
end
test "hubot set room" do
gh_post_receive("github", "master")
Janky::Builder.start!
Janky::Builder.complete!
assert Janky::Notifier.success?("github", "master", "builds")
Janky::Notifier.reset!
hubot_update_room("github", "enterprise").ok?
hubot_build("github", "master")
Janky::Builder.start!
Janky::Builder.complete!
assert Janky::Notifier.success?("github", "master", "enterprise")
end
test "hubot 404s" do
assert hubot_status("janky", "master").not_found?
assert hubot_build("janky", "master").not_found?
assert hubot_build("github", "master").not_found?
end
test "github owner is parsed correctly" do
repo = Janky::Repository.setup("github/janky")
assert_equal "github", repo.github_owner
assert_equal "janky", repo.github_name
end
test "owner with a dash is parsed correctly" do
repo = Janky::Repository.setup("digital-science/central-ftp-manage")
assert_equal "digital-science", repo.github_owner
assert_equal "central-ftp-manage", repo.github_name
end
test "repository with period is parsed correctly" do
repo = Janky::Repository.setup("github/pygments.rb")
assert_equal "github", repo.github_owner
assert_equal "pygments.rb", repo.github_name
end
test "build janky url" do
gh_post_receive("github")
Janky::Builder.start!
Janky::Builder.complete!
assert_equal "http://localhost:9393/1/output", Janky::Build.last.web_url
build_page = Janky::Build.last.repo_job_name + "/" + Janky::Build.last.number + "/"
assert_equal "http://localhost:8080/job/" + build_page, Janky::Build.last.url
end
end