blob: a3831ff951c4b73a0586e987f2aec44a04fc5fc0 [file] [log] [blame]
Jesse Keatingd96e5882017-01-19 13:55:50 -08001#!/usr/bin/env python
2# Copyright (c) 2017 IBM Corp.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from tests.base import ZuulTestCase, simple_layout
17
18
19class TestGithubRequirements(ZuulTestCase):
20 """Test pipeline and trigger requirements"""
21 config_file = 'zuul-github-driver.conf'
22
23 @simple_layout('layouts/requirements-github.yaml', driver='github')
24 def test_pipeline_require_status(self):
25 "Test pipeline requirement: status"
26 A = self.fake_github.openFakePullRequest('org/project1', 'master', 'A')
27 # A comment event that we will keep submitting to trigger
28 comment = A.getCommentAddedEvent('test me')
29 self.fake_github.emitEvent(comment)
30 self.waitUntilSettled()
31 # No status from zuul so should not be enqueued
32 self.assertEqual(len(self.history), 0)
33
34 # An error status should not cause it to be enqueued
35 A.setStatus(A.head_sha, 'error', 'null', 'null', 'check')
36 self.fake_github.emitEvent(comment)
37 self.waitUntilSettled()
38 self.assertEqual(len(self.history), 0)
39
40 # A success status goes in
41 A.setStatus(A.head_sha, 'success', 'null', 'null', 'check')
42 self.fake_github.emitEvent(comment)
43 self.waitUntilSettled()
44 self.assertEqual(len(self.history), 1)
45 self.assertEqual(self.history[0].name, 'project1-pipeline')
Adam Gandelman8c6eeb52017-01-23 16:31:06 -080046
47 @simple_layout('layouts/requirements-github.yaml', driver='github')
48 def test_trigger_require_status(self):
49 "Test trigger requirement: status"
50 A = self.fake_github.openFakePullRequest('org/project2', 'master', 'A')
51
52 # An error status should not cause it to be enqueued
53 A.setStatus(A.head_sha, 'error', 'null', 'null', 'check')
54 self.fake_github.emitEvent(A.getCommitStatusEvent('check',
55 state='error'))
56 self.waitUntilSettled()
57 self.assertEqual(len(self.history), 0)
58
59 # An success status from unknown user should not cause it to be
60 # enqueued
61 A.setStatus(A.head_sha, 'success', 'null', 'null', 'check', user='foo')
62 self.fake_github.emitEvent(A.getCommitStatusEvent('check',
63 state='success',
64 user='foo'))
65 self.waitUntilSettled()
66 self.assertEqual(len(self.history), 0)
67
68 # A success status goes in
69 A.setStatus(A.head_sha, 'success', 'null', 'null', 'check')
70 self.fake_github.emitEvent(A.getCommitStatusEvent('check'))
71 self.waitUntilSettled()
72 self.assertEqual(len(self.history), 1)
73 self.assertEqual(self.history[0].name, 'project2-trigger')
74
75 # An error status for a different context should not cause it to be
76 # enqueued
77 A.setStatus(A.head_sha, 'error', 'null', 'null', 'gate')
78 self.fake_github.emitEvent(A.getCommitStatusEvent('gate',
79 state='error'))
80 self.waitUntilSettled()
81 self.assertEqual(len(self.history), 1)