diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2012-02-28 14:39:58 +0000 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2012-08-23 15:17:02 +0100 |
commit | cbc4314155a5a959502b2a7ea78a3b27e5ea2e4a (patch) | |
tree | 5098f4dfa50a71bca532a4b3e9528ae97a53b29e /test | |
parent | eb36dc50ee6a8b804d77ffe026cb9274b8e03210 (diff) |
Add test suite for install script generation
This test suite creates an OsinfoInstallConfig object and along
with a demo XSL template, it generates some install scripts
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 7 | ||||
-rw-r--r-- | test/install-script.xsl | 34 | ||||
-rw-r--r-- | test/test-install-script.c | 222 |
3 files changed, 263 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 83ecd7d..2ceb7b1 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -18,6 +18,7 @@ check_PROGRAMS = \ test-isodetect \ test-mediauris \ test-treeuris \ + test-install-script \ $(NULL) COMMON_LDADD = \ @@ -35,6 +36,7 @@ COMMON_CFLAGS = \ $(SOUP_GNOME_CFLAGS) \ -I$(top_srcdir) \ -DSRCDIR="\"$(abs_top_srcdir)\"" \ + -DBUILDDIR="\"$(abs_top_builddir)\"" \ $(CHECK_CFLAGS) test_entity_LDADD = $(COMMON_LDADD) @@ -101,6 +103,10 @@ test_treeuris_LDADD = $(COMMON_LDADD) test_treeuris_CFLAGS = $(COMMON_CFLAGS) test_treeuris_SOURCES = test-treeuris.c +test_install_script_LDADD = $(COMMON_LDADD) +test_install_script_CFLAGS = $(COMMON_CFLAGS) +test_install_script_SOURCES = test-install-script.c + TEST_SCRIPT_FILES = \ test-xml-validate @@ -111,6 +117,7 @@ TESTS = $(check_PROGRAMS) \ EXTRA_DIST += \ $(TEST_SCRIPT_FILES) \ test-lib.sh \ + install-script.xsl \ $(NULL) TESTS_ENVIRONMENT = \ diff --git a/test/install-script.xsl b/test/install-script.xsl new file mode 100644 index 0000000..f52e99f --- /dev/null +++ b/test/install-script.xsl @@ -0,0 +1,34 @@ +<?xml version="1.0"?> +<xsl:stylesheet + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + version="1.0"> + + <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"/> +install +text +keyboard <xsl:value-of select="config/l10n-keyboard"/> +lang <xsl:value-of select="config/l10n-language"/> +skipx +network --device eth0 --bootproto dhcp +rootpw <xsl:value-of select="config/admin-password"/> +timezone --utc <xsl:value-of select="config/l10n-timezone"/> +bootloader --location=mbr +zerombr + +part biosboot --fstype=biosboot --size=1 +part pv.2 --size=1 --grow --ondisk=vda +volgroup VolGroup00 --pesize=32768 pv.2 +logvol / --fstype ext4 --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow +reboot + +%packages +@base +@core +@hardware-support + +%end + </xsl:template> +</xsl:stylesheet> diff --git a/test/test-install-script.c b/test/test-install-script.c new file mode 100644 index 0000000..6abeeb3 --- /dev/null +++ b/test/test-install-script.c @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2009-2012 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Authors: + * Daniel P. Berrange <berrange@redhat.com> + */ + +#include <config.h> + +#include <config.h> +#include <stdlib.h> +#include <osinfo/osinfo.h> +#include <check.h> + +static GError *error = NULL; +static gchar *actualData = NULL; +static const gchar *expectData = \ + "\n" \ + "# OS id=http://fedoraproject.org/fedora/16 profile jeos\n" \ + "install\n" \ + "text\n" \ + "keyboard uk\n" \ + "lang en_GB.UTF-8\n" \ + "skipx\n" \ + "network --device eth0 --bootproto dhcp\n" \ + "rootpw 123456\n" \ + "timezone --utc Europe/London\n" \ + "bootloader --location=mbr\n" \ + "zerombr\n" \ + "\n" \ + "part biosboot --fstype=biosboot --size=1\n" \ + "part pv.2 --size=1 --grow --ondisk=vda\n" \ + "volgroup VolGroup00 --pesize=32768 pv.2\n" \ + "logvol / --fstype ext4 --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow\n" \ + "reboot\n" \ + "\n" \ + "%packages\n" \ + "@base\n" \ + "@core\n" \ + "@hardware-support\n" \ + "\n" \ + "%end\n" \ + " "; + +static void test_generate_finish(GObject *src, + GAsyncResult *res, + gpointer user_data) +{ + GMainLoop *loop = user_data; + + actualData = osinfo_install_script_generate_finish(OSINFO_INSTALL_SCRIPT(src), + res, + &error); + + g_main_loop_quit(loop); +} + +static OsinfoInstallConfig *test_get_config(void) +{ + OsinfoInstallConfig *config; + + config = osinfo_install_config_new("http://example.com"); + + osinfo_install_config_set_l10n_keyboard(config, "uk"); + osinfo_install_config_set_l10n_language(config, "en_GB.UTF-8"); + osinfo_install_config_set_l10n_timezone(config, "Europe/London"); + + osinfo_install_config_set_admin_password(config, "123456"); + + osinfo_install_config_set_user_password(config, "123456"); + osinfo_install_config_set_user_login(config, "fred"); + osinfo_install_config_set_user_realname(config, "Fred Blogs"); + osinfo_install_config_set_user_autologin(config, TRUE); + osinfo_install_config_set_user_administrator(config, TRUE); + + return config; +} + +START_TEST(test_script_file) +{ + OsinfoInstallScript *script; + OsinfoInstallConfig *config = test_get_config(); + OsinfoOs *os; + GMainLoop *loop; + + script = osinfo_install_script_new_uri("http://example.com", + "jeos", + "file://" SRCDIR "/test/install-script.xsl"); + + 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); + + if (g_main_loop_is_running(loop)) + g_main_loop_run(loop); + + unlink(BUILDDIR "/test/install-script-actual.txt"); + fail_unless(error == NULL, error ? error->message : "none"); + + fail_unless(strcmp(actualData, expectData) == 0, "Actual '%s' match expect '%s'", + actualData, expectData); + + g_object_unref(os); + g_object_unref(config); + g_object_unref(script); + g_main_loop_unref(loop); +} +END_TEST + + + +START_TEST(test_script_data) +{ + OsinfoInstallScript *script; + OsinfoInstallConfig *config = test_get_config(); + OsinfoOs *os; + GMainLoop *loop; + GFile *file = g_file_new_for_uri("file://" SRCDIR "/test/install-script.xsl"); + gchar *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"); + script = osinfo_install_script_new_data("http://example.com", + "jeos", + 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); + + if (g_main_loop_is_running(loop)) + g_main_loop_run(loop); + + unlink(BUILDDIR "/test/install-script-actual.txt"); + fail_unless(error == NULL, error ? error->message : "none"); + + g_object_unref(os); + g_object_unref(config); + g_object_unref(script); +} +END_TEST + + + +static Suite * +list_suite(void) +{ + Suite *s = suite_create("List"); + TCase *tc = tcase_create("Core"); + tcase_set_timeout(tc, 120); + + tcase_add_test(tc, test_script_file); + tcase_add_test(tc, test_script_data); + suite_add_tcase(s, tc); + return s; +} + +int main(void) +{ + int number_failed; + Suite *s = list_suite (); + SRunner *sr = srunner_create (s); + + g_type_init(); + + /* Upfront so we don't confuse valgrind */ + osinfo_entity_get_type(); + osinfo_db_get_type(); + osinfo_device_get_type(); + osinfo_platform_get_type(); + osinfo_os_get_type(); + osinfo_list_get_type(); + osinfo_devicelist_get_type(); + osinfo_platformlist_get_type(); + osinfo_oslist_get_type(); + osinfo_filter_get_type(); + + srunner_run_all (sr, CK_ENV); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} +/* + * Local variables: + * indent-tabs-mode: nil + * c-indent-level: 4 + * c-basic-offset: 4 + * End: + */ |