Re: [PATCH 06/10] tests: Pass media to script generator

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

 



On Thu, May 07, 2015 at 05:36:41PM +0100, Zeeshan Ali (Khattak) wrote:
> Now that we have an API to pass media to script generation methods, let's
> test that API instead since its not only the recommended API but also this
> way we get to test both passing of OS and media information to script
> template.
> 
> One of the test cases still uses the existing API on purpose to keep the
> case of 'no media available' covered as well.
> ---
>  .../dbdata/install-scripts/test-install-script.xml |  6 ++
>  test/dbdata/oses/test-os-data.xml                  | 23 +++++
>  test/install-script.xsl                            |  7 +-
>  test/test-install-script.c                         | 98 +++++++++++++++++-----
>  4 files changed, 110 insertions(+), 24 deletions(-)
>  create mode 100644 test/dbdata/oses/test-os-data.xml
> 
> diff --git a/test/dbdata/install-scripts/test-install-script.xml b/test/dbdata/install-scripts/test-install-script.xml
> index 48469ef..e3c05b7 100644
> --- a/test/dbdata/install-scripts/test-install-script.xml
> +++ b/test/dbdata/install-scripts/test-install-script.xml
> @@ -16,6 +16,12 @@
>          <xsl:output method="text"/>
>  
>          <xsl:template match="/install-script-config">
> +# OS id=<xsl:value-of select="os/id"/>
> +# <xsl:choose>
> +    <xsl:when test="media != ''">Media id=<xsl:value-of select="media/id"/></xsl:when>
> +    <xsl:otherwise>Unknown media</xsl:otherwise>
> +  </xsl:choose>
> +# Profile: <xsl:value-of select="script/profile"/>
>  keyboard <xsl:value-of select="config/l10n-keyboard"/>
>  lang <xsl:value-of select="config/l10n-language"/>
>  timezone --utc <xsl:value-of select="config/l10n-timezone"/>
> diff --git a/test/dbdata/oses/test-os-data.xml b/test/dbdata/oses/test-os-data.xml
> new file mode 100644
> index 0000000..88ef431
> --- /dev/null
> +++ b/test/dbdata/oses/test-os-data.xml
> @@ -0,0 +1,23 @@
> +<?xml version="1.0" encoding="UTF-8"?>
> +<libosinfo version="0.0.1">
> +  <os id="http://fedoraproject.org/fedora/16";>
> +    <short-id>fedora16</short-id>
> +    <name>Fedora 16</name>
> +    <version>16</version>
> +    <vendor>Fedora Project</vendor>
> +    <family>linux</family>
> +    <distro>fedora</distro>
> +    <codename>Verne</codename>
> +
> +    <media arch="i686">
> +      <url>http://archive.fedoraproject.org/pub/archive/fedora/linux/releases/16/Fedora/i386/iso/Fedora-16-i386-DVD.iso</url>
> +      <iso>
> +        <volume-id>Fedora 16 i386 DVD</volume-id>
> +        <system-id>LINUX</system-id>
> +        <volume-size>3806375936</volume-size>
> +      </iso>
> +      <kernel>isolinux/vmlinuz</kernel>
> +      <initrd>isolinux/initrd.img</initrd>
> +    </media>
> +  </os>
> +</libosinfo>
> diff --git a/test/install-script.xsl b/test/install-script.xsl
> index f52e99f..f355152 100644
> --- a/test/install-script.xsl
> +++ b/test/install-script.xsl
> @@ -6,7 +6,12 @@
>    <xsl:output method="text"/>
>  
>    <xsl:template match="/install-script-config">
> -# OS id=<xsl:value-of select="os/id"/> profile <xsl:value-of select="script/profile"/>
> +# OS id=<xsl:value-of select="os/id"/>
> +# <xsl:choose>
> +    <xsl:when test="media != ''">Media id=<xsl:value-of select="media/id"/></xsl:when>
> +    <xsl:otherwise>Unknown media</xsl:otherwise>
> +  </xsl:choose>
> +# Profile: <xsl:value-of select="script/profile"/>
>  install
>  text
>  keyboard <xsl:value-of select="config/l10n-keyboard"/>
> diff --git a/test/test-install-script.c b/test/test-install-script.c
> index 4da3bb4..c067e9d 100644
> --- a/test/test-install-script.c
> +++ b/test/test-install-script.c
> @@ -30,7 +30,9 @@ static GError *error = NULL;
>  static gchar *actualData = NULL;
>  static const gchar *expectData =                                        \
>      "\n"                                                                \
> -    "# OS id=http://fedoraproject.org/fedora/16 profile jeos\n"         \
> +    "# OS id=http://fedoraproject.org/fedora/16\n";                      \
> +    "# Media id=http://fedoraproject.org/fedora/16:0\n";                 \
> +    "# Profile: jeos\n"                                                 \
>      "install\n"                                                         \
>      "text\n"                                                            \
>      "keyboard uk\n"                                                     \
> @@ -58,10 +60,26 @@ static const gchar *expectData =                                        \
>  
>  static const gchar *expectData2 =                                       \
>      "\n"                                                                \
> +    "# OS id=http://fedoraproject.org/fedora/16\n";                      \
> +    "# Unknown media\n"                                                 \
> +    "# Profile: jeos\n"                                                 \
>      "keyboard FOOBAR\n"                                                 \
>      "lang French\n"                                                     \
>      "timezone --utc Europe/Paris";
>  
> +static void test_generate_for_media_finish(GObject *src,
> +                                           GAsyncResult *res,
> +                                           gpointer user_data)
> +{
> +    GMainLoop *loop = user_data;
> +
> +    actualData = osinfo_install_script_generate_for_media_finish(OSINFO_INSTALL_SCRIPT(src),
> +                                                                 res,
> +                                                                 &error);
> +
> +    g_main_loop_quit(loop);
> +}
> +
>  static void test_generate_finish(GObject *src,
>                                   GAsyncResult *res,
>                                   gpointer user_data)
> @@ -100,23 +118,41 @@ START_TEST(test_script_file)
>  {
>      OsinfoInstallScript *script;
>      OsinfoInstallConfig *config = test_get_config();
> -    OsinfoOs *os;
> +    OsinfoLoader *loader = osinfo_loader_new();
> +    OsinfoDb *db;
> +    OsinfoMedia *media;
>      GMainLoop *loop;
>  
>      script = osinfo_install_script_new_uri("http://example.com";,
>                                             "jeos",
>                                             "file://" SRCDIR "/test/install-script.xsl");
>  
> +    osinfo_loader_process_path(loader, SRCDIR "/test/dbdata", &error);
> +    fail_unless(error == NULL, error ? error->message : "none");
> +    db = g_object_ref(osinfo_loader_get_db(loader));
> +    g_object_unref(loader);
> +
>      loop = g_main_loop_new(g_main_context_get_thread_default(),
>                             TRUE);
>  
> -    os = osinfo_os_new("http://fedoraproject.org/fedora/16";);
> -    osinfo_install_script_generate_async(script,
> -                                         os,
> -                                         config,
> -                                         NULL,
> -                                         test_generate_finish,
> -                                         loop);
> +    media = osinfo_media_new("http://fedoraproject.org/fedora/16:0";, "i686");
> +    osinfo_entity_set_param(OSINFO_ENTITY (media),
> +                            OSINFO_MEDIA_PROP_VOLUME_ID,
> +                            "Fedora 16 i386 DVD");
> +    osinfo_entity_set_param(OSINFO_ENTITY (media),
> +                            OSINFO_MEDIA_PROP_SYSTEM_ID,
> +                            "LINUX");
> +    osinfo_entity_set_param_int64(OSINFO_ENTITY (media),
> +                                  OSINFO_MEDIA_PROP_VOLUME_SIZE,
> +                                  3806375936);
> +    fail_unless(osinfo_db_identify_media (db, media), "Failed to identify media");
> +

This bit seems duplicated below, I'd tend to have a small helper to
create the media/identify it.

ACK either way.

> +    osinfo_install_script_generate_for_media_async(script,
> +                                                   media,
> +                                                   config,
> +                                                   NULL,
> +                                                   test_generate_for_media_finish,
> +                                                   loop);
>  
>      if (g_main_loop_is_running(loop))
>          g_main_loop_run(loop);
> @@ -127,7 +163,8 @@ START_TEST(test_script_file)
>      fail_unless(strcmp(actualData, expectData) == 0, "Actual '%s' match expect '%s'",
>                  actualData, expectData);
>  
> -    g_object_unref(os);
> +    g_object_unref(media);
> +    g_object_unref(db);
>      g_object_unref(config);
>      g_object_unref(script);
>      g_main_loop_unref(loop);
> @@ -140,7 +177,9 @@ START_TEST(test_script_data)
>  {
>      OsinfoInstallScript *script;
>      OsinfoInstallConfig *config = test_get_config();
> -    OsinfoOs *os;
> +    OsinfoLoader *loader = osinfo_loader_new();
> +    OsinfoDb *db;
> +    OsinfoMedia *media;
>      GMainLoop *loop;
>      GFile *file = g_file_new_for_uri("file://" SRCDIR "/test/install-script.xsl");
>      gchar *data;
> @@ -148,10 +187,23 @@ START_TEST(test_script_data)
>      g_file_load_contents(file, NULL, &data, NULL, NULL, &error);
>      fail_unless(error == NULL, error ? error->message : "none");
>  
> -    os = osinfo_os_new("http://fedoraproject.org/fedora/16";);
> -    osinfo_entity_set_param(OSINFO_ENTITY(os),
> -                            OSINFO_PRODUCT_PROP_SHORT_ID,
> -                            "fedora16");
> +    osinfo_loader_process_path(loader, SRCDIR "/test/dbdata", &error);
> +    fail_unless(error == NULL, error ? error->message : "none");
> +    db = g_object_ref(osinfo_loader_get_db(loader));
> +    g_object_unref(loader);
> +
> +    media = osinfo_media_new("http://fedoraproject.org/fedora/16:0";, "i686");
> +    osinfo_entity_set_param(OSINFO_ENTITY (media),
> +                            OSINFO_MEDIA_PROP_VOLUME_ID,
> +                            "Fedora 16 i386 DVD");
> +    osinfo_entity_set_param(OSINFO_ENTITY (media),
> +                            OSINFO_MEDIA_PROP_SYSTEM_ID,
> +                            "LINUX");
> +    osinfo_entity_set_param_int64(OSINFO_ENTITY (media),
> +                                  OSINFO_MEDIA_PROP_VOLUME_SIZE,
> +                                  3806375936);
> +    fail_unless(osinfo_db_identify_media (db, media), "Failed to identify media");
> +
>      script = osinfo_install_script_new_data("http://example.com";,
>                                              "jeos",
>                                              data);
> @@ -159,12 +211,12 @@ START_TEST(test_script_data)
>      loop = g_main_loop_new(g_main_context_get_thread_default(),
>                             TRUE);
>  
> -    osinfo_install_script_generate_async(script,
> -                                         os,
> -                                         config,
> -                                         NULL,
> -                                         test_generate_finish,
> -                                         loop);
> +    osinfo_install_script_generate_for_media_async(script,
> +                                                   media,
> +                                                   config,
> +                                                   NULL,
> +                                                   test_generate_for_media_finish,
> +                                                   loop);
>  
>      if (g_main_loop_is_running(loop))
>          g_main_loop_run(loop);
> @@ -172,7 +224,8 @@ START_TEST(test_script_data)
>      unlink(BUILDDIR "/test/install-script-actual.txt");
>      fail_unless(error == NULL, error ? error->message : "none");
>  
> -    g_object_unref(os);
> +    g_object_unref(media);
> +    g_object_unref(db);
>      g_object_unref(config);
>      g_object_unref(script);
>  }
> @@ -225,7 +278,6 @@ START_TEST(test_script_datamap)
>      osinfo_install_config_set_l10n_language(config, "fr_FR");
>      osinfo_install_config_set_l10n_timezone(config, "Europe/Paris");
>  
> -
>      os = osinfo_os_new("http://fedoraproject.org/fedora/16";);
>      osinfo_entity_set_param(OSINFO_ENTITY(os),
>                              OSINFO_PRODUCT_PROP_SHORT_ID,
> -- 
> 2.1.0
> 
> _______________________________________________
> Libosinfo mailing list
> Libosinfo@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libosinfo

Attachment: pgpXSNNCRYSjD.pgp
Description: PGP signature

_______________________________________________
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