Skip to content

Commit

Permalink
Merge pull request #426 from srikavin/test-servicelevels
Browse files Browse the repository at this point in the history
Copy python tests for Modulemd.ModuleStream.servicelevels into C

Signed-off-by: Stephen Gallagher <[email protected]>
  • Loading branch information
sgallagher committed Jan 23, 2020
2 parents d83574c + b4f2709 commit 6724516
Showing 1 changed file with 83 additions and 5 deletions.
88 changes: 83 additions & 5 deletions modulemd/tests/test-modulemd-modulestream.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
"═€ίζησθლბშიнстемองจึองታሽ።ደለᚢᛞᚦᚹ⠳⠞⠊⠎▉▒▒▓😃"
#define MMD_TEST_TRACKER_PROP "tracker"

typedef struct _ModuleStreamFixture
{
} ModuleStreamFixture;


static void
module_stream_test_construct (void)
Expand Down Expand Up @@ -524,6 +520,83 @@ module_stream_v2_test_rpm_artifacts (void)
g_clear_object (&stream);
}


static void
module_stream_v1_test_servicelevels (void)
{
g_autoptr (ModulemdModuleStreamV1) stream = NULL;
g_auto (GStrv) servicelevel_names = NULL;
g_autoptr (ModulemdServiceLevel) sl = NULL;
ModulemdServiceLevel *sl_retrieved = NULL;
g_autofree gchar *name_prop = NULL;
g_autofree gchar *eol_str = NULL;

stream = modulemd_module_stream_v1_new (NULL, NULL);
sl = modulemd_service_level_new ("rawhide");
modulemd_service_level_set_eol_ymd (sl, 1980, 3, 2);

modulemd_module_stream_v1_add_servicelevel (stream, sl);

servicelevel_names =
modulemd_module_stream_v1_get_servicelevel_names_as_strv (stream);
g_assert_true (
g_strv_contains ((const gchar *const *)servicelevel_names, "rawhide"));
g_assert_cmpint (g_strv_length (servicelevel_names), ==, 1);

sl_retrieved =
modulemd_module_stream_v1_get_servicelevel (stream, "rawhide");
g_object_get (sl_retrieved, "name", &name_prop, NULL);
eol_str = modulemd_service_level_get_eol_as_string (sl_retrieved);

g_assert_cmpstr (name_prop, ==, "rawhide");
g_assert_cmpstr (eol_str, ==, "1980-03-02");

g_clear_object (&sl);
g_clear_object (&stream);
g_clear_pointer (&name_prop, g_free);
g_clear_pointer (&eol_str, g_free);
g_clear_pointer (&servicelevel_names, g_strfreev);
}


static void
module_stream_v2_test_servicelevels (void)
{
g_autoptr (ModulemdModuleStreamV2) stream = NULL;
g_auto (GStrv) servicelevel_names = NULL;
g_autoptr (ModulemdServiceLevel) sl = NULL;
ModulemdServiceLevel *sl_retrieved = NULL;
g_autofree gchar *name_prop = NULL;
g_autofree gchar *eol_str = NULL;

stream = modulemd_module_stream_v2_new (NULL, NULL);
sl = modulemd_service_level_new ("rawhide");
modulemd_service_level_set_eol_ymd (sl, 1980, 3, 2);

modulemd_module_stream_v2_add_servicelevel (stream, sl);

servicelevel_names =
modulemd_module_stream_v2_get_servicelevel_names_as_strv (stream);
g_assert_true (
g_strv_contains ((const gchar *const *)servicelevel_names, "rawhide"));
g_assert_cmpint (g_strv_length (servicelevel_names), ==, 1);

sl_retrieved =
modulemd_module_stream_v2_get_servicelevel (stream, "rawhide");
g_object_get (sl_retrieved, "name", &name_prop, NULL);
eol_str = modulemd_service_level_get_eol_as_string (sl_retrieved);

g_assert_cmpstr (name_prop, ==, "rawhide");
g_assert_cmpstr (eol_str, ==, "1980-03-02");

g_clear_object (&sl);
g_clear_object (&stream);
g_clear_pointer (&name_prop, g_free);
g_clear_pointer (&eol_str, g_free);
g_clear_pointer (&servicelevel_names, g_strfreev);
}


static void
module_stream_v1_test_documentation (void)
{
Expand Down Expand Up @@ -2547,13 +2620,18 @@ main (int argc, char *argv[])
g_test_add_func ("/modulemd/v2/modulestream/upgrade",
module_stream_test_upgrade);


g_test_add_func ("/modulemd/v2/modulestream/v1/rpm_artifacts",
module_stream_v1_test_rpm_artifacts);

g_test_add_func ("/modulemd/v2/modulestream/v2/rpm_artifacts",
module_stream_v2_test_rpm_artifacts);

g_test_add_func ("/modulemd/v2/modulestream/v1/servicelevels",
module_stream_v2_test_servicelevels);

g_test_add_func ("/modulemd/v2/modulestream/v2/servicelevels",
module_stream_v1_test_servicelevels);

g_test_add_func ("/modulemd/v2/modulestream/v1/components",
module_stream_v1_test_components);

Expand Down

0 comments on commit 6724516

Please sign in to comment.