blob: 80c3be97c17652743152c7da0ba2d40e238c8ca9 [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
Jesse Keating8c2eb572017-05-30 17:31:45 -070028 A = self.fake_github.openFakePullRequest('org/project1', 'master', 'A')
James E. Blair289f5932017-07-27 15:02:29 -070029 new_sha = A.head_sha
30 A.setMerged("merging A")
Jesse Keating71a47ff2017-06-06 11:36:43 -070031 pevent = self.fake_github.getPushEvent(project='org/project1',
32 ref='refs/heads/master',
James E. Blair289f5932017-07-27 15:02:29 -070033 new_rev=new_sha)
34
Jesse Keating71a47ff2017-06-06 11:36:43 -070035 self.fake_github.emitEvent(pevent)
Jesse Keating8c2eb572017-05-30 17:31:45 -070036
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. Blair289f5932017-07-27 15:02:29 -070047 B.setMerged()
Jesse Keating8c2eb572017-05-30 17:31:45 -070048 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()