Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy Python tests for Modulemd.ModuleStream.rpm_filters into C #406

Merged
merged 2 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions modulemd/tests/ModulemdTests/modulestream.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,17 @@ def test_rpm_filters(self):
for version in modulestream_versions:
stream = Modulemd.ModuleStream.new(version)

stream.add_rpm_filter("foo")
stream.add_rpm_filter("bar")
assert "foo" in stream.get_rpm_filters()
assert "bar" in stream.get_rpm_filters()
assert len(stream.get_rpm_filters()) == 2

stream.remove_rpm_filter("bar")
assert "foo" in stream.get_rpm_filters()
assert len(stream.get_rpm_filters()) == 1

stream.clear_rpm_filters()
assert len(stream.get_rpm_filters()) == 0

def test_servicelevels(self):
Expand Down
84 changes: 84 additions & 0 deletions modulemd/tests/test-modulemd-modulestream.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,77 @@ module_stream_v2_test_profiles (ModuleStreamFixture *fixture,
g_clear_pointer (&rpms, g_strfreev);
}

static void
module_stream_v1_test_rpm_filters (ModuleStreamFixture *fixture,
gconstpointer user_data)
{
g_autoptr (ModulemdModuleStreamV1) stream = NULL;
g_auto (GStrv) filters = NULL;

stream = modulemd_module_stream_v1_new ("sssd", NULL);

// Test add_rpm_filter
modulemd_module_stream_v1_add_rpm_filter (stream, "foo");
modulemd_module_stream_v1_add_rpm_filter (stream, "bar");
filters = modulemd_module_stream_v1_get_rpm_filters_as_strv (stream);

g_assert_true (g_strv_contains ((const gchar *const *)filters, "foo"));
g_assert_true (g_strv_contains ((const gchar *const *)filters, "bar"));
g_assert_cmpint (g_strv_length (filters), ==, 2);
g_clear_pointer (&filters, g_strfreev);

// Test remove_rpm_filter
modulemd_module_stream_v1_remove_rpm_filter (stream, "foo");
filters = modulemd_module_stream_v1_get_rpm_filters_as_strv (stream);

g_assert_true (g_strv_contains ((const gchar *const *)filters, "bar"));
g_assert_cmpint (g_strv_length (filters), ==, 1);
g_clear_pointer (&filters, g_strfreev);

// Test clear_rpm_filters
modulemd_module_stream_v1_clear_rpm_filters (stream);
filters = modulemd_module_stream_v1_get_rpm_filters_as_strv (stream);
g_assert_cmpint (g_strv_length (filters), ==, 0);

g_clear_pointer (&filters, g_strfreev);
g_clear_object (&stream);
}

static void
module_stream_v2_test_rpm_filters (ModuleStreamFixture *fixture,
gconstpointer user_data)
{
g_autoptr (ModulemdModuleStreamV2) stream = NULL;
g_auto (GStrv) filters = NULL;

stream = modulemd_module_stream_v2_new ("sssd", NULL);

// Test add_rpm_filter
modulemd_module_stream_v2_add_rpm_filter (stream, "foo");
modulemd_module_stream_v2_add_rpm_filter (stream, "bar");
filters = modulemd_module_stream_v2_get_rpm_filters_as_strv (stream);

g_assert_true (g_strv_contains ((const gchar *const *)filters, "foo"));
g_assert_true (g_strv_contains ((const gchar *const *)filters, "bar"));
g_assert_cmpint (g_strv_length (filters), ==, 2);
g_clear_pointer (&filters, g_strfreev);

// Test remove_rpm_filter
modulemd_module_stream_v2_remove_rpm_filter (stream, "foo");
filters = modulemd_module_stream_v2_get_rpm_filters_as_strv (stream);

g_assert_true (g_strv_contains ((const gchar *const *)filters, "bar"));
g_assert_cmpint (g_strv_length (filters), ==, 1);
g_clear_pointer (&filters, g_strfreev);

// Test clear_rpm_filters
modulemd_module_stream_v2_clear_rpm_filters (stream);
filters = modulemd_module_stream_v2_get_rpm_filters_as_strv (stream);
g_assert_cmpint (g_strv_length (filters), ==, 0);

g_clear_pointer (&filters, g_strfreev);
g_clear_object (&stream);
}

static void
module_stream_v1_test_documentation (ModuleStreamFixture *fixture,
Expand Down Expand Up @@ -2018,6 +2089,19 @@ main (int argc, char *argv[])
module_stream_v2_test_profiles,
NULL);

g_test_add ("/modulemd/v2/modulestream/v1/rpm_filters",
ModuleStreamFixture,
NULL,
NULL,
module_stream_v1_test_rpm_filters,
NULL);

g_test_add ("/modulemd/v2/modulestream/v2/rpm_filters",
ModuleStreamFixture,
NULL,
NULL,
module_stream_v2_test_rpm_filters,
NULL);
g_test_add ("/modulemd/v2/modulestream/v1/components",
ModuleStreamFixture,
NULL,
Expand Down