Bläddra i källkod

rinfo_cmd converted

bigtedde 1 år sedan
förälder
incheckning
116428cd4f
1 ändrade filer med 62 tillägg och 57 borttagningar
  1. 62 57
      src/borg/testsuite/archiver/rinfo_cmd.py

+ 62 - 57
src/borg/testsuite/archiver/rinfo_cmd.py

@@ -1,61 +1,66 @@
 import json
 from random import randbytes
-import unittest
 
 from ...constants import *  # NOQA
-from . import (
-    ArchiverTestCaseBase,
-    RemoteArchiverTestCaseBase,
-    ArchiverTestCaseBinaryBase,
-    RK_ENCRYPTION,
-    BORG_EXES,
-    checkts,
-)
-
-
-class ArchiverTestCase(ArchiverTestCaseBase):
-    def test_info(self):
-        self.create_regular_file("file1", size=1024 * 80)
-        self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
-        self.cmd(f"--repo={self.repository_location}", "create", "test", "input")
-        info_repo = self.cmd(f"--repo={self.repository_location}", "rinfo")
-        assert "Original size:" in info_repo
-
-    def test_info_json(self):
-        self.create_regular_file("file1", size=1024 * 80)
-        self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
-        self.cmd(f"--repo={self.repository_location}", "create", "test", "input")
-        info_repo = json.loads(self.cmd(f"--repo={self.repository_location}", "rinfo", "--json"))
-        repository = info_repo["repository"]
-        assert len(repository["id"]) == 64
-        assert "last_modified" in repository
-        checkts(repository["last_modified"])
-        assert info_repo["encryption"]["mode"] == RK_ENCRYPTION[13:]
-        assert "keyfile" not in info_repo["encryption"]
-        cache = info_repo["cache"]
-        stats = cache["stats"]
-        assert all(isinstance(o, int) for o in stats.values())
-        assert all(key in stats for key in ("total_chunks", "total_size", "total_unique_chunks", "unique_size"))
-
-    def test_info_on_repository_with_storage_quota(self):
-        self.create_regular_file("file1", contents=randbytes(1000 * 1000))
-        self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION, "--storage-quota=1G")
-        self.cmd(f"--repo={self.repository_location}", "create", "test", "input")
-        info_repo = self.cmd(f"--repo={self.repository_location}", "rinfo")
-        assert "Storage quota: 1.00 MB used out of 1.00 GB" in info_repo
-
-    def test_info_on_repository_without_storage_quota(self):
-        self.create_regular_file("file1", contents=randbytes(1000 * 1000))
-        self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
-        self.cmd(f"--repo={self.repository_location}", "create", "test", "input")
-        info_repo = self.cmd(f"--repo={self.repository_location}", "rinfo")
-        assert "Storage quota: 1.00 MB used" in info_repo
-
-
-class RemoteArchiverTestCase(RemoteArchiverTestCaseBase, ArchiverTestCase):
-    """run the same tests, but with a remote repository"""
-
-
-@unittest.skipUnless("binary" in BORG_EXES, "no borg.exe available")
-class ArchiverTestCaseBinary(ArchiverTestCaseBinaryBase, ArchiverTestCase):
-    """runs the same tests, but via the borg binary"""
+from . import checkts, cmd, create_regular_file, RK_ENCRYPTION
+
+
+def pytest_generate_tests(metafunc):
+    # Generate tests for different scenarios: local repository, remote repository, and using the borg binary.
+    if "archivers" in metafunc.fixturenames:
+        metafunc.parametrize("archivers", ["archiver", "remote_archiver", "binary_archiver"])
+
+
+def test_info(archivers, request):
+    archiver = request.getfixturevalue(archivers)
+    repo_location, input_path = archiver.repository_location, archiver.input_path
+    create_regular_file(input_path, "file1", size=1024 * 80)
+
+    cmd(archiver, f"--repo={repo_location}", "rcreate", RK_ENCRYPTION)
+    cmd(archiver, f"--repo={repo_location}", "create", "test", "input")
+    info_repo = cmd(archiver, f"--repo={repo_location}", "rinfo")
+    assert "Original size:" in info_repo
+
+
+def test_info_json(archivers, request):
+    archiver = request.getfixturevalue(archivers)
+    repo_location, input_path = archiver.repository_location, archiver.input_path
+    create_regular_file(input_path, "file1", size=1024 * 80)
+
+    cmd(archiver, f"--repo={repo_location}", "rcreate", RK_ENCRYPTION)
+    cmd(archiver, f"--repo={repo_location}", "create", "test", "input")
+    info_repo = json.loads(cmd(archiver, f"--repo={repo_location}", "rinfo", "--json"))
+    repository = info_repo["repository"]
+    assert len(repository["id"]) == 64
+    assert "last_modified" in repository
+
+    checkts(repository["last_modified"])
+    assert info_repo["encryption"]["mode"] == RK_ENCRYPTION[13:]
+    assert "keyfile" not in info_repo["encryption"]
+
+    cache = info_repo["cache"]
+    stats = cache["stats"]
+    assert all(isinstance(o, int) for o in stats.values())
+    assert all(key in stats for key in ("total_chunks", "total_size", "total_unique_chunks", "unique_size"))
+
+
+def test_info_on_repository_with_storage_quota(archivers, request):
+    archiver = request.getfixturevalue(archivers)
+    repo_location, input_path = archiver.repository_location, archiver.input_path
+    create_regular_file(input_path, "file1", contents=randbytes(1000 * 1000))
+
+    cmd(archiver, f"--repo={repo_location}", "rcreate", RK_ENCRYPTION, "--storage-quota=1G")
+    cmd(archiver, f"--repo={repo_location}", "create", "test", "input")
+    info_repo = cmd(archiver, f"--repo={repo_location}", "rinfo")
+    assert "Storage quota: 1.00 MB used out of 1.00 GB" in info_repo
+
+
+def test_info_on_repository_without_storage_quota(archivers, request):
+    archiver = request.getfixturevalue(archivers)
+    repo_location, input_path = archiver.repository_location, archiver.input_path
+    create_regular_file(input_path, "file1", contents=randbytes(1000 * 1000))
+
+    cmd(archiver, f"--repo={repo_location}", "rcreate", RK_ENCRYPTION)
+    cmd(archiver, f"--repo={repo_location}", "create", "test", "input")
+    info_repo = cmd(archiver, f"--repo={repo_location}", "rinfo")
+    assert "Storage quota: 1.00 MB used" in info_repo