blob: bdd5e5dc32df62dae51f9eb79f1f661b2dadd517 [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
Mike Frysinger1ca14432020-02-16 00:18:56 -050013import sys
14
Allen Lid78af972017-07-13 12:48:01 -070015import mock
16
17from chromite.lib import cros_test_lib
18from chromite.scripts.sysmon import osinfo_metrics
19
20
Mike Frysinger1ca14432020-02-16 00:18:56 -050021assert sys.version_info >= (3, 6), 'This module requires Python 3.6+'
22
23
Allen Lid78af972017-07-13 12:48:01 -070024class TestOSInfoMetrics(cros_test_lib.TestCase):
25 """Tests for osinfo_metrics."""
26
27 def setUp(self):
28 patcher = mock.patch('infra_libs.ts_mon.common.interface.state.store',
29 autospec=True)
30 self.store = patcher.start()
31 self.addCleanup(patcher.stop)
32
33 def test_collect(self):
34 with mock.patch('platform.system', autospec=True) as system, \
35 mock.patch('platform.dist', autospec=True) as dist, \
36 mock.patch('sys.maxsize', 2**64):
37 system.return_value = 'Linux'
38 dist.return_value = ('Ubuntu', '14.04', 'trusty')
39 osinfo_metrics.collect_os_info()
40
41 setter = self.store.set
42 calls = [
43 mock.call('proc/os/name', (), None, 'ubuntu', enforce_ge=mock.ANY),
44 mock.call('proc/os/version', (), None, '14.04', enforce_ge=mock.ANY),
45 mock.call('proc/os/arch', (), None, 'x86_64', enforce_ge=mock.ANY),
46 mock.call('proc/python/arch', (), None, '64', enforce_ge=mock.ANY),
47 ]
48 setter.assert_has_calls(calls)
49 self.assertEqual(len(setter.mock_calls), len(calls))