Jesse Keating | 8c2eb57 | 2017-05-30 17:31:45 -0700 | [diff] [blame] | 1 | # Copyright (c) 2017 IBM Corp. |
| 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 | |
| 15 | from tests.base import ZuulTestCase |
| 16 | |
| 17 | |
| 18 | class TestPushRequirements(ZuulTestCase): |
| 19 | config_file = 'zuul-push-reqs.conf' |
| 20 | tenant_config_file = 'config/push-reqs/main.yaml' |
| 21 | |
| 22 | def setup_config(self): |
| 23 | super(TestPushRequirements, self).setup_config() |
| 24 | |
| 25 | def test_push_requirements(self): |
| 26 | self.executor_server.hold_jobs_in_build = True |
| 27 | |
Jesse Keating | 8c2eb57 | 2017-05-30 17:31:45 -0700 | [diff] [blame] | 28 | A = self.fake_github.openFakePullRequest('org/project1', 'master', 'A') |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 29 | new_sha = A.head_sha |
| 30 | A.setMerged("merging A") |
Jesse Keating | 71a47ff | 2017-06-06 11:36:43 -0700 | [diff] [blame] | 31 | pevent = self.fake_github.getPushEvent(project='org/project1', |
| 32 | ref='refs/heads/master', |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 33 | new_rev=new_sha) |
| 34 | |
Jesse Keating | 71a47ff | 2017-06-06 11:36:43 -0700 | [diff] [blame] | 35 | self.fake_github.emitEvent(pevent) |
Jesse Keating | 8c2eb57 | 2017-05-30 17:31:45 -0700 | [diff] [blame] | 36 | |
| 37 | self.waitUntilSettled() |
| 38 | |
| 39 | # All but one pipeline should be skipped |
| 40 | self.assertEqual(1, len(self.builds)) |
| 41 | self.assertEqual('pushhub', self.builds[0].pipeline) |
| 42 | self.assertEqual('org/project1', self.builds[0].project) |
| 43 | |
| 44 | # Make a gerrit change, and emit a ref-updated event |
| 45 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 46 | self.fake_gerrit.addEvent(B.getRefUpdatedEvent()) |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 47 | B.setMerged() |
Jesse Keating | 8c2eb57 | 2017-05-30 17:31:45 -0700 | [diff] [blame] | 48 | self.waitUntilSettled() |
| 49 | |
| 50 | # All but one pipeline should be skipped, increasing builds by 1 |
| 51 | self.assertEqual(2, len(self.builds)) |
| 52 | self.assertEqual('pushgerrit', self.builds[1].pipeline) |
| 53 | self.assertEqual('org/project2', self.builds[1].project) |
| 54 | |
| 55 | self.executor_server.hold_jobs_in_build = False |
| 56 | self.executor_server.release() |
| 57 | self.waitUntilSettled() |