From d1b95639b9c6a4a277419f7c5047495608fd7dc9 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Thu, 13 Feb 2020 11:00:14 -0800 Subject: Report robot comments to gerrit If there are line comments, we are supposed to always report them. However, when we added support for robot comments, we didn't update the check which determined whether to post a review. We do that if at least one of the following is true: there is a message, there is a label, there is a line comment. That should also be true if there is a robot comment (since that is a form of line comment). This updates that check and adds a test. Change-Id: Iebd6dafd9e040b6c443ebe1ed1e2702d37804399 --- tests/unit/test_gerrit.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests/unit/test_gerrit.py') diff --git a/tests/unit/test_gerrit.py b/tests/unit/test_gerrit.py index 7c328b09d..567a35f10 100644 --- a/tests/unit/test_gerrit.py +++ b/tests/unit/test_gerrit.py @@ -381,6 +381,46 @@ class TestChecksApi(ZuulTestCase): self.assertEqual(len(A.checks_history), 3) self.assertEqual(A.data['status'], 'NEW') + @simple_layout('layouts/gerrit-checks.yaml') + def test_config_error(self): + # Test that line comments are reported on config errors + in_repo_conf = textwrap.dedent( + """ + - project: + check: + jobs: + - bad-job + """) + file_dict = {'.zuul.yaml': in_repo_conf} + A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', + files=file_dict) + A.setCheck('zuul:check', reset=True) + self.waitForPoll('gerrit') + self.waitUntilSettled() + + self.assertEqual(A.checks_history[0]['zuul:check']['state'], + 'NOT_STARTED') + self.assertEqual(A.checks_history[1]['zuul:check']['state'], + 'SCHEDULED') + self.assertEqual(A.checks_history[2]['zuul:check']['state'], + 'FAILED') + self.assertEqual(len(A.checks_history), 3) + comments = sorted(A.comments, key=lambda x: x['line']) + self.assertEqual(comments[0], + {'file': '.zuul.yaml', + 'line': 5, + 'message': 'Job bad-job not defined', + 'range': {'end_character': 0, + 'end_line': 5, + 'start_character': 2, + 'start_line': 2}, + 'reviewer': {'email': 'zuul@example.com', + 'name': 'Zuul', + 'username': 'jenkins'}} + ) + self.assertEqual(A.reported, 0, "no messages should be reported") + self.assertEqual(A.messages, [], "no messages should be reported") + class TestPolling(ZuulTestCase): config_file = 'zuul-gerrit-no-stream.conf' -- cgit v1.2.1