blob: 2daa23d4f5fccd9281ec8acb3b56a84f39d71902 [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
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]
21_ANDROID_VERSION_SAMPLES = [
22 'git_mnc-release/shamu-userdebug/2457013'
23]
Richard Barnette6c2b70a2017-01-26 13:40:51 -080024
Allen Li606673f2017-02-21 18:41:13 -080025
26class ActionTestCase(unittest.TestCase):
27 """Tests for Action functions."""
Richard Barnette17fa7c42018-04-26 00:33:11 +000028 #pylint:disable=missing-docstring
Allen Li606673f2017-02-21 18:41:13 -080029
30 def test__get_label_action_with_keyval_label(self):
31 got = provision._get_label_action('cros-version:foo')
32 self.assertEqual(got, provision._Action('cros-version', 'foo'))
33
34 def test__get_label_action_with_plain_label(self):
35 got = provision._get_label_action('webcam')
36 self.assertEqual(got, provision._Action('webcam', None))
37
38 def test__get_label_action_with_empty_string(self):
39 got = provision._get_label_action('')
40 self.assertEqual(got, provision._Action('', None))
41
42
Richard Barnette6c2b70a2017-01-26 13:40:51 -080043class ImageParsingTests(unittest.TestCase):
44 """Unit tests for `provision.get_version_label_prefix()`."""
45
46 def _do_test_prefixes(self, expected, version_samples):
47 for v in version_samples:
48 prefix = provision.get_version_label_prefix(v)
49 self.assertEqual(prefix, expected)
50
51 def test_cros_prefix(self):
52 """Test handling of Chrome OS version strings."""
53 self._do_test_prefixes(provision.CROS_VERSION_PREFIX,
54 _CROS_VERSION_SAMPLES)
55
Richard Barnette7203e182018-07-10 11:22:20 -070056 def test_cros_android_prefix(self):
57 """Test handling of Chrome OS version strings."""
58 self._do_test_prefixes(provision.CROS_ANDROID_VERSION_PREFIX,
59 _CROS_ANDROID_VERSION_SAMPLES)
60
Richard Barnette6c2b70a2017-01-26 13:40:51 -080061 def test_android_prefix(self):
62 """Test handling of Android version strings."""
63 self._do_test_prefixes(provision.ANDROID_BUILD_VERSION_PREFIX,
64 _ANDROID_VERSION_SAMPLES)
65
Richard Barnette6c2b70a2017-01-26 13:40:51 -080066
67if __name__ == '__main__':
68 unittest.main()