OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # coding: utf-8 |
| 3 # Copyright 2016 The LUCI Authors. All rights reserved. |
| 4 # Use of this source code is governed under the Apache License, Version 2.0 |
| 5 # that can be found in the LICENSE file. |
| 6 |
| 7 import collections |
| 8 import logging |
| 9 import re |
| 10 import sys |
| 11 import unittest |
| 12 |
| 13 # Setups environment. |
| 14 import test_env_handlers |
| 15 |
| 16 import cipd |
| 17 import swarming_rpcs |
| 18 |
| 19 |
| 20 class TestPinChecker(unittest.TestCase): |
| 21 def setUp(self): |
| 22 super(TestPinChecker, self).setUp() |
| 23 self.cp = collections.namedtuple('CipdPackage', 'path package_name version') |
| 24 |
| 25 def test_correct_pins(self): |
| 26 a = self.cp('path', 'package_name/${platform}-${os_ver}', 'latest') |
| 27 b = self.cp('path', 'package_name/windows-amd64-something_10', 'deadbeef'*5) |
| 28 |
| 29 with cipd.pin_check_fn(None, None) as check: |
| 30 # will not raise |
| 31 check(a, b) |
| 32 |
| 33 a = self.cp('path', 'other/${platform}-${os_ver}', 'latest') |
| 34 b = self.cp('path', 'other/windows-amd64-something_10', 'deadbeef'*5) |
| 35 |
| 36 # will not raise |
| 37 check(a, b) |
| 38 |
| 39 def test_mismatched_pins(self): |
| 40 # if a is already a pin, b must match its version exactly |
| 41 a = self.cp('path', 'package_name/${platform}-${os_ver}', 'deadbeef'*5) |
| 42 b = self.cp('path', 'package_name/windows-amd64-something_10', 'badc0ffe'*5) |
| 43 |
| 44 with cipd.pin_check_fn(None, None) as check: |
| 45 with self.assertRaisesRegexp(ValueError, 'Mismatched pins'): |
| 46 check(a, b) |
| 47 |
| 48 def test_mismatched_paths(self): |
| 49 a = self.cp('path', 'package_name/${platform}-${os_ver}', 'latest') |
| 50 b = self.cp('else', 'package_name/windows-amd64-something_10', 'deadbeef'*5) |
| 51 |
| 52 with cipd.pin_check_fn(None, None) as check: |
| 53 with self.assertRaisesRegexp(ValueError, 'Mismatched path'): |
| 54 check(a, b) |
| 55 |
| 56 def test_mismatched_names(self): |
| 57 a = self.cp('', 'package_name/${platform}-${os_ver}', 'latest') |
| 58 b = self.cp('', 'else/windows-amd64-something_10', 'deadbeef'*5) |
| 59 |
| 60 with cipd.pin_check_fn(None, None) as check: |
| 61 with self.assertRaisesRegexp(ValueError, 'Mismatched package_name'): |
| 62 check(a, b) |
| 63 |
| 64 a = self.cp('', 'package_name/${platform}-${os_ver}', 'latest') |
| 65 b = self.cp('', 'package_name/windows-amd64-something_10', 'deadbeef'*5) |
| 66 # will not raise |
| 67 check(a, b) |
| 68 |
| 69 # This doesn't match the previous knowledge of platform or os_ver, so it |
| 70 # will not match. |
| 71 a = self.cp('', 'package_name/${platform}-${os_ver}', 'latest') |
| 72 b = self.cp('', 'package_name/linux-32-nerds', 'deadbeef'*5) |
| 73 |
| 74 with self.assertRaisesRegexp(ValueError, 'Mismatched package_name'): |
| 75 check(a, b) |
| 76 |
| 77 |
| 78 if __name__ == '__main__': |
| 79 if '-v' in sys.argv: |
| 80 unittest.TestCase.maxDiff = None |
| 81 logging.basicConfig( |
| 82 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL, |
| 83 format='%(levelname)-7s %(filename)s:%(lineno)3d %(message)s') |
| 84 unittest.main() |
OLD | NEW |