aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_remote.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_remote.py')
-rw-r--r--tests/test_remote.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/test_remote.py b/tests/test_remote.py
index c2b9857..2f273fb 100644
--- a/tests/test_remote.py
+++ b/tests/test_remote.py
@@ -391,11 +391,38 @@ class StatsTest(Base):
def test_missing_sources_are_null(self):
s = sbb.cmd_stats(self.cfg)
self.assertIsNotNone(s["load"])
+ self.assertEqual(set(s["disk"]), {"total", "free"})
+ self.assertIn("slackpkg", s)
self.assertIsNone(s["packages"])
self.assertIsNone(s["slackrepo"])
self.assertEqual(s["sync"], {"personal": None, "pentesting": None})
json.dumps(s)
+ def test_vm_figures(self):
+ meminfo = os.path.join(self.tmp, "meminfo")
+ with open(meminfo, "w") as f:
+ f.write("MemTotal: 16000 kB\nMemFree: 9000 kB\nMemAvailable: 12000 kB\n")
+ self.assertEqual(sbb._meminfo(meminfo), {"total": 16000 * 1024, "available": 12000 * 1024})
+ with mock.patch.object(sbb, "_cpu_times", side_effect=[(100, 1000), (150, 1100)]), \
+ mock.patch.object(sbb.time, "sleep"):
+ self.assertEqual(sbb._cpu(), 50.0)
+ stat = os.path.join(self.tmp, "stat")
+ with open(stat, "w") as f:
+ f.write("cpu 10 0 10 70 10 0 0 0 0 0\ncpu0 1 2 3 4\n")
+ self.assertEqual(sbb._cpu_times(stat), (20, 100)) # idle + iowait count as not busy
+
+ def test_slackpkg_times(self):
+ last = os.path.join(self.tmp, "LASTUPDATE")
+ with open(last, "w") as f:
+ f.write("1791760212\n")
+ pkgs = os.path.join(self.tmp, "packages")
+ os.mkdir(pkgs)
+ for name, t in (("a-1-x86_64-1", 1000), ("b-2-x86_64-1", 3000)):
+ open(os.path.join(pkgs, name), "w").close()
+ os.utime(os.path.join(pkgs, name), (t, t))
+ self.assertEqual(sbb._slackpkg(last, pkgs), {"update": 1791760212, "upgrade": 3000})
+ self.assertEqual(sbb._slackpkg("/nonexistent", "/nonexistent"), {"update": None, "upgrade": None})
+
def test_counts(self):
r = self.cfg["repo_dir"]
for p in ("cat/foo", "cat/bar", "personal/foo", "personal/baz", "pentesting/nmap"):