Gregory Haynes | 4fc1254 | 2015-04-22 20:38:06 -0700 | [diff] [blame] | 1 | # Copyright 2015 GoodData |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 15 | import os |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 16 | import re |
Jamie Lennox | 3f16de5 | 2017-05-09 14:24:11 +1000 | [diff] [blame] | 17 | from testtools.matchers import MatchesRegex, StartsWith |
Tristan Cacqueray | 2bafb1f | 2017-06-12 07:10:26 +0000 | [diff] [blame] | 18 | import urllib |
Jan Hruban | 324ca5b | 2015-11-05 19:28:54 +0100 | [diff] [blame] | 19 | import time |
Gregory Haynes | 4fc1254 | 2015-04-22 20:38:06 -0700 | [diff] [blame] | 20 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 21 | import git |
| 22 | |
Wayne | 1a78c61 | 2015-06-11 17:14:13 -0700 | [diff] [blame] | 23 | from tests.base import ZuulTestCase, simple_layout, random_sha1 |
Gregory Haynes | 4fc1254 | 2015-04-22 20:38:06 -0700 | [diff] [blame] | 24 | |
Gregory Haynes | 4fc1254 | 2015-04-22 20:38:06 -0700 | [diff] [blame] | 25 | |
| 26 | class TestGithubDriver(ZuulTestCase): |
| 27 | config_file = 'zuul-github-driver.conf' |
| 28 | |
| 29 | @simple_layout('layouts/basic-github.yaml', driver='github') |
| 30 | def test_pull_event(self): |
| 31 | self.executor_server.hold_jobs_in_build = True |
| 32 | |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 33 | A = self.fake_github.openFakePullRequest('org/project', 'master', 'A') |
| 34 | self.fake_github.emitEvent(A.getPullRequestOpenedEvent()) |
Gregory Haynes | 4fc1254 | 2015-04-22 20:38:06 -0700 | [diff] [blame] | 35 | self.waitUntilSettled() |
| 36 | |
Gregory Haynes | 4fc1254 | 2015-04-22 20:38:06 -0700 | [diff] [blame] | 37 | self.executor_server.hold_jobs_in_build = False |
| 38 | self.executor_server.release() |
| 39 | self.waitUntilSettled() |
| 40 | |
| 41 | self.assertEqual('SUCCESS', |
| 42 | self.getJobFromHistory('project-test1').result) |
| 43 | self.assertEqual('SUCCESS', |
| 44 | self.getJobFromHistory('project-test2').result) |
| 45 | |
| 46 | job = self.getJobFromHistory('project-test2') |
Monty Taylor | d13bc36 | 2017-06-30 13:11:37 -0500 | [diff] [blame] | 47 | zuulvars = job.parameters['zuul'] |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 48 | self.assertEqual(str(A.number), zuulvars['change']) |
| 49 | self.assertEqual(str(A.head_sha), zuulvars['patchset']) |
James E. Blair | 3b22249 | 2017-07-21 15:17:37 -0700 | [diff] [blame] | 50 | self.assertEqual('master', zuulvars['branch']) |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 51 | self.assertEqual(1, len(A.comments)) |
Jan Hruban | d4edee8 | 2015-12-16 12:49:51 +0100 | [diff] [blame] | 52 | self.assertEqual(2, len(self.history)) |
| 53 | |
| 54 | # test_pull_unmatched_branch_event(self): |
| 55 | self.create_branch('org/project', 'unmatched_branch') |
| 56 | B = self.fake_github.openFakePullRequest( |
| 57 | 'org/project', 'unmatched_branch', 'B') |
| 58 | self.fake_github.emitEvent(B.getPullRequestOpenedEvent()) |
| 59 | self.waitUntilSettled() |
| 60 | |
| 61 | self.assertEqual(2, len(self.history)) |
Wayne | 1a78c61 | 2015-06-11 17:14:13 -0700 | [diff] [blame] | 62 | |
Jan Hruban | 570d01c | 2016-03-10 21:51:32 +0100 | [diff] [blame] | 63 | @simple_layout('layouts/files-github.yaml', driver='github') |
| 64 | def test_pull_matched_file_event(self): |
| 65 | A = self.fake_github.openFakePullRequest( |
| 66 | 'org/project', 'master', 'A', |
| 67 | files=['random.txt', 'build-requires']) |
| 68 | self.fake_github.emitEvent(A.getPullRequestOpenedEvent()) |
| 69 | self.waitUntilSettled() |
| 70 | self.assertEqual(1, len(self.history)) |
| 71 | |
| 72 | # test_pull_unmatched_file_event |
| 73 | B = self.fake_github.openFakePullRequest('org/project', 'master', 'B', |
| 74 | files=['random.txt']) |
| 75 | self.fake_github.emitEvent(B.getPullRequestOpenedEvent()) |
| 76 | self.waitUntilSettled() |
| 77 | self.assertEqual(1, len(self.history)) |
| 78 | |
Jan Hruban | c7ab160 | 2015-10-14 15:29:33 +0200 | [diff] [blame] | 79 | @simple_layout('layouts/basic-github.yaml', driver='github') |
| 80 | def test_comment_event(self): |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 81 | A = self.fake_github.openFakePullRequest('org/project', 'master', 'A') |
| 82 | self.fake_github.emitEvent(A.getCommentAddedEvent('test me')) |
Jan Hruban | c7ab160 | 2015-10-14 15:29:33 +0200 | [diff] [blame] | 83 | self.waitUntilSettled() |
| 84 | self.assertEqual(2, len(self.history)) |
| 85 | |
| 86 | # Test an unmatched comment, history should remain the same |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 87 | B = self.fake_github.openFakePullRequest('org/project', 'master', 'B') |
| 88 | self.fake_github.emitEvent(B.getCommentAddedEvent('casual comment')) |
Jan Hruban | c7ab160 | 2015-10-14 15:29:33 +0200 | [diff] [blame] | 89 | self.waitUntilSettled() |
| 90 | self.assertEqual(2, len(self.history)) |
| 91 | |
Wayne | 1a78c61 | 2015-06-11 17:14:13 -0700 | [diff] [blame] | 92 | @simple_layout('layouts/push-tag-github.yaml', driver='github') |
| 93 | def test_tag_event(self): |
| 94 | self.executor_server.hold_jobs_in_build = True |
| 95 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 96 | self.create_branch('org/project', 'tagbranch') |
| 97 | files = {'README.txt': 'test'} |
| 98 | self.addCommitToRepo('org/project', 'test tag', |
| 99 | files, branch='tagbranch', tag='newtag') |
| 100 | path = os.path.join(self.upstream_root, 'org/project') |
| 101 | repo = git.Repo(path) |
| 102 | tag = repo.tags['newtag'] |
| 103 | sha = tag.commit.hexsha |
| 104 | del repo |
| 105 | |
Wayne | 1a78c61 | 2015-06-11 17:14:13 -0700 | [diff] [blame] | 106 | self.fake_github.emitEvent( |
| 107 | self.fake_github.getPushEvent('org/project', 'refs/tags/newtag', |
| 108 | new_rev=sha)) |
| 109 | self.waitUntilSettled() |
| 110 | |
| 111 | build_params = self.builds[0].parameters |
James E. Blair | a438c17 | 2017-07-21 14:54:42 -0700 | [diff] [blame] | 112 | self.assertEqual('refs/tags/newtag', build_params['zuul']['ref']) |
Wayne | 1a78c61 | 2015-06-11 17:14:13 -0700 | [diff] [blame] | 113 | self.assertEqual('00000000000000000000000000000000', |
James E. Blair | ed8b001 | 2017-07-21 14:49:29 -0700 | [diff] [blame] | 114 | build_params['zuul']['oldrev']) |
| 115 | self.assertEqual(sha, build_params['zuul']['newrev']) |
Wayne | 1a78c61 | 2015-06-11 17:14:13 -0700 | [diff] [blame] | 116 | |
| 117 | self.executor_server.hold_jobs_in_build = False |
| 118 | self.executor_server.release() |
| 119 | self.waitUntilSettled() |
| 120 | |
| 121 | self.assertEqual('SUCCESS', |
| 122 | self.getJobFromHistory('project-tag').result) |
| 123 | |
| 124 | @simple_layout('layouts/push-tag-github.yaml', driver='github') |
| 125 | def test_push_event(self): |
| 126 | self.executor_server.hold_jobs_in_build = True |
| 127 | |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 128 | A = self.fake_github.openFakePullRequest('org/project', 'master', 'A') |
| 129 | old_sha = '0' * 40 |
| 130 | new_sha = A.head_sha |
| 131 | A.setMerged("merging A") |
| 132 | pevent = self.fake_github.getPushEvent(project='org/project', |
| 133 | ref='refs/heads/master', |
| 134 | old_rev=old_sha, |
| 135 | new_rev=new_sha) |
| 136 | self.fake_github.emitEvent(pevent) |
Wayne | 1a78c61 | 2015-06-11 17:14:13 -0700 | [diff] [blame] | 137 | self.waitUntilSettled() |
| 138 | |
| 139 | build_params = self.builds[0].parameters |
James E. Blair | a438c17 | 2017-07-21 14:54:42 -0700 | [diff] [blame] | 140 | self.assertEqual('refs/heads/master', build_params['zuul']['ref']) |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 141 | self.assertFalse('oldrev' in build_params['zuul']) |
James E. Blair | ed8b001 | 2017-07-21 14:49:29 -0700 | [diff] [blame] | 142 | self.assertEqual(new_sha, build_params['zuul']['newrev']) |
Wayne | 1a78c61 | 2015-06-11 17:14:13 -0700 | [diff] [blame] | 143 | |
| 144 | self.executor_server.hold_jobs_in_build = False |
| 145 | self.executor_server.release() |
| 146 | self.waitUntilSettled() |
| 147 | |
| 148 | self.assertEqual('SUCCESS', |
| 149 | self.getJobFromHistory('project-post').result) |
Jan Hruban | d4edee8 | 2015-12-16 12:49:51 +0100 | [diff] [blame] | 150 | self.assertEqual(1, len(self.history)) |
| 151 | |
| 152 | # test unmatched push event |
| 153 | old_sha = random_sha1() |
| 154 | new_sha = random_sha1() |
| 155 | self.fake_github.emitEvent( |
| 156 | self.fake_github.getPushEvent('org/project', |
| 157 | 'refs/heads/unmatched_branch', |
| 158 | old_sha, new_sha)) |
| 159 | self.waitUntilSettled() |
| 160 | |
| 161 | self.assertEqual(1, len(self.history)) |
Jan Hruban | 6d53c5e | 2015-10-24 03:03:34 +0200 | [diff] [blame] | 162 | |
Jan Hruban | 16ad31f | 2015-11-07 14:39:07 +0100 | [diff] [blame] | 163 | @simple_layout('layouts/labeling-github.yaml', driver='github') |
| 164 | def test_labels(self): |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 165 | A = self.fake_github.openFakePullRequest('org/project', 'master', 'A') |
Jan Hruban | 16ad31f | 2015-11-07 14:39:07 +0100 | [diff] [blame] | 166 | self.fake_github.emitEvent(A.addLabel('test')) |
| 167 | self.waitUntilSettled() |
| 168 | self.assertEqual(1, len(self.history)) |
| 169 | self.assertEqual('project-labels', self.history[0].name) |
| 170 | self.assertEqual(['tests passed'], A.labels) |
| 171 | |
| 172 | # test label removed |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 173 | B = self.fake_github.openFakePullRequest('org/project', 'master', 'B') |
Jan Hruban | 16ad31f | 2015-11-07 14:39:07 +0100 | [diff] [blame] | 174 | B.addLabel('do not test') |
| 175 | self.fake_github.emitEvent(B.removeLabel('do not test')) |
| 176 | self.waitUntilSettled() |
| 177 | self.assertEqual(2, len(self.history)) |
| 178 | self.assertEqual('project-labels', self.history[1].name) |
| 179 | self.assertEqual(['tests passed'], B.labels) |
| 180 | |
| 181 | # test unmatched label |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 182 | C = self.fake_github.openFakePullRequest('org/project', 'master', 'C') |
Jan Hruban | 16ad31f | 2015-11-07 14:39:07 +0100 | [diff] [blame] | 183 | self.fake_github.emitEvent(C.addLabel('other label')) |
| 184 | self.waitUntilSettled() |
| 185 | self.assertEqual(2, len(self.history)) |
| 186 | self.assertEqual(['other label'], C.labels) |
| 187 | |
Jesse Keating | 5c05a9f | 2017-01-12 14:44:58 -0800 | [diff] [blame] | 188 | @simple_layout('layouts/reviews-github.yaml', driver='github') |
| 189 | def test_review_event(self): |
| 190 | A = self.fake_github.openFakePullRequest('org/project', 'master', 'A') |
| 191 | self.fake_github.emitEvent(A.getReviewAddedEvent('approve')) |
| 192 | self.waitUntilSettled() |
| 193 | self.assertEqual(1, len(self.history)) |
| 194 | self.assertEqual('project-reviews', self.history[0].name) |
| 195 | self.assertEqual(['tests passed'], A.labels) |
| 196 | |
| 197 | # test_review_unmatched_event |
| 198 | B = self.fake_github.openFakePullRequest('org/project', 'master', 'B') |
| 199 | self.fake_github.emitEvent(B.getReviewAddedEvent('comment')) |
| 200 | self.waitUntilSettled() |
| 201 | self.assertEqual(1, len(self.history)) |
| 202 | |
Jan Hruban | 324ca5b | 2015-11-05 19:28:54 +0100 | [diff] [blame] | 203 | @simple_layout('layouts/dequeue-github.yaml', driver='github') |
| 204 | def test_dequeue_pull_synchronized(self): |
| 205 | self.executor_server.hold_jobs_in_build = True |
| 206 | |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 207 | A = self.fake_github.openFakePullRequest( |
| 208 | 'org/one-job-project', 'master', 'A') |
| 209 | self.fake_github.emitEvent(A.getPullRequestOpenedEvent()) |
Jan Hruban | 324ca5b | 2015-11-05 19:28:54 +0100 | [diff] [blame] | 210 | self.waitUntilSettled() |
| 211 | |
| 212 | # event update stamp has resolution one second, wait so the latter |
| 213 | # one has newer timestamp |
| 214 | time.sleep(1) |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 215 | A.addCommit() |
| 216 | self.fake_github.emitEvent(A.getPullRequestSynchronizeEvent()) |
Jan Hruban | 324ca5b | 2015-11-05 19:28:54 +0100 | [diff] [blame] | 217 | self.waitUntilSettled() |
| 218 | |
| 219 | self.executor_server.hold_jobs_in_build = False |
| 220 | self.executor_server.release() |
| 221 | self.waitUntilSettled() |
| 222 | |
| 223 | self.assertEqual(2, len(self.history)) |
| 224 | self.assertEqual(1, self.countJobResults(self.history, 'ABORTED')) |
| 225 | |
| 226 | @simple_layout('layouts/dequeue-github.yaml', driver='github') |
| 227 | def test_dequeue_pull_abandoned(self): |
| 228 | self.executor_server.hold_jobs_in_build = True |
| 229 | |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 230 | A = self.fake_github.openFakePullRequest( |
| 231 | 'org/one-job-project', 'master', 'A') |
| 232 | self.fake_github.emitEvent(A.getPullRequestOpenedEvent()) |
Jan Hruban | 324ca5b | 2015-11-05 19:28:54 +0100 | [diff] [blame] | 233 | self.waitUntilSettled() |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 234 | self.fake_github.emitEvent(A.getPullRequestClosedEvent()) |
Jan Hruban | 324ca5b | 2015-11-05 19:28:54 +0100 | [diff] [blame] | 235 | self.waitUntilSettled() |
| 236 | |
| 237 | self.executor_server.hold_jobs_in_build = False |
| 238 | self.executor_server.release() |
| 239 | self.waitUntilSettled() |
| 240 | |
| 241 | self.assertEqual(1, len(self.history)) |
| 242 | self.assertEqual(1, self.countJobResults(self.history, 'ABORTED')) |
| 243 | |
Jan Hruban | 6d53c5e | 2015-10-24 03:03:34 +0200 | [diff] [blame] | 244 | @simple_layout('layouts/basic-github.yaml', driver='github') |
| 245 | def test_git_https_url(self): |
| 246 | """Test that git_ssh option gives git url with ssh""" |
| 247 | url = self.fake_github.real_getGitUrl('org/project') |
| 248 | self.assertEqual('https://github.com/org/project', url) |
| 249 | |
| 250 | @simple_layout('layouts/basic-github.yaml', driver='github') |
| 251 | def test_git_ssh_url(self): |
| 252 | """Test that git_ssh option gives git url with ssh""" |
| 253 | url = self.fake_github_ssh.real_getGitUrl('org/project') |
| 254 | self.assertEqual('ssh://git@github.com/org/project.git', url) |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 255 | |
Jesse Keating | be4ef8a | 2016-12-06 11:29:13 -0800 | [diff] [blame] | 256 | @simple_layout('layouts/basic-github.yaml', driver='github') |
| 257 | def test_git_enterprise_url(self): |
| 258 | """Test that git_url option gives git url with proper host""" |
| 259 | url = self.fake_github_ent.real_getGitUrl('org/project') |
| 260 | self.assertEqual('ssh://git@github.enterprise.io/org/project.git', url) |
| 261 | |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 262 | @simple_layout('layouts/reporting-github.yaml', driver='github') |
| 263 | def test_reporting(self): |
Jesse Keating | 1f7ebe9 | 2017-06-12 17:21:00 -0700 | [diff] [blame] | 264 | project = 'org/project' |
Tobias Henkel | 3c17d5f | 2017-08-03 11:46:54 +0200 | [diff] [blame] | 265 | github = self.fake_github.github_client |
| 266 | |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 267 | # pipeline reports pull status both on start and success |
| 268 | self.executor_server.hold_jobs_in_build = True |
Jesse Keating | 1f7ebe9 | 2017-06-12 17:21:00 -0700 | [diff] [blame] | 269 | A = self.fake_github.openFakePullRequest(project, 'master', 'A') |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 270 | self.fake_github.emitEvent(A.getPullRequestOpenedEvent()) |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 271 | self.waitUntilSettled() |
Tobias Henkel | 3c17d5f | 2017-08-03 11:46:54 +0200 | [diff] [blame] | 272 | |
Jesse Keating | d96e588 | 2017-01-19 13:55:50 -0800 | [diff] [blame] | 273 | # We should have a status container for the head sha |
Tobias Henkel | 3c17d5f | 2017-08-03 11:46:54 +0200 | [diff] [blame] | 274 | self.assertIn( |
| 275 | A.head_sha, github.repo_from_project(project)._commits.keys()) |
| 276 | statuses = self.fake_github.getCommitStatuses(project, A.head_sha) |
| 277 | |
Jesse Keating | d96e588 | 2017-01-19 13:55:50 -0800 | [diff] [blame] | 278 | # We should only have one status for the head sha |
Jesse Keating | 1f7ebe9 | 2017-06-12 17:21:00 -0700 | [diff] [blame] | 279 | self.assertEqual(1, len(statuses)) |
| 280 | check_status = statuses[0] |
Jan Hruban | ddeb95a | 2017-01-03 15:12:41 +0100 | [diff] [blame] | 281 | check_url = ('http://zuul.example.com/status/#%s,%s' % |
| 282 | (A.number, A.head_sha)) |
Jamie Lennox | 18bc7ed | 2017-05-10 10:37:55 +1000 | [diff] [blame] | 283 | self.assertEqual('tenant-one/check', check_status['context']) |
Jesse Keating | fb6cc99 | 2017-08-01 14:18:13 -0700 | [diff] [blame] | 284 | self.assertEqual('check status: pending', |
| 285 | check_status['description']) |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 286 | self.assertEqual('pending', check_status['state']) |
Jan Hruban | ddeb95a | 2017-01-03 15:12:41 +0100 | [diff] [blame] | 287 | self.assertEqual(check_url, check_status['url']) |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 288 | self.assertEqual(0, len(A.comments)) |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 289 | |
| 290 | self.executor_server.hold_jobs_in_build = False |
| 291 | self.executor_server.release() |
| 292 | self.waitUntilSettled() |
Jesse Keating | d96e588 | 2017-01-19 13:55:50 -0800 | [diff] [blame] | 293 | # We should only have two statuses for the head sha |
Tobias Henkel | 3c17d5f | 2017-08-03 11:46:54 +0200 | [diff] [blame] | 294 | statuses = self.fake_github.getCommitStatuses(project, A.head_sha) |
Jesse Keating | 1f7ebe9 | 2017-06-12 17:21:00 -0700 | [diff] [blame] | 295 | self.assertEqual(2, len(statuses)) |
| 296 | check_status = statuses[0] |
Jesse Keating | d96e588 | 2017-01-19 13:55:50 -0800 | [diff] [blame] | 297 | check_url = ('http://zuul.example.com/status/#%s,%s' % |
| 298 | (A.number, A.head_sha)) |
Jamie Lennox | 18bc7ed | 2017-05-10 10:37:55 +1000 | [diff] [blame] | 299 | self.assertEqual('tenant-one/check', check_status['context']) |
Jesse Keating | fb6cc99 | 2017-08-01 14:18:13 -0700 | [diff] [blame] | 300 | self.assertEqual('check status: success', |
| 301 | check_status['description']) |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 302 | self.assertEqual('success', check_status['state']) |
Jan Hruban | ddeb95a | 2017-01-03 15:12:41 +0100 | [diff] [blame] | 303 | self.assertEqual(check_url, check_status['url']) |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 304 | self.assertEqual(1, len(A.comments)) |
| 305 | self.assertThat(A.comments[0], |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 306 | MatchesRegex('.*Build succeeded.*', re.DOTALL)) |
| 307 | |
| 308 | # pipeline does not report any status but does comment |
| 309 | self.executor_server.hold_jobs_in_build = True |
| 310 | self.fake_github.emitEvent( |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 311 | A.getCommentAddedEvent('reporting check')) |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 312 | self.waitUntilSettled() |
Tobias Henkel | 3c17d5f | 2017-08-03 11:46:54 +0200 | [diff] [blame] | 313 | statuses = self.fake_github.getCommitStatuses(project, A.head_sha) |
Jesse Keating | 1f7ebe9 | 2017-06-12 17:21:00 -0700 | [diff] [blame] | 314 | self.assertEqual(2, len(statuses)) |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 315 | # comments increased by one for the start message |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 316 | self.assertEqual(2, len(A.comments)) |
| 317 | self.assertThat(A.comments[1], |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 318 | MatchesRegex('.*Starting reporting jobs.*', re.DOTALL)) |
| 319 | self.executor_server.hold_jobs_in_build = False |
| 320 | self.executor_server.release() |
| 321 | self.waitUntilSettled() |
Jesse Keating | d96e588 | 2017-01-19 13:55:50 -0800 | [diff] [blame] | 322 | # pipeline reports success status |
Tobias Henkel | 3c17d5f | 2017-08-03 11:46:54 +0200 | [diff] [blame] | 323 | statuses = self.fake_github.getCommitStatuses(project, A.head_sha) |
Jesse Keating | 1f7ebe9 | 2017-06-12 17:21:00 -0700 | [diff] [blame] | 324 | self.assertEqual(3, len(statuses)) |
| 325 | report_status = statuses[0] |
Jamie Lennox | 18bc7ed | 2017-05-10 10:37:55 +1000 | [diff] [blame] | 326 | self.assertEqual('tenant-one/reporting', report_status['context']) |
Jesse Keating | fb6cc99 | 2017-08-01 14:18:13 -0700 | [diff] [blame] | 327 | self.assertEqual('reporting status: success', |
| 328 | report_status['description']) |
Jesse Keating | d96e588 | 2017-01-19 13:55:50 -0800 | [diff] [blame] | 329 | self.assertEqual('success', report_status['state']) |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 330 | self.assertEqual(2, len(A.comments)) |
Jamie Lennox | 3f16de5 | 2017-05-09 14:24:11 +1000 | [diff] [blame] | 331 | |
| 332 | base = 'http://logs.example.com/tenant-one/reporting/%s/%s/' % ( |
| 333 | A.project, A.number) |
| 334 | |
| 335 | # Deconstructing the URL because we don't save the BuildSet UUID |
| 336 | # anywhere to do a direct comparison and doing regexp matches on a full |
| 337 | # URL is painful. |
| 338 | |
| 339 | # The first part of the URL matches the easy base string |
| 340 | self.assertThat(report_status['url'], StartsWith(base)) |
| 341 | |
| 342 | # The rest of the URL is a UUID and a trailing slash. |
| 343 | self.assertThat(report_status['url'][len(base):], |
| 344 | MatchesRegex('^[a-fA-F0-9]{32}\/$')) |
Jan Hruban | 49bff07 | 2015-11-03 11:45:46 +0100 | [diff] [blame] | 345 | |
Jesse Keating | 08dab8f | 2017-06-21 12:59:23 +0100 | [diff] [blame] | 346 | @simple_layout('layouts/reporting-github.yaml', driver='github') |
Jesse Keating | fb6cc99 | 2017-08-01 14:18:13 -0700 | [diff] [blame] | 347 | def test_truncated_status_description(self): |
| 348 | project = 'org/project' |
| 349 | # pipeline reports pull status both on start and success |
| 350 | self.executor_server.hold_jobs_in_build = True |
| 351 | A = self.fake_github.openFakePullRequest(project, 'master', 'A') |
| 352 | self.fake_github.emitEvent( |
| 353 | A.getCommentAddedEvent('long pipeline')) |
| 354 | self.waitUntilSettled() |
Tobias Henkel | 3c17d5f | 2017-08-03 11:46:54 +0200 | [diff] [blame] | 355 | statuses = self.fake_github.getCommitStatuses(project, A.head_sha) |
Jesse Keating | fb6cc99 | 2017-08-01 14:18:13 -0700 | [diff] [blame] | 356 | self.assertEqual(1, len(statuses)) |
| 357 | check_status = statuses[0] |
| 358 | # Status is truncated due to long pipeline name |
| 359 | self.assertEqual('status: pending', |
| 360 | check_status['description']) |
| 361 | |
| 362 | self.executor_server.hold_jobs_in_build = False |
| 363 | self.executor_server.release() |
| 364 | self.waitUntilSettled() |
| 365 | # We should only have two statuses for the head sha |
Tobias Henkel | 3c17d5f | 2017-08-03 11:46:54 +0200 | [diff] [blame] | 366 | statuses = self.fake_github.getCommitStatuses(project, A.head_sha) |
Jesse Keating | fb6cc99 | 2017-08-01 14:18:13 -0700 | [diff] [blame] | 367 | self.assertEqual(2, len(statuses)) |
| 368 | check_status = statuses[0] |
| 369 | # Status is truncated due to long pipeline name |
| 370 | self.assertEqual('status: success', |
| 371 | check_status['description']) |
| 372 | |
| 373 | @simple_layout('layouts/reporting-github.yaml', driver='github') |
Jesse Keating | 08dab8f | 2017-06-21 12:59:23 +0100 | [diff] [blame] | 374 | def test_push_reporting(self): |
| 375 | project = 'org/project2' |
| 376 | # pipeline reports pull status both on start and success |
| 377 | self.executor_server.hold_jobs_in_build = True |
Jesse Keating | 08dab8f | 2017-06-21 12:59:23 +0100 | [diff] [blame] | 378 | |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 379 | A = self.fake_github.openFakePullRequest(project, 'master', 'A') |
| 380 | old_sha = '0' * 40 |
| 381 | new_sha = A.head_sha |
| 382 | A.setMerged("merging A") |
| 383 | pevent = self.fake_github.getPushEvent(project=project, |
| 384 | ref='refs/heads/master', |
| 385 | old_rev=old_sha, |
| 386 | new_rev=new_sha) |
Jesse Keating | 08dab8f | 2017-06-21 12:59:23 +0100 | [diff] [blame] | 387 | self.fake_github.emitEvent(pevent) |
| 388 | self.waitUntilSettled() |
| 389 | |
| 390 | # there should only be one report, a status |
| 391 | self.assertEqual(1, len(self.fake_github.reports)) |
| 392 | # Verify the user/context/state of the status |
| 393 | status = ('zuul', 'tenant-one/push-reporting', 'pending') |
| 394 | self.assertEqual(status, self.fake_github.reports[0][-1]) |
| 395 | |
| 396 | # free the executor, allow the build to finish |
| 397 | self.executor_server.hold_jobs_in_build = False |
| 398 | self.executor_server.release() |
| 399 | self.waitUntilSettled() |
| 400 | |
| 401 | # Now there should be a second report, the success of the build |
| 402 | self.assertEqual(2, len(self.fake_github.reports)) |
| 403 | # Verify the user/context/state of the status |
| 404 | status = ('zuul', 'tenant-one/push-reporting', 'success') |
| 405 | self.assertEqual(status, self.fake_github.reports[-1][-1]) |
| 406 | |
| 407 | # now make a PR which should also comment |
| 408 | self.executor_server.hold_jobs_in_build = True |
| 409 | A = self.fake_github.openFakePullRequest(project, 'master', 'A') |
| 410 | self.fake_github.emitEvent(A.getPullRequestOpenedEvent()) |
| 411 | self.waitUntilSettled() |
| 412 | |
| 413 | # Now there should be a four reports, a new comment |
| 414 | # and status |
| 415 | self.assertEqual(4, len(self.fake_github.reports)) |
| 416 | self.executor_server.release() |
| 417 | self.waitUntilSettled() |
| 418 | |
Jan Hruban | 49bff07 | 2015-11-03 11:45:46 +0100 | [diff] [blame] | 419 | @simple_layout('layouts/merging-github.yaml', driver='github') |
| 420 | def test_report_pull_merge(self): |
| 421 | # pipeline merges the pull request on success |
Jan Hruban | 3b41592 | 2016-02-03 13:10:22 +0100 | [diff] [blame] | 422 | A = self.fake_github.openFakePullRequest('org/project', 'master', |
| 423 | 'PR title') |
Jan Hruban | 49bff07 | 2015-11-03 11:45:46 +0100 | [diff] [blame] | 424 | self.fake_github.emitEvent(A.getCommentAddedEvent('merge me')) |
| 425 | self.waitUntilSettled() |
| 426 | self.assertTrue(A.is_merged) |
Jan Hruban | 3b41592 | 2016-02-03 13:10:22 +0100 | [diff] [blame] | 427 | self.assertThat(A.merge_message, |
| 428 | MatchesRegex('.*PR title.*Reviewed-by.*', re.DOTALL)) |
Jan Hruban | 49bff07 | 2015-11-03 11:45:46 +0100 | [diff] [blame] | 429 | |
| 430 | # pipeline merges the pull request on success after failure |
| 431 | self.fake_github.merge_failure = True |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 432 | B = self.fake_github.openFakePullRequest('org/project', 'master', 'B') |
Jan Hruban | 49bff07 | 2015-11-03 11:45:46 +0100 | [diff] [blame] | 433 | self.fake_github.emitEvent(B.getCommentAddedEvent('merge me')) |
| 434 | self.waitUntilSettled() |
| 435 | self.assertFalse(B.is_merged) |
| 436 | self.fake_github.merge_failure = False |
| 437 | |
| 438 | # pipeline merges the pull request on second run of merge |
| 439 | # first merge failed on 405 Method Not Allowed error |
| 440 | self.fake_github.merge_not_allowed_count = 1 |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 441 | C = self.fake_github.openFakePullRequest('org/project', 'master', 'C') |
Jan Hruban | 49bff07 | 2015-11-03 11:45:46 +0100 | [diff] [blame] | 442 | self.fake_github.emitEvent(C.getCommentAddedEvent('merge me')) |
| 443 | self.waitUntilSettled() |
| 444 | self.assertTrue(C.is_merged) |
| 445 | |
| 446 | # pipeline does not merge the pull request |
| 447 | # merge failed on 405 Method Not Allowed error - twice |
| 448 | self.fake_github.merge_not_allowed_count = 2 |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 449 | D = self.fake_github.openFakePullRequest('org/project', 'master', 'D') |
Jan Hruban | 49bff07 | 2015-11-03 11:45:46 +0100 | [diff] [blame] | 450 | self.fake_github.emitEvent(D.getCommentAddedEvent('merge me')) |
| 451 | self.waitUntilSettled() |
| 452 | self.assertFalse(D.is_merged) |
Adam Gandelman | 62198cb | 2017-02-14 16:11:02 -0800 | [diff] [blame] | 453 | self.assertEqual(len(D.comments), 1) |
| 454 | self.assertEqual(D.comments[0], 'Merge failed') |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 455 | |
Jesse Keating | 2843431 | 2017-07-31 11:32:48 -0700 | [diff] [blame] | 456 | @simple_layout('layouts/reporting-multiple-github.yaml', driver='github') |
| 457 | def test_reporting_multiple_github(self): |
| 458 | project = 'org/project1' |
Tobias Henkel | 3c17d5f | 2017-08-03 11:46:54 +0200 | [diff] [blame] | 459 | github = self.fake_github.github_client |
| 460 | |
Jesse Keating | 2843431 | 2017-07-31 11:32:48 -0700 | [diff] [blame] | 461 | # pipeline reports pull status both on start and success |
| 462 | self.executor_server.hold_jobs_in_build = True |
| 463 | A = self.fake_github.openFakePullRequest(project, 'master', 'A') |
| 464 | self.fake_github.emitEvent(A.getPullRequestOpenedEvent()) |
| 465 | # open one on B as well, which should not effect A reporting |
| 466 | B = self.fake_github.openFakePullRequest('org/project2', 'master', |
| 467 | 'B') |
| 468 | self.fake_github.emitEvent(B.getPullRequestOpenedEvent()) |
| 469 | self.waitUntilSettled() |
| 470 | # We should have a status container for the head sha |
Tobias Henkel | 3c17d5f | 2017-08-03 11:46:54 +0200 | [diff] [blame] | 471 | statuses = self.fake_github.getCommitStatuses(project, A.head_sha) |
| 472 | self.assertIn( |
| 473 | A.head_sha, github.repo_from_project(project)._commits.keys()) |
Jesse Keating | 2843431 | 2017-07-31 11:32:48 -0700 | [diff] [blame] | 474 | # We should only have one status for the head sha |
| 475 | self.assertEqual(1, len(statuses)) |
| 476 | check_status = statuses[0] |
| 477 | check_url = ('http://zuul.example.com/status/#%s,%s' % |
| 478 | (A.number, A.head_sha)) |
| 479 | self.assertEqual('tenant-one/check', check_status['context']) |
Jesse Keating | fb6cc99 | 2017-08-01 14:18:13 -0700 | [diff] [blame] | 480 | self.assertEqual('check status: pending', check_status['description']) |
Jesse Keating | 2843431 | 2017-07-31 11:32:48 -0700 | [diff] [blame] | 481 | self.assertEqual('pending', check_status['state']) |
| 482 | self.assertEqual(check_url, check_status['url']) |
| 483 | self.assertEqual(0, len(A.comments)) |
| 484 | |
| 485 | self.executor_server.hold_jobs_in_build = False |
| 486 | self.executor_server.release() |
| 487 | self.waitUntilSettled() |
| 488 | # We should only have two statuses for the head sha |
Tobias Henkel | 3c17d5f | 2017-08-03 11:46:54 +0200 | [diff] [blame] | 489 | statuses = self.fake_github.getCommitStatuses(project, A.head_sha) |
Jesse Keating | 2843431 | 2017-07-31 11:32:48 -0700 | [diff] [blame] | 490 | self.assertEqual(2, len(statuses)) |
| 491 | check_status = statuses[0] |
| 492 | check_url = ('http://zuul.example.com/status/#%s,%s' % |
| 493 | (A.number, A.head_sha)) |
| 494 | self.assertEqual('tenant-one/check', check_status['context']) |
| 495 | self.assertEqual('success', check_status['state']) |
Jesse Keating | fb6cc99 | 2017-08-01 14:18:13 -0700 | [diff] [blame] | 496 | self.assertEqual('check status: success', check_status['description']) |
Jesse Keating | 2843431 | 2017-07-31 11:32:48 -0700 | [diff] [blame] | 497 | self.assertEqual(check_url, check_status['url']) |
| 498 | self.assertEqual(1, len(A.comments)) |
| 499 | self.assertThat(A.comments[0], |
| 500 | MatchesRegex('.*Build succeeded.*', re.DOTALL)) |
| 501 | |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 502 | @simple_layout('layouts/dependent-github.yaml', driver='github') |
| 503 | def test_parallel_changes(self): |
| 504 | "Test that changes are tested in parallel and merged in series" |
| 505 | |
| 506 | self.executor_server.hold_jobs_in_build = True |
| 507 | A = self.fake_github.openFakePullRequest('org/project', 'master', 'A') |
| 508 | B = self.fake_github.openFakePullRequest('org/project', 'master', 'B') |
| 509 | C = self.fake_github.openFakePullRequest('org/project', 'master', 'C') |
| 510 | |
| 511 | self.fake_github.emitEvent(A.addLabel('merge')) |
| 512 | self.fake_github.emitEvent(B.addLabel('merge')) |
| 513 | self.fake_github.emitEvent(C.addLabel('merge')) |
| 514 | |
| 515 | self.waitUntilSettled() |
| 516 | self.assertEqual(len(self.builds), 1) |
| 517 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 518 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 519 | |
| 520 | self.executor_server.release('.*-merge') |
| 521 | self.waitUntilSettled() |
| 522 | self.assertEqual(len(self.builds), 3) |
| 523 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 524 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 525 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 526 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 527 | self.assertEqual(self.builds[2].name, 'project-merge') |
| 528 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
| 529 | |
| 530 | self.executor_server.release('.*-merge') |
| 531 | self.waitUntilSettled() |
| 532 | self.assertEqual(len(self.builds), 5) |
| 533 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 534 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 535 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 536 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 537 | |
| 538 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 539 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 540 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 541 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
| 542 | |
| 543 | self.assertEqual(self.builds[4].name, 'project-merge') |
| 544 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
| 545 | |
| 546 | self.executor_server.release('.*-merge') |
| 547 | self.waitUntilSettled() |
| 548 | self.assertEqual(len(self.builds), 6) |
| 549 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 550 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 551 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 552 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 553 | |
| 554 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 555 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
| 556 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 557 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
| 558 | |
| 559 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 560 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
| 561 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 562 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
| 563 | |
| 564 | all_builds = self.builds[:] |
| 565 | self.release(all_builds[2]) |
| 566 | self.release(all_builds[3]) |
| 567 | self.waitUntilSettled() |
| 568 | self.assertFalse(A.is_merged) |
| 569 | self.assertFalse(B.is_merged) |
| 570 | self.assertFalse(C.is_merged) |
| 571 | |
| 572 | self.release(all_builds[0]) |
| 573 | self.release(all_builds[1]) |
| 574 | self.waitUntilSettled() |
| 575 | self.assertTrue(A.is_merged) |
| 576 | self.assertTrue(B.is_merged) |
| 577 | self.assertFalse(C.is_merged) |
| 578 | |
| 579 | self.executor_server.hold_jobs_in_build = False |
| 580 | self.executor_server.release() |
| 581 | self.waitUntilSettled() |
| 582 | self.assertEqual(len(self.builds), 0) |
| 583 | self.assertEqual(len(self.history), 9) |
| 584 | self.assertTrue(C.is_merged) |
| 585 | |
| 586 | self.assertNotIn('merge', A.labels) |
| 587 | self.assertNotIn('merge', B.labels) |
| 588 | self.assertNotIn('merge', C.labels) |
| 589 | |
| 590 | @simple_layout('layouts/dependent-github.yaml', driver='github') |
| 591 | def test_failed_changes(self): |
| 592 | "Test that a change behind a failed change is retested" |
| 593 | self.executor_server.hold_jobs_in_build = True |
| 594 | |
| 595 | A = self.fake_github.openFakePullRequest('org/project', 'master', 'A') |
| 596 | B = self.fake_github.openFakePullRequest('org/project', 'master', 'B') |
| 597 | |
| 598 | self.executor_server.failJob('project-test1', A) |
| 599 | |
| 600 | self.fake_github.emitEvent(A.addLabel('merge')) |
| 601 | self.fake_github.emitEvent(B.addLabel('merge')) |
| 602 | self.waitUntilSettled() |
| 603 | |
| 604 | self.executor_server.release('.*-merge') |
| 605 | self.waitUntilSettled() |
| 606 | |
| 607 | self.executor_server.hold_jobs_in_build = False |
| 608 | self.executor_server.release() |
| 609 | |
| 610 | self.waitUntilSettled() |
| 611 | # It's certain that the merge job for change 2 will run, but |
| 612 | # the test1 and test2 jobs may or may not run. |
| 613 | self.assertTrue(len(self.history) > 6) |
| 614 | self.assertFalse(A.is_merged) |
| 615 | self.assertTrue(B.is_merged) |
| 616 | self.assertNotIn('merge', A.labels) |
| 617 | self.assertNotIn('merge', B.labels) |
| 618 | |
| 619 | @simple_layout('layouts/dependent-github.yaml', driver='github') |
| 620 | def test_failed_change_at_head(self): |
| 621 | "Test that if a change at the head fails, jobs behind it are canceled" |
| 622 | |
| 623 | self.executor_server.hold_jobs_in_build = True |
| 624 | A = self.fake_github.openFakePullRequest('org/project', 'master', 'A') |
| 625 | B = self.fake_github.openFakePullRequest('org/project', 'master', 'B') |
| 626 | C = self.fake_github.openFakePullRequest('org/project', 'master', 'C') |
| 627 | |
| 628 | self.executor_server.failJob('project-test1', A) |
| 629 | |
| 630 | self.fake_github.emitEvent(A.addLabel('merge')) |
| 631 | self.fake_github.emitEvent(B.addLabel('merge')) |
| 632 | self.fake_github.emitEvent(C.addLabel('merge')) |
| 633 | |
| 634 | self.waitUntilSettled() |
| 635 | |
| 636 | self.assertEqual(len(self.builds), 1) |
| 637 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 638 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 639 | |
| 640 | self.executor_server.release('.*-merge') |
| 641 | self.waitUntilSettled() |
| 642 | self.executor_server.release('.*-merge') |
| 643 | self.waitUntilSettled() |
| 644 | self.executor_server.release('.*-merge') |
| 645 | self.waitUntilSettled() |
| 646 | |
| 647 | self.assertEqual(len(self.builds), 6) |
| 648 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 649 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 650 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 651 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 652 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 653 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 654 | |
| 655 | self.release(self.builds[0]) |
| 656 | self.waitUntilSettled() |
| 657 | |
| 658 | # project-test2, project-merge for B |
| 659 | self.assertEqual(len(self.builds), 2) |
| 660 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
| 661 | |
| 662 | self.executor_server.hold_jobs_in_build = False |
| 663 | self.executor_server.release() |
| 664 | self.waitUntilSettled() |
| 665 | |
| 666 | self.assertEqual(len(self.builds), 0) |
| 667 | self.assertEqual(len(self.history), 15) |
| 668 | self.assertFalse(A.is_merged) |
| 669 | self.assertTrue(B.is_merged) |
| 670 | self.assertTrue(C.is_merged) |
| 671 | self.assertNotIn('merge', A.labels) |
| 672 | self.assertNotIn('merge', B.labels) |
| 673 | self.assertNotIn('merge', C.labels) |
Jesse Keating | 71a47ff | 2017-06-06 11:36:43 -0700 | [diff] [blame] | 674 | |
| 675 | @simple_layout('layouts/basic-github.yaml', driver='github') |
| 676 | def test_push_event_reconfigure(self): |
Tobias Henkel | 3c17d5f | 2017-08-03 11:46:54 +0200 | [diff] [blame] | 677 | pevent = self.fake_github.getPushEvent(project='org/common-config', |
Jesse Keating | 71a47ff | 2017-06-06 11:36:43 -0700 | [diff] [blame] | 678 | ref='refs/heads/master', |
| 679 | modified_files=['zuul.yaml']) |
| 680 | |
| 681 | # record previous tenant reconfiguration time, which may not be set |
| 682 | old = self.sched.tenant_last_reconfigured.get('tenant-one', 0) |
| 683 | time.sleep(1) |
| 684 | self.fake_github.emitEvent(pevent) |
| 685 | self.waitUntilSettled() |
| 686 | new = self.sched.tenant_last_reconfigured.get('tenant-one', 0) |
| 687 | # New timestamp should be greater than the old timestamp |
| 688 | self.assertLess(old, new) |
Tristan Cacqueray | 2bafb1f | 2017-06-12 07:10:26 +0000 | [diff] [blame] | 689 | |
| 690 | @simple_layout('layouts/basic-github.yaml', driver='github') |
| 691 | def test_ping_event(self): |
| 692 | # Test valid ping |
| 693 | pevent = {'repository': {'full_name': 'org/project'}} |
| 694 | req = self.fake_github.emitEvent(('ping', pevent)) |
| 695 | self.assertEqual(req.status, 200, "Ping event didn't succeed") |
| 696 | |
| 697 | # Test invalid ping |
| 698 | pevent = {'repository': {'full_name': 'unknown-project'}} |
| 699 | self.assertRaises( |
| 700 | urllib.error.HTTPError, |
| 701 | self.fake_github.emitEvent, |
| 702 | ('ping', pevent), |
| 703 | ) |
Tobias Henkel | eca4620 | 2017-08-02 20:27:10 +0200 | [diff] [blame] | 704 | |
| 705 | |
| 706 | class TestGithubUnprotectedBranches(ZuulTestCase): |
| 707 | config_file = 'zuul-github-driver.conf' |
| 708 | tenant_config_file = 'config/unprotected-branches/main.yaml' |
| 709 | |
| 710 | def test_unprotected_branches(self): |
| 711 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 712 | |
| 713 | project1 = tenant.untrusted_projects[0] |
| 714 | project2 = tenant.untrusted_projects[1] |
| 715 | |
| 716 | # project1 should have parsed master |
| 717 | self.assertIn('master', project1.unparsed_branch_config.keys()) |
| 718 | |
| 719 | # project2 should have no parsed branch |
| 720 | self.assertEqual(0, len(project2.unparsed_branch_config.keys())) |