blob: 8388c20d7366daca52ae370b92a4c6d7fd31a892 [file] [log] [blame]
Allen Li606673f2017-02-21 18:41:13 -08001#!/usr/bin/python2.7
Richard Barnette6c2b70a2017-01-26 13:40:51 -08002# 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
6import unittest
7
8import common
9from 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 Li606673f2017-02-21 18:41:13 -080018
19class 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 Barnette6c2b70a2017-01-26 13:40:51 -080035class 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
59if __name__ == '__main__':
60 unittest.main()