blob: b3c133cadc51564b58248fe959595bf985de162b [file] [log] [blame]
Joshua Hesketh352264b2015-08-11 23:42:08 +10001# Copyright 2014 Rackspace Australia
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
16import testtools
17
18import zuul.connection.gerrit
19
Joshua Heskethacccffc2015-03-31 23:38:17 +110020from tests.base import ZuulTestCase
21
Joshua Hesketh352264b2015-08-11 23:42:08 +100022
23class TestGerritConnection(testtools.TestCase):
24 log = logging.getLogger("zuul.test_connection")
25
26 def test_driver_name(self):
27 self.assertEqual('gerrit',
28 zuul.connection.gerrit.GerritConnection.driver_name)
Joshua Heskethacccffc2015-03-31 23:38:17 +110029
30
31class TestConnections(ZuulTestCase):
Morgan Fainberg4245a422016-08-05 16:20:12 -070032 config_file = 'zuul-connections-same-gerrit.conf'
33 tenant_config_file = 'config/zuul-connections-same-gerrit/main.yaml'
Joshua Heskethacccffc2015-03-31 23:38:17 +110034
35 def test_multiple_connections(self):
36 "Test multiple connections to the one gerrit"
37
38 A = self.fake_review_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair7fc8daa2016-08-08 15:37:15 -070039 self.addEvent('review_gerrit', A.getPatchsetCreatedEvent(1))
Joshua Heskethacccffc2015-03-31 23:38:17 +110040
41 self.waitUntilSettled()
42
43 self.assertEqual(len(A.patchsets[-1]['approvals']), 1)
James E. Blair8b5408c2016-08-08 15:37:46 -070044 self.assertEqual(A.patchsets[-1]['approvals'][0]['type'], 'verified')
Joshua Heskethacccffc2015-03-31 23:38:17 +110045 self.assertEqual(A.patchsets[-1]['approvals'][0]['value'], '1')
46 self.assertEqual(A.patchsets[-1]['approvals'][0]['by']['username'],
47 'jenkins')
48
49 B = self.fake_review_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blaira5dba232016-08-08 15:53:24 -070050 self.launch_server.failJob('project-test2', B)
James E. Blair7fc8daa2016-08-08 15:37:15 -070051 self.addEvent('review_gerrit', B.getPatchsetCreatedEvent(1))
Joshua Heskethacccffc2015-03-31 23:38:17 +110052
53 self.waitUntilSettled()
54
55 self.assertEqual(len(B.patchsets[-1]['approvals']), 1)
James E. Blair8b5408c2016-08-08 15:37:46 -070056 self.assertEqual(B.patchsets[-1]['approvals'][0]['type'], 'verified')
Joshua Heskethacccffc2015-03-31 23:38:17 +110057 self.assertEqual(B.patchsets[-1]['approvals'][0]['value'], '-1')
58 self.assertEqual(B.patchsets[-1]['approvals'][0]['by']['username'],
59 'civoter')
60
61
62class TestMultipleGerrits(ZuulTestCase):
James E. Blair509cada2015-12-08 16:31:16 -080063 def setUp(self):
64 self.skip("Disabled for early v3 development")
65
Joshua Heskethacccffc2015-03-31 23:38:17 +110066 def setup_config(self,
67 config_file='zuul-connections-multiple-gerrits.conf'):
68 super(TestMultipleGerrits, self).setup_config(config_file)
James E. Blairf84026c2015-12-08 16:11:46 -080069 self.self.updateConfigLayout(
Joshua Heskethacccffc2015-03-31 23:38:17 +110070 'layout-connections-multiple-gerrits.yaml')
71
72 def test_multiple_project_separate_gerrits(self):
73 self.worker.hold_jobs_in_build = True
74
75 A = self.fake_another_gerrit.addFakeChange(
76 'org/project', 'master', 'A')
77 self.fake_another_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
78
79 self.waitUntilSettled()
80
81 self.assertEqual(1, len(self.builds))
82 self.assertEqual('project-another-gerrit', self.builds[0].name)
83 self.assertTrue(self.job_has_changes(self.builds[0], A))
84
85 self.worker.hold_jobs_in_build = False
86 self.worker.release()
87 self.waitUntilSettled()