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