Allen Li | 606673f | 2017-02-21 18:41:13 -0800 | [diff] [blame^] | 1 | #!/usr/bin/python2.7 |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 2 | # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | import unittest |
| 7 | |
| 8 | import common |
| 9 | from autotest_lib.server.cros import provision |
| 10 | |
| 11 | _CROS_VERSION_SAMPLES = ['cave-release/R57-9030.0.0'] |
| 12 | _ANDROID_VERSION_SAMPLES = ['git_mnc-release/shamu-userdebug/2457013'] |
| 13 | _TESTBED_VERSION_SAMPLES = [ |
| 14 | ','.join(_ANDROID_VERSION_SAMPLES * 2), |
| 15 | _ANDROID_VERSION_SAMPLES[0] + '#4' |
| 16 | ] |
| 17 | |
Allen Li | 606673f | 2017-02-21 18:41:13 -0800 | [diff] [blame^] | 18 | |
| 19 | class ActionTestCase(unittest.TestCase): |
| 20 | """Tests for Action functions.""" |
| 21 | |
| 22 | def test__get_label_action_with_keyval_label(self): |
| 23 | got = provision._get_label_action('cros-version:foo') |
| 24 | self.assertEqual(got, provision._Action('cros-version', 'foo')) |
| 25 | |
| 26 | def test__get_label_action_with_plain_label(self): |
| 27 | got = provision._get_label_action('webcam') |
| 28 | self.assertEqual(got, provision._Action('webcam', None)) |
| 29 | |
| 30 | def test__get_label_action_with_empty_string(self): |
| 31 | got = provision._get_label_action('') |
| 32 | self.assertEqual(got, provision._Action('', None)) |
| 33 | |
| 34 | |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 35 | class ImageParsingTests(unittest.TestCase): |
| 36 | """Unit tests for `provision.get_version_label_prefix()`.""" |
| 37 | |
| 38 | def _do_test_prefixes(self, expected, version_samples): |
| 39 | for v in version_samples: |
| 40 | prefix = provision.get_version_label_prefix(v) |
| 41 | self.assertEqual(prefix, expected) |
| 42 | |
| 43 | def test_cros_prefix(self): |
| 44 | """Test handling of Chrome OS version strings.""" |
| 45 | self._do_test_prefixes(provision.CROS_VERSION_PREFIX, |
| 46 | _CROS_VERSION_SAMPLES) |
| 47 | |
| 48 | def test_android_prefix(self): |
| 49 | """Test handling of Android version strings.""" |
| 50 | self._do_test_prefixes(provision.ANDROID_BUILD_VERSION_PREFIX, |
| 51 | _ANDROID_VERSION_SAMPLES) |
| 52 | |
| 53 | def test_testbed_prefix(self): |
| 54 | """Test handling of Testbed version strings.""" |
| 55 | self._do_test_prefixes(provision.TESTBED_BUILD_VERSION_PREFIX, |
| 56 | _TESTBED_VERSION_SAMPLES) |
| 57 | |
| 58 | |
| 59 | if __name__ == '__main__': |
| 60 | unittest.main() |