zuul/tests/unit/test_push_reqs.py
Jesse Keating 71a47ff90c Extend in-repo config update support to github
The code that would look for in-repo config changes was gerrit specific.
Turn the gerrit specific bit into a generic that drivers can implement.

Implement the generic in the github driver, which required accounting
for files that are part of a push event (where code is landing in the
repo we care about).

Also remove an unnecessary fake pull request method of getPushEvent, as
there was already one in the fake github class.

Move the real updatesConfig function from the Change object to the Ref
object (since we can get a change from a ref) and move the files
attribute as well.

Introduce a test for github to verify that the tenant is reconfigured.
This required introducing a new Scheduler object attribute to track when
each tenant is reconfigured. The existing reconfiguration time tracker
was generic, and not updated via dyanmic updates.

Change-Id: Ibf59f91fa3701c15d93d859920fe3070478fe457
Story: 2000774
Task: 4664
2017-06-07 15:37:15 -07:00

57 lines
2.2 KiB
Python

# Copyright (c) 2017 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from tests.base import ZuulTestCase
class TestPushRequirements(ZuulTestCase):
config_file = 'zuul-push-reqs.conf'
tenant_config_file = 'config/push-reqs/main.yaml'
def setup_config(self):
super(TestPushRequirements, self).setup_config()
def test_push_requirements(self):
self.executor_server.hold_jobs_in_build = True
# Create a github change, add a change and emit a push event
A = self.fake_github.openFakePullRequest('org/project1', 'master', 'A')
old_sha = A.head_sha
pevent = self.fake_github.getPushEvent(project='org/project1',
ref='refs/heads/master',
old_rev=old_sha)
self.fake_github.emitEvent(pevent)
self.waitUntilSettled()
# All but one pipeline should be skipped
self.assertEqual(1, len(self.builds))
self.assertEqual('pushhub', self.builds[0].pipeline)
self.assertEqual('org/project1', self.builds[0].project)
# Make a gerrit change, and emit a ref-updated event
B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
self.fake_gerrit.addEvent(B.getRefUpdatedEvent())
self.waitUntilSettled()
# All but one pipeline should be skipped, increasing builds by 1
self.assertEqual(2, len(self.builds))
self.assertEqual('pushgerrit', self.builds[1].pipeline)
self.assertEqual('org/project2', self.builds[1].project)
self.executor_server.hold_jobs_in_build = False
self.executor_server.release()
self.waitUntilSettled()