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 | |
| 28 | # Create a github change, add a change and emit a push event |
| 29 | A = self.fake_github.openFakePullRequest('org/project1', 'master', 'A') |
| 30 | old_sha = A.head_sha |
| 31 | self.fake_github.emitEvent(A.getPushEvent(old_sha)) |
| 32 | |
| 33 | self.waitUntilSettled() |
| 34 | |
| 35 | # All but one pipeline should be skipped |
| 36 | self.assertEqual(1, len(self.builds)) |
| 37 | self.assertEqual('pushhub', self.builds[0].pipeline) |
| 38 | self.assertEqual('org/project1', self.builds[0].project) |
| 39 | |
| 40 | # Make a gerrit change, and emit a ref-updated event |
| 41 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 42 | self.fake_gerrit.addEvent(B.getRefUpdatedEvent()) |
| 43 | |
| 44 | self.waitUntilSettled() |
| 45 | |
| 46 | # All but one pipeline should be skipped, increasing builds by 1 |
| 47 | self.assertEqual(2, len(self.builds)) |
| 48 | self.assertEqual('pushgerrit', self.builds[1].pipeline) |
| 49 | self.assertEqual('org/project2', self.builds[1].project) |
| 50 | |
| 51 | self.executor_server.hold_jobs_in_build = False |
| 52 | self.executor_server.release() |
| 53 | self.waitUntilSettled() |