blob: d386ae49a62b6f52ecd42e90e89ff6a81c3bf2cd [file] [log] [blame]
Gregory Haynes4fc12542015-04-22 20:38:06 -07001# Copyright 2015 GoodData
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
15import logging
16
Wayne1a78c612015-06-11 17:14:13 -070017from tests.base import ZuulTestCase, simple_layout, random_sha1
Gregory Haynes4fc12542015-04-22 20:38:06 -070018
19logging.basicConfig(level=logging.DEBUG,
20 format='%(asctime)s %(name)-32s '
21 '%(levelname)-8s %(message)s')
22
23
24class TestGithubDriver(ZuulTestCase):
25 config_file = 'zuul-github-driver.conf'
26
27 @simple_layout('layouts/basic-github.yaml', driver='github')
28 def test_pull_event(self):
29 self.executor_server.hold_jobs_in_build = True
30
31 pr = self.fake_github.openFakePullRequest('org/project', 'master')
32 self.fake_github.emitEvent(pr.getPullRequestOpenedEvent())
33 self.waitUntilSettled()
34
35 build_params = self.builds[0].parameters
36 self.assertEqual('master', build_params['ZUUL_BRANCH'])
37 self.assertEqual(str(pr.number), build_params['ZUUL_CHANGE'])
38 self.assertEqual(pr.head_sha, build_params['ZUUL_PATCHSET'])
39
40 self.executor_server.hold_jobs_in_build = False
41 self.executor_server.release()
42 self.waitUntilSettled()
43
44 self.assertEqual('SUCCESS',
45 self.getJobFromHistory('project-test1').result)
46 self.assertEqual('SUCCESS',
47 self.getJobFromHistory('project-test2').result)
48
49 job = self.getJobFromHistory('project-test2')
50 zuulvars = job.parameters['vars']['zuul']
51 self.assertEqual(pr.number, zuulvars['change'])
52 self.assertEqual(pr.head_sha, zuulvars['patchset'])
Wayne40f40042015-06-12 16:56:30 -070053 self.assertEqual(1, len(pr.comments))
Wayne1a78c612015-06-11 17:14:13 -070054
55 @simple_layout('layouts/push-tag-github.yaml', driver='github')
56 def test_tag_event(self):
57 self.executor_server.hold_jobs_in_build = True
58
59 sha = random_sha1()
60 self.fake_github.emitEvent(
61 self.fake_github.getPushEvent('org/project', 'refs/tags/newtag',
62 new_rev=sha))
63 self.waitUntilSettled()
64
65 build_params = self.builds[0].parameters
66 self.assertEqual('refs/tags/newtag', build_params['ZUUL_REF'])
67 self.assertEqual('00000000000000000000000000000000',
68 build_params['ZUUL_OLDREV'])
69 self.assertEqual(sha, build_params['ZUUL_NEWREV'])
70
71 self.executor_server.hold_jobs_in_build = False
72 self.executor_server.release()
73 self.waitUntilSettled()
74
75 self.assertEqual('SUCCESS',
76 self.getJobFromHistory('project-tag').result)
77
78 @simple_layout('layouts/push-tag-github.yaml', driver='github')
79 def test_push_event(self):
80 self.executor_server.hold_jobs_in_build = True
81
82 old_sha = random_sha1()
83 new_sha = random_sha1()
84 self.fake_github.emitEvent(
85 self.fake_github.getPushEvent('org/project', 'refs/heads/master',
86 old_sha, new_sha))
87 self.waitUntilSettled()
88
89 build_params = self.builds[0].parameters
90 self.assertEqual('refs/heads/master', build_params['ZUUL_REF'])
91 self.assertEqual(old_sha, build_params['ZUUL_OLDREV'])
92 self.assertEqual(new_sha, build_params['ZUUL_NEWREV'])
93
94 self.executor_server.hold_jobs_in_build = False
95 self.executor_server.release()
96 self.waitUntilSettled()
97
98 self.assertEqual('SUCCESS',
99 self.getJobFromHistory('project-post').result)