[osinfo-db-tools PATCH 5/7] tests: Add osinfo-db-validate tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a set of functional tests to ensure osinfo-db-validate works as
epxected. The covered scenarios are:
- osinfo-db-validate --system
- osinfo-db-validate --local
- osinfo-db-validate --user
- osindo-db-validate --dir
  - For this, a negative test was also added

https://gitlab.com/libosinfo/osinfo-db-tools/issues/2

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 tests/Makefile.am                |  1 +
 tests/test_osinfo_db_validate.py | 76 ++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+)
 create mode 100755 tests/test_osinfo_db_validate.py

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 16b760b..fb7dfab 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -6,6 +6,7 @@ test_helpers = \
 
 test_programs = \
 	test_osinfo_db_path.py \
+	test_osinfo_db_validate.py \
 	$(NULL)
 
 EXTRA_DIST += \
diff --git a/tests/test_osinfo_db_validate.py b/tests/test_osinfo_db_validate.py
new file mode 100755
index 0000000..91dcc43
--- /dev/null
+++ b/tests/test_osinfo_db_validate.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python3
+#
+# This work is licensed under the GNU GPLv2 or later.
+# See the COPYING file in the top-level directory.
+
+import os
+import pytest
+import shutil
+import sys
+import util
+
+
+def test_osinfo_db_validate_system():
+    """
+    Test osinfo-db-validate --system
+    """
+    os.environ["OSINFO_SYSTEM_DIR"] = util.Data.positive
+    cmd = [util.Tools.db_validate, util.ToolsArgs.SYSTEM]
+    returncode = util.get_returncode(cmd)
+    assert returncode == 0
+
+
+def test_osinfo_db_validate_local():
+    """
+    Test osinfo-db-validate --local
+    """
+    os.environ["OSINFO_LOCAL_DIR"] = util.Data.positive
+    cmd = [util.Tools.db_validate, util.ToolsArgs.LOCAL]
+    returncode = util.get_returncode(cmd)
+    assert returncode == 0
+
+
+def test_osinfo_db_validate_user():
+    """
+    Test osinfo-db-validate --user
+    """
+    os.environ["OSINFO_USER_DIR"] = util.Data.positive
+    cmd = [util.Tools.db_validate, util.ToolsArgs.USER]
+    returncode = util.get_returncode(cmd)
+    assert returncode == 0
+
+
+def test_osinfo_db_validate_dir():
+    """
+    Test osinfo-db-validate --dir
+    """
+    cmd = [util.Tools.db_validate, util.ToolsArgs.DIR, util.Data.positive]
+    returncode = util.get_returncode(cmd)
+    assert returncode == 0
+
+
+def test_osinfo_db_validate_root():
+    """
+    Test osinfo-db-validate --dir
+    """
+    os.environ["OSINFO_SYSTEM_DIR"] = "positive"
+    tempdir = util.tempdir()
+    shutil.copytree(util.Data.positive, os.path.join(tempdir, "positive"))
+    cmd = [util.Tools.db_validate, util.ToolsArgs.ROOT, tempdir,
+            util.ToolsArgs.SYSTEM]
+    returncode = util.get_returncode(cmd)
+    shutil.rmtree(tempdir)
+    assert returncode == 0
+
+
+def test_negative_osinfo_db_validate_dir():
+    """
+    Test failure on osinfo-db-validate --dir
+    """
+    cmd = [util.Tools.db_validate, util.ToolsArgs.DIR, util.Data.negative]
+    returncode = util.get_returncode(cmd)
+    assert returncode == 1
+
+
+if __name__ == "__main__":
+    exit(pytest.main(sys.argv))
-- 
2.21.0

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux