| OLD | NEW |
| (Empty) |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """Unit tests for tools/validate_config.py.""" | |
| 6 | |
| 7 import mock | |
| 8 import os | |
| 9 import unittest | |
| 10 | |
| 11 from cq_client import cq_pb2 | |
| 12 from cq_client import validate_config | |
| 13 | |
| 14 | |
| 15 TEST_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| 16 | |
| 17 | |
| 18 class TestValidateConfig(unittest.TestCase): | |
| 19 def test_is_valid_rietveld(self): | |
| 20 with open(os.path.join(TEST_DIR, 'cq_rietveld.cfg'), 'r') as test_config: | |
| 21 self.assertTrue(validate_config.IsValid(test_config.read())) | |
| 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 | |
| 37 def test_has_field(self): | |
| 38 config = cq_pb2.Config() | |
| 39 | |
| 40 self.assertFalse(validate_config._HasField(config, 'version')) | |
| 41 config.version = 1 | |
| 42 self.assertTrue(validate_config._HasField(config, 'version')) | |
| 43 | |
| 44 self.assertFalse(validate_config._HasField( | |
| 45 config, 'rietveld.project_bases')) | |
| 46 config.rietveld.project_bases.append('foo://bar') | |
| 47 self.assertTrue(validate_config._HasField( | |
| 48 config, 'rietveld.project_bases')) | |
| 49 | |
| 50 self.assertFalse(validate_config._HasField( | |
| 51 config, 'verifiers.try_job.buckets')) | |
| 52 self.assertFalse(validate_config._HasField( | |
| 53 config, 'verifiers.try_job.buckets.name')) | |
| 54 | |
| 55 bucket = config.verifiers.try_job.buckets.add() | |
| 56 bucket.name = 'tryserver.chromium.linux' | |
| 57 | |
| 58 | |
| 59 self.assertTrue(validate_config._HasField( | |
| 60 config, 'verifiers.try_job.buckets')) | |
| 61 self.assertTrue(validate_config._HasField( | |
| 62 config, 'verifiers.try_job.buckets.name')) | |
| 63 | |
| 64 config.verifiers.try_job.buckets.add() | |
| 65 self.assertFalse(validate_config._HasField( | |
| 66 config, 'verifiers.try_job.buckets.name')) | |
| OLD | NEW |