blob: 00df495f0c3da05288eea57bb652cb83a5406259 [file] [log] [blame]
Allen Lid78af972017-07-13 12:48:01 -07001# Copyright 2017 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Unit tests for osinfo_metrics."""
6
7# pylint: disable=protected-access
8
9from __future__ import absolute_import
10from __future__ import print_function
11
12import mock
13
14from chromite.lib import cros_test_lib
15from chromite.scripts.sysmon import osinfo_metrics
16
17
18class TestOSInfoMetrics(cros_test_lib.TestCase):
19 """Tests for osinfo_metrics."""
20
21 def setUp(self):
22 patcher = mock.patch('infra_libs.ts_mon.common.interface.state.store',
23 autospec=True)
24 self.store = patcher.start()
25 self.addCleanup(patcher.stop)
26
27 def test_collect(self):
28 with mock.patch('platform.system', autospec=True) as system, \
29 mock.patch('platform.dist', autospec=True) as dist, \
30 mock.patch('sys.maxsize', 2**64):
31 system.return_value = 'Linux'
32 dist.return_value = ('Ubuntu', '14.04', 'trusty')
33 osinfo_metrics.collect_os_info()
34
35 setter = self.store.set
36 calls = [
37 mock.call('proc/os/name', (), None, 'ubuntu', enforce_ge=mock.ANY),
38 mock.call('proc/os/version', (), None, '14.04', enforce_ge=mock.ANY),
39 mock.call('proc/os/arch', (), None, 'x86_64', enforce_ge=mock.ANY),
40 mock.call('proc/python/arch', (), None, '64', enforce_ge=mock.ANY),
41 ]
42 setter.assert_has_calls(calls)
43 self.assertEqual(len(setter.mock_calls), len(calls))