blob: 52dff4e2ce7a58ed0cbf947d6c624598cf5fe2aa [file] [log] [blame]
Mike Frysingere58c0e22017-10-04 15:43:30 -04001# -*- coding: utf-8 -*-
Allen Lid78af972017-07-13 12:48:01 -07002# 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"""Unit tests for osinfo_metrics."""
7
8# pylint: disable=protected-access
9
10from __future__ import absolute_import
11from __future__ import print_function
12
13import mock
14
15from chromite.lib import cros_test_lib
16from chromite.scripts.sysmon import osinfo_metrics
17
18
19class TestOSInfoMetrics(cros_test_lib.TestCase):
20 """Tests for osinfo_metrics."""
21
22 def setUp(self):
23 patcher = mock.patch('infra_libs.ts_mon.common.interface.state.store',
24 autospec=True)
25 self.store = patcher.start()
26 self.addCleanup(patcher.stop)
27
28 def test_collect(self):
29 with mock.patch('platform.system', autospec=True) as system, \
30 mock.patch('platform.dist', autospec=True) as dist, \
31 mock.patch('sys.maxsize', 2**64):
32 system.return_value = 'Linux'
33 dist.return_value = ('Ubuntu', '14.04', 'trusty')
34 osinfo_metrics.collect_os_info()
35
36 setter = self.store.set
37 calls = [
38 mock.call('proc/os/name', (), None, 'ubuntu', enforce_ge=mock.ANY),
39 mock.call('proc/os/version', (), None, '14.04', enforce_ge=mock.ANY),
40 mock.call('proc/os/arch', (), None, 'x86_64', enforce_ge=mock.ANY),
41 mock.call('proc/python/arch', (), None, '64', enforce_ge=mock.ANY),
42 ]
43 setter.assert_has_calls(calls)
44 self.assertEqual(len(setter.mock_calls), len(calls))