summaryrefslogtreecommitdiff
path: root/cloudinit/tests
diff options
context:
space:
mode:
authorIgor Galić <me+git@igalic.co>2020-01-10 05:06:06 +0100
committerChad Smith <chad.smith@canonical.com>2020-01-09 21:06:06 -0700
commitc911afbfe5a38823971e9cdbd4d1848c6e5c16de (patch)
tree4c6f04f883e0394b6bfc1d24d94c7db294e76fdd /cloudinit/tests
parent6e7f8590402967bffbdd0bb0ae241180910fcd2c (diff)
downloadvyos-cloud-init-c911afbfe5a38823971e9cdbd4d1848c6e5c16de.tar.gz
vyos-cloud-init-c911afbfe5a38823971e9cdbd4d1848c6e5c16de.zip
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>
Diffstat (limited to 'cloudinit/tests')
-rw-r--r--cloudinit/tests/test_util.py15
1 files changed, 15 insertions, 0 deletions
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):