[Libosinfo] [libosinfo PATCH 2/2] test-image: Add test for loading an entry

Fabiano Fidêncio fidencio at redhat.com
Wed Apr 10 11:53:42 UTC 2019


Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 .../dbdata/os/libosinfo.org/test-db-image.xml | 18 ++++++++
 tests/test-image.c                            | 44 +++++++++++++++++++
 2 files changed, 62 insertions(+)
 create mode 100644 tests/dbdata/os/libosinfo.org/test-db-image.xml

diff --git a/tests/dbdata/os/libosinfo.org/test-db-image.xml b/tests/dbdata/os/libosinfo.org/test-db-image.xml
new file mode 100644
index 0000000..d3930d3
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-db-image.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/db/image">
+    <short-id>db-image</short-id>
+    <name>DB Image</name>
+    <version>unknown</version>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+
+    <image arch="x86_64" format="qcow2" cloud-init="true">
+      <url>http://libosinfo.org/db/image.qcow2</url>
+    </image>
+
+    <image arch="i686" format="vmdk">
+      <url>http://libosinfo.org/db/image.vmdk</url>
+    </image>
+  </os>
+</libosinfo>
diff --git a/tests/test-image.c b/tests/test-image.c
index 2c6e236..e9ee642 100644
--- a/tests/test-image.c
+++ b/tests/test-image.c
@@ -51,15 +51,59 @@ test_basic(void)
 }
 
 
+static void
+test_loaded(void)
+{
+    OsinfoLoader *loader = osinfo_loader_new();
+    OsinfoDb *db;
+    OsinfoOs *os;
+    OsinfoImageList *list;
+    gint list_len, i;
+    GError *error = NULL;
+
+    osinfo_loader_process_path(loader, SRCDIR "/tests/dbdata", &error);
+    g_assert_no_error(error);
+    db = osinfo_loader_get_db(loader);
+
+    os = osinfo_db_get_os(db, "http://libosinfo.org/test/db/image");
+
+    list = osinfo_os_get_image_list(os);
+    list_len = osinfo_list_get_length(OSINFO_LIST(list));
+    g_assert_cmpint(list_len, ==, 2);
+
+    for (i = 0; i < list_len; i++) {
+        OsinfoImage *image = OSINFO_IMAGE(osinfo_list_get_nth(OSINFO_LIST(list), i));
+
+        if (g_str_equal(osinfo_image_get_architecture(image), "i686")) {
+            g_assert_cmpstr(osinfo_image_get_url(image), ==, "http://libosinfo.org/db/image.vmdk");
+            g_assert_cmpstr(osinfo_image_get_format(image), ==, "vmdk");
+            g_assert_false(osinfo_image_get_cloud_init(image));
+        } else {
+            g_assert_cmpstr(osinfo_image_get_url(image), ==, "http://libosinfo.org/db/image.qcow2");
+            g_assert_cmpstr(osinfo_image_get_format(image), ==, "qcow2");
+            g_assert_true(osinfo_image_get_cloud_init(image));
+        }
+    }
+
+    g_object_unref(list);
+    g_object_unref(loader);
+}
+
+
 int
 main(int argc, char *argv[])
 {
     g_test_init(&argc, &argv, NULL);
 
     g_test_add_func("/image/basic", test_basic);
+    g_test_add_func("/image/loaded", test_loaded);
 
     /* Upfront so we don't confuse valgrind */
+    osinfo_db_get_type();
     osinfo_image_get_type();
+    osinfo_imagelist_get_type();
+    osinfo_loader_get_type();
+    osinfo_os_get_type();
 
     return g_test_run();
 }
-- 
2.20.1




More information about the Libosinfo mailing list