| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Unit tests for tools/validate_config.py.""" | 5 """Unit tests for tools/validate_config.py.""" |
| 6 | 6 |
| 7 import mock | 7 import mock |
| 8 import os | 8 import os |
| 9 import unittest | 9 import unittest |
| 10 | 10 |
| 11 from cq_client import cq_pb2 | 11 from cq_client import cq_pb2 |
| 12 from cq_client import validate_config | 12 from cq_client import validate_config |
| 13 | 13 |
| 14 | 14 |
| 15 TEST_DIR = os.path.dirname(os.path.abspath(__file__)) | 15 TEST_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 16 | 16 |
| 17 | 17 |
| 18 class TestValidateConfig(unittest.TestCase): | 18 class TestValidateConfig(unittest.TestCase): |
| 19 def test_is_valid(self): | 19 def test_is_valid_rietveld(self): |
| 20 with open(os.path.join(TEST_DIR, 'cq_example.cfg'), 'r') as test_config: | 20 with open(os.path.join(TEST_DIR, 'cq_rietveld.cfg'), 'r') as test_config: |
| 21 self.assertTrue(validate_config.IsValid(test_config.read())) | 21 self.assertTrue(validate_config.IsValid(test_config.read())) |
| 22 | 22 |
| 23 def test_is_valid_gerrit(self): |
| 24 with open(os.path.join(TEST_DIR, 'cq_gerrit.cfg'), 'r') as test_config: |
| 25 self.assertTrue(validate_config.IsValid(test_config.read())) |
| 26 |
| 27 def test_one_codereview(self): |
| 28 with open(os.path.join(TEST_DIR, 'cq_gerrit.cfg'), 'r') as gerrit_config: |
| 29 data = gerrit_config.read() |
| 30 data += '\n'.join([ |
| 31 'rietveld{', |
| 32 'url: "https://blabla.com"', |
| 33 '}' |
| 34 ]) |
| 35 self.assertFalse(validate_config.IsValid(data)) |
| 36 |
| 23 def test_has_field(self): | 37 def test_has_field(self): |
| 24 config = cq_pb2.Config() | 38 config = cq_pb2.Config() |
| 25 | 39 |
| 26 self.assertFalse(validate_config._HasField(config, 'version')) | 40 self.assertFalse(validate_config._HasField(config, 'version')) |
| 27 config.version = 1 | 41 config.version = 1 |
| 28 self.assertTrue(validate_config._HasField(config, 'version')) | 42 self.assertTrue(validate_config._HasField(config, 'version')) |
| 29 | 43 |
| 30 self.assertFalse(validate_config._HasField( | 44 self.assertFalse(validate_config._HasField( |
| 31 config, 'rietveld.project_bases')) | 45 config, 'rietveld.project_bases')) |
| 32 config.rietveld.project_bases.append('foo://bar') | 46 config.rietveld.project_bases.append('foo://bar') |
| (...skipping 10 matching lines...) Expand all Loading... |
| 43 | 57 |
| 44 | 58 |
| 45 self.assertTrue(validate_config._HasField( | 59 self.assertTrue(validate_config._HasField( |
| 46 config, 'verifiers.try_job.buckets')) | 60 config, 'verifiers.try_job.buckets')) |
| 47 self.assertTrue(validate_config._HasField( | 61 self.assertTrue(validate_config._HasField( |
| 48 config, 'verifiers.try_job.buckets.name')) | 62 config, 'verifiers.try_job.buckets.name')) |
| 49 | 63 |
| 50 config.verifiers.try_job.buckets.add() | 64 config.verifiers.try_job.buckets.add() |
| 51 self.assertFalse(validate_config._HasField( | 65 self.assertFalse(validate_config._HasField( |
| 52 config, 'verifiers.try_job.buckets.name')) | 66 config, 'verifiers.try_job.buckets.name')) |
| OLD | NEW |