blob: d3a1febe8c2a40d23f59bdc56d09d54b4402bbae [file] [log] [blame]
Jesse Keating8c2eb572017-05-30 17:31:45 -07001# 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
15from tests.base import ZuulTestCase
16
17
18class 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
Jesse Keating71a47ff2017-06-06 11:36:43 -070031 pevent = self.fake_github.getPushEvent(project='org/project1',
32 ref='refs/heads/master',
33 old_rev=old_sha)
34 self.fake_github.emitEvent(pevent)
Jesse Keating8c2eb572017-05-30 17:31:45 -070035
36 self.waitUntilSettled()
37
38 # All but one pipeline should be skipped
39 self.assertEqual(1, len(self.builds))
40 self.assertEqual('pushhub', self.builds[0].pipeline)
41 self.assertEqual('org/project1', self.builds[0].project)
42
43 # Make a gerrit change, and emit a ref-updated event
44 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
45 self.fake_gerrit.addEvent(B.getRefUpdatedEvent())
46
47 self.waitUntilSettled()
48
49 # All but one pipeline should be skipped, increasing builds by 1
50 self.assertEqual(2, len(self.builds))
51 self.assertEqual('pushgerrit', self.builds[1].pipeline)
52 self.assertEqual('org/project2', self.builds[1].project)
53
54 self.executor_server.hold_jobs_in_build = False
55 self.executor_server.release()
56 self.waitUntilSettled()