Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 1 | # 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 | |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 15 | from tests.base import ZuulTestCase |
| 16 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 17 | |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 18 | class TestConnections(ZuulTestCase): |
Morgan Fainberg | 4245a42 | 2016-08-05 16:20:12 -0700 | [diff] [blame] | 19 | config_file = 'zuul-connections-same-gerrit.conf' |
| 20 | tenant_config_file = 'config/zuul-connections-same-gerrit/main.yaml' |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 21 | |
| 22 | def test_multiple_connections(self): |
| 23 | "Test multiple connections to the one gerrit" |
| 24 | |
| 25 | A = self.fake_review_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 7fc8daa | 2016-08-08 15:37:15 -0700 | [diff] [blame] | 26 | self.addEvent('review_gerrit', A.getPatchsetCreatedEvent(1)) |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 27 | |
| 28 | self.waitUntilSettled() |
| 29 | |
| 30 | self.assertEqual(len(A.patchsets[-1]['approvals']), 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 31 | self.assertEqual(A.patchsets[-1]['approvals'][0]['type'], 'verified') |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 32 | self.assertEqual(A.patchsets[-1]['approvals'][0]['value'], '1') |
| 33 | self.assertEqual(A.patchsets[-1]['approvals'][0]['by']['username'], |
| 34 | 'jenkins') |
| 35 | |
| 36 | B = self.fake_review_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | a5dba23 | 2016-08-08 15:53:24 -0700 | [diff] [blame] | 37 | self.launch_server.failJob('project-test2', B) |
James E. Blair | 7fc8daa | 2016-08-08 15:37:15 -0700 | [diff] [blame] | 38 | self.addEvent('review_gerrit', B.getPatchsetCreatedEvent(1)) |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 39 | |
| 40 | self.waitUntilSettled() |
| 41 | |
| 42 | self.assertEqual(len(B.patchsets[-1]['approvals']), 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 43 | self.assertEqual(B.patchsets[-1]['approvals'][0]['type'], 'verified') |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 44 | self.assertEqual(B.patchsets[-1]['approvals'][0]['value'], '-1') |
| 45 | self.assertEqual(B.patchsets[-1]['approvals'][0]['by']['username'], |
| 46 | 'civoter') |
| 47 | |
| 48 | |
| 49 | class TestMultipleGerrits(ZuulTestCase): |
James E. Blair | 509cada | 2015-12-08 16:31:16 -0800 | [diff] [blame] | 50 | |
Jamie Lennox | d2e3733 | 2016-12-05 15:26:19 +1100 | [diff] [blame] | 51 | config_file = 'zuul-connections-multiple-gerrits.conf' |
| 52 | tenant_config_file = 'config/zuul-connections-multiple-gerrits/main.yaml' |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 53 | |
| 54 | def test_multiple_project_separate_gerrits(self): |
Jamie Lennox | d2e3733 | 2016-12-05 15:26:19 +1100 | [diff] [blame] | 55 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 56 | |
| 57 | A = self.fake_another_gerrit.addFakeChange( |
Jamie Lennox | d2e3733 | 2016-12-05 15:26:19 +1100 | [diff] [blame] | 58 | 'org/project1', 'master', 'A') |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 59 | self.fake_another_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 60 | |
| 61 | self.waitUntilSettled() |
| 62 | |
Jamie Lennox | d2e3733 | 2016-12-05 15:26:19 +1100 | [diff] [blame] | 63 | self.assertBuilds([dict(name='project-test2', |
| 64 | changes='1,1', |
| 65 | project='org/project1', |
| 66 | pipeline='another_check')]) |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 67 | |
Jamie Lennox | d2e3733 | 2016-12-05 15:26:19 +1100 | [diff] [blame] | 68 | # NOTE(jamielennox): the tests back the git repo for both connections |
| 69 | # onto the same git repo on the file system. If we just create another |
| 70 | # fake change the fake_review_gerrit will try to create another 1,1 |
| 71 | # change and git will fail to create the ref. Arbitrarily set it to get |
| 72 | # around the problem. |
| 73 | self.fake_review_gerrit.change_number = 50 |
| 74 | |
| 75 | B = self.fake_review_gerrit.addFakeChange( |
| 76 | 'org/project1', 'master', 'B') |
| 77 | self.fake_review_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 78 | |
| 79 | self.waitUntilSettled() |
| 80 | |
| 81 | self.assertBuilds([ |
| 82 | dict(name='project-test2', |
| 83 | changes='1,1', |
| 84 | project='org/project1', |
| 85 | pipeline='another_check'), |
| 86 | dict(name='project-test1', |
| 87 | changes='51,1', |
| 88 | project='org/project1', |
| 89 | pipeline='review_check'), |
| 90 | ]) |
| 91 | |
| 92 | self.launch_server.hold_jobs_in_build = False |
| 93 | self.launch_server.release() |
Joshua Hesketh | acccffc | 2015-03-31 23:38:17 +1100 | [diff] [blame] | 94 | self.waitUntilSettled() |