Skip to content

Commit

Permalink
formated
Browse files Browse the repository at this point in the history
  • Loading branch information
chenliTW committed Jan 12, 2020
1 parent 51391b9 commit 095c23b
Showing 1 changed file with 150 additions and 87 deletions.
237 changes: 150 additions & 87 deletions modulemd/tests/test-modulemd-merger.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ merger_test_deduplicate (CommonMmdTestFixture *fixture,


static void
merger_test_merger (CommonMmdTestFixture *fixture,
gconstpointer user_data)
merger_test_merger (CommonMmdTestFixture *fixture, gconstpointer user_data)
{
g_autoptr (ModulemdModuleIndex) base_index = NULL;
g_autofree gchar *yaml_path = NULL;
Expand All @@ -125,80 +124,112 @@ merger_test_merger (CommonMmdTestFixture *fixture,
gint32 random_high;

/* Get a set of o = NULLbjects in a ModuleIndex */
yaml_path = g_strdup_printf ("%s/merging-base.yaml", g_getenv ("TEST_DATA_PATH"));
yaml_path =
g_strdup_printf ("%s/merging-base.yaml", g_getenv ("TEST_DATA_PATH"));
base_index = modulemd_module_index_new ();
modulemd_module_index_update_from_file (base_index, yaml_path, TRUE, &failures,&error);
g_clear_pointer(&yaml_path,g_free);
modulemd_module_index_update_from_file (
base_index, yaml_path, TRUE, &failures, &error);
g_clear_pointer (&yaml_path, g_free);

/* Baseline */
httpd = modulemd_module_index_get_module (base_index, "httpd");
httpd_defaults = (ModulemdDefaultsV1*)modulemd_module_get_defaults(httpd);
httpd_defaults = (ModulemdDefaultsV1 *)modulemd_module_get_defaults (httpd);
g_assert_nonnull (httpd_defaults);

g_assert_cmpstr (modulemd_defaults_v1_get_default_stream(httpd_defaults,NULL), == , "2.2");

httpd_profile_streams = modulemd_defaults_v1_get_streams_with_default_profiles_as_strv(httpd_defaults,NULL);
g_assert_cmpstr (
modulemd_defaults_v1_get_default_stream (httpd_defaults, NULL), ==, "2.2");

httpd_profile_streams =
modulemd_defaults_v1_get_streams_with_default_profiles_as_strv (
httpd_defaults, NULL);
g_assert_cmpint (g_strv_length (httpd_profile_streams), ==, 2);
g_assert_true (g_strv_contains((const char **)httpd_profile_streams, "2.2"));
g_assert_true (g_strv_contains((const char **)httpd_profile_streams, "2.8"));
g_clear_pointer(&httpd_profile_streams,g_strfreev);
httpd_profile_streams = modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (httpd_defaults, "2.2", NULL);
g_assert_true (
g_strv_contains ((const char **)httpd_profile_streams, "2.2"));
g_assert_true (
g_strv_contains ((const char **)httpd_profile_streams, "2.8"));
g_clear_pointer (&httpd_profile_streams, g_strfreev);
httpd_profile_streams =
modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (
httpd_defaults, "2.2", NULL);
g_assert_cmpint (g_strv_length (httpd_profile_streams), ==, 2);
g_assert_true (g_strv_contains((const char **)httpd_profile_streams,"client"));
g_assert_true (g_strv_contains((const char **)httpd_profile_streams,"server"));
g_clear_pointer(&httpd_profile_streams,g_strfreev);
httpd_profile_streams = modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (httpd_defaults, "2.8", NULL);
g_assert_true (g_strv_contains((const char **)httpd_profile_streams,"notreal"));
g_clear_pointer(&httpd_profile_streams,g_strfreev);

g_assert_cmpstr(modulemd_defaults_v1_get_default_stream(httpd_defaults,"workstation"), == ,"2.4");

httpd_profile_streams = modulemd_defaults_v1_get_streams_with_default_profiles_as_strv(httpd_defaults,"workstation");
g_assert_true (
g_strv_contains ((const char **)httpd_profile_streams, "client"));
g_assert_true (
g_strv_contains ((const char **)httpd_profile_streams, "server"));
g_clear_pointer (&httpd_profile_streams, g_strfreev);
httpd_profile_streams =
modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (
httpd_defaults, "2.8", NULL);
g_assert_true (
g_strv_contains ((const char **)httpd_profile_streams, "notreal"));
g_clear_pointer (&httpd_profile_streams, g_strfreev);

g_assert_cmpstr (
modulemd_defaults_v1_get_default_stream (httpd_defaults, "workstation"),
==,
"2.4");

httpd_profile_streams =
modulemd_defaults_v1_get_streams_with_default_profiles_as_strv (
httpd_defaults, "workstation");
g_assert_cmpint (g_strv_length (httpd_profile_streams), ==, 2);
g_assert_true(g_strv_contains((const char **)httpd_profile_streams,"2.4"));
g_assert_true(g_strv_contains((const char **)httpd_profile_streams,"2.6"));
g_clear_pointer(&httpd_profile_streams,g_strfreev);
httpd_profile_streams = modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (httpd_defaults,"2.4", "workstation");
g_assert_true (
g_strv_contains ((const char **)httpd_profile_streams, "2.4"));
g_assert_true (
g_strv_contains ((const char **)httpd_profile_streams, "2.6"));
g_clear_pointer (&httpd_profile_streams, g_strfreev);
httpd_profile_streams =
modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (
httpd_defaults, "2.4", "workstation");
g_assert_cmpint (g_strv_length (httpd_profile_streams), ==, 1);
g_clear_pointer(&httpd_profile_streams,g_strfreev);
httpd_profile_streams = modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (httpd_defaults,"2.6", "workstation");
g_clear_pointer (&httpd_profile_streams, g_strfreev);
httpd_profile_streams =
modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (
httpd_defaults, "2.6", "workstation");
g_assert_cmpint (g_strv_length (httpd_profile_streams), ==, 3);
g_clear_pointer(&httpd_profile_streams,g_strfreev);
g_clear_pointer (&httpd_profile_streams, g_strfreev);

/*
* Get another set of objects that will override the default stream for
* nodejs
*/

yaml_path = g_strdup_printf ("%s/overriding-nodejs.yaml", g_getenv ("TEST_DATA_PATH"));

yaml_path =
g_strdup_printf ("%s/overriding-nodejs.yaml", g_getenv ("TEST_DATA_PATH"));
override_nodejs_index = modulemd_module_index_new ();
modulemd_module_index_update_from_file (override_nodejs_index, yaml_path, TRUE, &failures,&error);
g_clear_pointer(&yaml_path,g_free);
modulemd_module_index_update_from_file (
override_nodejs_index, yaml_path, TRUE, &failures, &error);
g_clear_pointer (&yaml_path, g_free);

/*
* Test that adding both of these at the same priority level results in
* the no default stream
*/
merger = modulemd_module_index_merger_new ();
modulemd_module_index_merger_associate_index(merger,base_index, 0);
modulemd_module_index_merger_associate_index(merger,override_nodejs_index, 0);

merged_index = modulemd_module_index_merger_resolve(merger,NULL);
g_clear_object(&merger);
modulemd_module_index_merger_associate_index (merger, base_index, 0);
modulemd_module_index_merger_associate_index (
merger, override_nodejs_index, 0);

merged_index = modulemd_module_index_merger_resolve (merger, NULL);
g_clear_object (&merger);

nodejs = modulemd_module_index_get_module(merged_index,"nodejs");
g_assert_nonnull(nodejs);
nodejs = modulemd_module_index_get_module (merged_index, "nodejs");
g_assert_nonnull (nodejs);

nodejs_defaults = (ModulemdDefaultsV1*)modulemd_module_get_defaults(nodejs);
g_assert_nonnull(nodejs_defaults);
g_assert_null(modulemd_defaults_v1_get_default_stream(nodejs_defaults,NULL));
g_clear_object(&merged_index);
nodejs_defaults =
(ModulemdDefaultsV1 *)modulemd_module_get_defaults (nodejs);
g_assert_nonnull (nodejs_defaults);
g_assert_null (
modulemd_defaults_v1_get_default_stream (nodejs_defaults, NULL));
g_clear_object (&merged_index);

/* Get another set of objects that will override g_assert_null(modulemd_defaults_v1_get_default_stream the above */
yaml_path = g_strdup_printf ("%s/overriding.yaml", g_getenv ("TEST_DATA_PATH"));
yaml_path =
g_strdup_printf ("%s/overriding.yaml", g_getenv ("TEST_DATA_PATH"));
override_index = modulemd_module_index_new ();
modulemd_module_index_update_from_file (override_index, yaml_path, TRUE, &failures,&error);
g_clear_pointer(&yaml_path,g_free);
modulemd_module_index_update_from_file (
override_index, yaml_path, TRUE, &failures, &error);
g_clear_pointer (&yaml_path, g_free);

/*
* Test that override_index at a higher priority level succeeds
Expand All @@ -208,55 +239,87 @@ merger_test_merger (CommonMmdTestFixture *fixture,
* sorting issues.
*/
merger = modulemd_module_index_merger_new ();
random_low = g_random_int_range(1,100);
random_high = g_random_int_range(101,999);
printf("Low priority: %d, High priority: %d",random_low,random_high);
modulemd_module_index_merger_associate_index (merger, base_index , random_low);
modulemd_module_index_merger_associate_index (merger, override_index , random_high);
random_low = g_random_int_range (1, 100);
random_high = g_random_int_range (101, 999);
printf ("Low priority: %d, High priority: %d", random_low, random_high);
modulemd_module_index_merger_associate_index (
merger, base_index, random_low);
modulemd_module_index_merger_associate_index (
merger, override_index, random_high);

merged_index = modulemd_module_index_merger_resolve(merger,NULL);
g_assert_nonnull(merged_index);
g_clear_object(&merger);
merged_index = modulemd_module_index_merger_resolve (merger, NULL);
g_assert_nonnull (merged_index);
g_clear_object (&merger);

/*Validate merged results*/

/*HTTPD*/
merged_httpd_defaults = (ModulemdDefaultsV1*)modulemd_module_get_defaults(modulemd_module_index_get_module(merged_index,"httpd"));
g_assert_nonnull(merged_httpd_defaults);

g_assert_cmpstr(modulemd_defaults_v1_get_default_stream(merged_httpd_defaults,NULL), == ,"2.4");

httpd_profile_streams = modulemd_defaults_v1_get_streams_with_default_profiles_as_strv(merged_httpd_defaults,NULL);
g_assert_true(g_strv_contains((const char **)httpd_profile_streams,"2.2"));
g_assert_true(g_strv_contains((const char **)httpd_profile_streams,"2.4"));
g_clear_pointer(&httpd_profile_streams,g_strfreev);
httpd_profile_streams = modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (merged_httpd_defaults, "2.2", NULL);
merged_httpd_defaults = (ModulemdDefaultsV1 *)modulemd_module_get_defaults (
modulemd_module_index_get_module (merged_index, "httpd"));
g_assert_nonnull (merged_httpd_defaults);

g_assert_cmpstr (
modulemd_defaults_v1_get_default_stream (merged_httpd_defaults, NULL),
==,
"2.4");

httpd_profile_streams =
modulemd_defaults_v1_get_streams_with_default_profiles_as_strv (
merged_httpd_defaults, NULL);
g_assert_true (
g_strv_contains ((const char **)httpd_profile_streams, "2.2"));
g_assert_true (
g_strv_contains ((const char **)httpd_profile_streams, "2.4"));
g_clear_pointer (&httpd_profile_streams, g_strfreev);
httpd_profile_streams =
modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (
merged_httpd_defaults, "2.2", NULL);
g_assert_cmpint (g_strv_length (httpd_profile_streams), ==, 2);
g_assert_true (g_strv_contains((const char **)httpd_profile_streams,"client"));
g_assert_true (g_strv_contains((const char **)httpd_profile_streams,"server"));
g_clear_pointer(&httpd_profile_streams,g_strfreev);
httpd_profile_streams = modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (merged_httpd_defaults, "2.4", NULL);
g_assert_true (g_strv_contains((const char **)httpd_profile_streams,"client"));
g_assert_true (g_strv_contains((const char **)httpd_profile_streams,"server"));
g_clear_pointer(&httpd_profile_streams,g_strfreev);

g_assert_cmpstr(modulemd_defaults_v1_get_default_stream(merged_httpd_defaults,"workstation"), == ,"2.8");

httpd_profile_streams = modulemd_defaults_v1_get_streams_with_default_profiles_as_strv(merged_httpd_defaults,"workstation");
g_assert_true (
g_strv_contains ((const char **)httpd_profile_streams, "client"));
g_assert_true (
g_strv_contains ((const char **)httpd_profile_streams, "server"));
g_clear_pointer (&httpd_profile_streams, g_strfreev);
httpd_profile_streams =
modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (
merged_httpd_defaults, "2.4", NULL);
g_assert_true (
g_strv_contains ((const char **)httpd_profile_streams, "client"));
g_assert_true (
g_strv_contains ((const char **)httpd_profile_streams, "server"));
g_clear_pointer (&httpd_profile_streams, g_strfreev);

g_assert_cmpstr (modulemd_defaults_v1_get_default_stream (
merged_httpd_defaults, "workstation"),
==,
"2.8");

httpd_profile_streams =
modulemd_defaults_v1_get_streams_with_default_profiles_as_strv (
merged_httpd_defaults, "workstation");
g_assert_cmpint (g_strv_length (httpd_profile_streams), ==, 3);
g_assert_true(g_strv_contains((const char **)httpd_profile_streams,"2.4"));
g_assert_true(g_strv_contains((const char **)httpd_profile_streams,"2.6"));
g_assert_true(g_strv_contains((const char **)httpd_profile_streams,"2.8"));
g_clear_pointer(&httpd_profile_streams,g_strfreev);
httpd_profile_streams = modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (merged_httpd_defaults,"2.4", "workstation");
g_assert_true (
g_strv_contains ((const char **)httpd_profile_streams, "2.4"));
g_assert_true (
g_strv_contains ((const char **)httpd_profile_streams, "2.6"));
g_assert_true (
g_strv_contains ((const char **)httpd_profile_streams, "2.8"));
g_clear_pointer (&httpd_profile_streams, g_strfreev);
httpd_profile_streams =
modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (
merged_httpd_defaults, "2.4", "workstation");
g_assert_cmpint (g_strv_length (httpd_profile_streams), ==, 1);
g_clear_pointer(&httpd_profile_streams,g_strfreev);
httpd_profile_streams = modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (merged_httpd_defaults,"2.6", "workstation");
g_clear_pointer (&httpd_profile_streams, g_strfreev);
httpd_profile_streams =
modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (
merged_httpd_defaults, "2.6", "workstation");
g_assert_cmpint (g_strv_length (httpd_profile_streams), ==, 3);
g_clear_pointer(&httpd_profile_streams,g_strfreev);
httpd_profile_streams = modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (merged_httpd_defaults,"2.8", "workstation");
g_clear_pointer (&httpd_profile_streams, g_strfreev);
httpd_profile_streams =
modulemd_defaults_v1_get_default_profiles_for_stream_as_strv (
merged_httpd_defaults, "2.8", "workstation");
g_assert_cmpint (g_strv_length (httpd_profile_streams), ==, 4);
g_clear_pointer(&httpd_profile_streams,g_strfreev);
g_clear_pointer (&httpd_profile_streams, g_strfreev);
}


Expand Down

0 comments on commit 095c23b

Please sign in to comment.