blob: d593bf3b0ee5d81186dd349d69240354481b9dc2 [file] [log] [blame]
Derek Beckett25616cc2021-08-24 13:04:02 -07001#!/usr/bin/python3
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
Richard Barnette7203e182018-07-10 11:22:20 -070011_CROS_VERSION_SAMPLES = [
12 'cave-release/R57-9030.0.0',
13 'grunt-llvm-next-toolchain-tryjob/R69-10851.0.0-b2726174'
14 'eve-tot-chrome-pfq-informational/R69-10822.0.0-b2700960',
15]
16_CROS_ANDROID_VERSION_SAMPLES = [
17 'git_nyc-mr1-arc/cheets_arm-user/4866647',
18 'git_nyc-mr1-arc/cheets_arm-user/P6244267',
19 'git_nyc-mr1-arc/cheets_x86-user/P6256537',
20]
Richard Barnette6c2b70a2017-01-26 13:40:51 -080021
Allen Li606673f2017-02-21 18:41:13 -080022
23class ActionTestCase(unittest.TestCase):
24 """Tests for Action functions."""
Richard Barnette17fa7c42018-04-26 00:33:11 +000025 #pylint:disable=missing-docstring
Allen Li606673f2017-02-21 18:41:13 -080026
27 def test__get_label_action_with_keyval_label(self):
28 got = provision._get_label_action('cros-version:foo')
29 self.assertEqual(got, provision._Action('cros-version', 'foo'))
30
31 def test__get_label_action_with_plain_label(self):
32 got = provision._get_label_action('webcam')
33 self.assertEqual(got, provision._Action('webcam', None))
34
35 def test__get_label_action_with_empty_string(self):
36 got = provision._get_label_action('')
37 self.assertEqual(got, provision._Action('', None))
38
39
Richard Barnette6c2b70a2017-01-26 13:40:51 -080040class ImageParsingTests(unittest.TestCase):
41 """Unit tests for `provision.get_version_label_prefix()`."""
42
43 def _do_test_prefixes(self, expected, version_samples):
44 for v in version_samples:
45 prefix = provision.get_version_label_prefix(v)
46 self.assertEqual(prefix, expected)
47
48 def test_cros_prefix(self):
49 """Test handling of Chrome OS version strings."""
50 self._do_test_prefixes(provision.CROS_VERSION_PREFIX,
51 _CROS_VERSION_SAMPLES)
52
Richard Barnette7203e182018-07-10 11:22:20 -070053 def test_cros_android_prefix(self):
54 """Test handling of Chrome OS version strings."""
55 self._do_test_prefixes(provision.CROS_ANDROID_VERSION_PREFIX,
56 _CROS_ANDROID_VERSION_SAMPLES)
57
Richard Barnette6c2b70a2017-01-26 13:40:51 -080058
59if __name__ == '__main__':
60 unittest.main()