From c911afbfe5a38823971e9cdbd4d1848c6e5c16de Mon Sep 17 00:00:00 2001 From: Igor Galić <me+git@igalic.co> Date: Fri, 10 Jan 2020 05:06:06 +0100 Subject: util: move uptime's else branch into its own boottime function (#53) Also fix bugs: - pass binary instead of string to sysctlbyname(), and - unpack the "return value" in a struct, rather than in single integer. LP: #1853160 Co-Authored-By: Ryan Harper <ryan.harper@canonical.com> --- cloudinit/tests/test_util.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'cloudinit/tests') diff --git a/cloudinit/tests/test_util.py b/cloudinit/tests/test_util.py index be100646..11f37000 100644 --- a/cloudinit/tests/test_util.py +++ b/cloudinit/tests/test_util.py @@ -189,6 +189,21 @@ class TestUtil(CiTestCase): self.assertEqual(is_rw, False) +class TestUptime(CiTestCase): + + @mock.patch('cloudinit.util.boottime') + @mock.patch('cloudinit.util.os.path.exists') + @mock.patch('cloudinit.util.time.time') + def test_uptime_non_linux_path(self, m_time, m_exists, m_boottime): + boottime = 1000.0 + uptime = 10.0 + m_boottime.return_value = boottime + m_time.return_value = boottime + uptime + m_exists.return_value = False + result = util.uptime() + self.assertEqual(str(uptime), result) + + class TestShellify(CiTestCase): def test_input_dict_raises_type_error(self): -- cgit v1.2.3