Skip to content

Commit

Permalink
Extends tests for ModuleStream.depends_on_stream()
Browse files Browse the repository at this point in the history
The tests for depends_on_stream() and build_depends_on_stream() is modified to handle empty lists
Replicates the existing python tests, and newly added tests for depends_on_stream to C.
Fixes : fedora-modularity#192
related:  fedora-modularity#199
  • Loading branch information
athira-selvam committed Feb 28, 2019
1 parent 707a598 commit 873dc5c
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 3 deletions.
13 changes: 10 additions & 3 deletions modulemd/v2/tests/ModulemdTests/modulestream.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,6 @@ def test_v2_yaml(self):

assert 'rawhide' in stream.get_servicelevel_names()
assert 'production' in stream.get_servicelevel_names()

sl = stream.get_servicelevel('rawhide')
assert sl is not None
assert sl.props.name == 'rawhide'
Expand Down Expand Up @@ -1035,8 +1034,16 @@ def test_depends_on_stream(self):
stream.build_depends_on_stream(
'platform', 'f28'), False)

self.assertEqual(stream.depends_on_stream('base', 'f30'), False)
self.assertEqual(stream.depends_on_stream('base', 'f30'), False)
self.assertEqual(
stream.depends_on_stream(
'base', ''), False)
self.assertEqual(
stream.build_depends_on_stream(
'base', ''), False)

ret = stream.build_depends_on_stream(
'platform', '')
assert (ret is True or ret is False)


if __name__ == '__main__':
Expand Down
159 changes: 159 additions & 0 deletions modulemd/v2/tests/test-modulemd-modulestream.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,152 @@ module_stream_test_copy (ModuleStreamFixture *fixture, gconstpointer user_data)
}
}

static void
module_stream_v1_test_depends_on_stream (ModuleStreamFixture *fixture,
gconstpointer user_data)
{
g_autoptr (ModulemdModuleStream) stream = NULL;
g_autofree gchar *path = NULL;
g_autoptr (GError) error = NULL;
g_autofree gchar *module_name = NULL;
g_autofree gchar *module_stream = NULL;
gboolean ret;

path = g_strdup_printf ("%s/modulemd/v2/tests/test_data/dependson_v1.yaml",
g_getenv ("MESON_SOURCE_ROOT"));
g_assert_nonnull (path);
stream = modulemd_module_stream_read_file (
path, TRUE, module_name, module_stream, &error);
g_assert_nonnull (stream);
g_assert_true (
modulemd_module_stream_depends_on_stream (stream, "platform", "f30"));
g_clear_object (&stream);

stream = modulemd_module_stream_read_file (
path, TRUE, module_name, module_stream, &error);
g_assert_nonnull (stream);
g_assert_true (modulemd_module_stream_build_depends_on_stream (
stream, "platform", "f30"));
g_clear_object (&stream);

stream = modulemd_module_stream_read_file (
path, TRUE, module_name, module_stream, &error);
g_assert_nonnull (stream);
g_assert_false (
modulemd_module_stream_depends_on_stream (stream, "platform", "f28"));
g_clear_object (&stream);

stream = modulemd_module_stream_read_file (
path, TRUE, module_name, module_stream, &error);
g_assert_nonnull (stream);
g_assert_false (modulemd_module_stream_build_depends_on_stream (
stream, "platform", "f28"));
g_clear_object (&stream);

stream = modulemd_module_stream_read_file (
path, TRUE, module_name, module_stream, &error);
g_assert_nonnull (stream);
g_assert_false (
modulemd_module_stream_depends_on_stream (stream, "base", "f30"));
g_clear_object (&stream);

stream = modulemd_module_stream_read_file (
path, TRUE, module_name, module_stream, &error);
g_assert_nonnull (stream);
g_assert_false (
modulemd_module_stream_build_depends_on_stream (stream, "base", "f30"));
g_clear_object (&stream);

stream = modulemd_module_stream_read_file (
path, TRUE, module_name, module_stream, &error);
g_assert_nonnull (stream);
ret = modulemd_module_stream_depends_on_stream (stream, "platform", "");
g_assert (ret == 0 || ret == 1);
g_clear_object (&stream);

stream = modulemd_module_stream_read_file (
path, TRUE, module_name, module_stream, &error);
g_assert_nonnull (stream);
ret =
modulemd_module_stream_build_depends_on_stream (stream, "platform", "");
g_assert (ret == 0 || ret == 1);
g_clear_object (&stream);
}

static void
module_stream_v2_test_depends_on_stream (ModuleStreamFixture *fixture,
gconstpointer user_data)
{
g_autoptr (ModulemdModuleStream) stream = NULL;
g_autofree gchar *path = NULL;
g_autoptr (GError) error = NULL;
g_autofree gchar *module_name = NULL;
g_autofree gchar *module_stream = NULL;
gboolean ret;


path = g_strdup_printf ("%s/modulemd/v2/tests/test_data/dependson_v2.yaml",
g_getenv ("MESON_SOURCE_ROOT"));
g_assert_nonnull (path);
stream = modulemd_module_stream_read_file (
path, TRUE, module_name, module_stream, &error);
g_assert_nonnull (stream);
g_assert_true (
modulemd_module_stream_depends_on_stream (stream, "platform", "f30"));
g_clear_object (&stream);

stream = modulemd_module_stream_read_file (
path, TRUE, module_name, module_stream, &error);
g_assert_nonnull (stream);
g_assert_true (modulemd_module_stream_build_depends_on_stream (
stream, "platform", "f30"));
g_clear_object (&stream);

stream = modulemd_module_stream_read_file (
path, TRUE, module_name, module_stream, &error);
g_assert_nonnull (stream);
g_assert_false (
modulemd_module_stream_depends_on_stream (stream, "platform", "f28"));
g_clear_object (&stream);

stream = modulemd_module_stream_read_file (
path, TRUE, module_name, module_stream, &error);
g_assert_nonnull (stream);
g_assert_false (modulemd_module_stream_build_depends_on_stream (
stream, "platform", "f28"));
g_clear_object (&stream);

stream = modulemd_module_stream_read_file (
path, TRUE, module_name, module_stream, &error);
g_assert_nonnull (stream);
g_assert_false (
modulemd_module_stream_depends_on_stream (stream, "base", "f30"));
g_clear_object (&stream);

stream = modulemd_module_stream_read_file (
path, TRUE, module_name, module_stream, &error);
g_assert_nonnull (stream);
g_assert_false (
modulemd_module_stream_build_depends_on_stream (stream, "base", "f30"));
g_clear_object (&stream);

stream = modulemd_module_stream_read_file (
path, TRUE, module_name, module_stream, &error);
g_assert_nonnull (stream);
ret = modulemd_module_stream_depends_on_stream (stream, "platform", "");
g_assert (ret == 0 || ret == 1);
g_clear_object (&stream);

stream = modulemd_module_stream_read_file (
path, TRUE, module_name, module_stream, &error);
g_assert_nonnull (stream);
ret =
modulemd_module_stream_build_depends_on_stream (stream, "platform", "");
g_assert (ret == 0 || ret == 1);
g_clear_object (&stream);
}


static void
module_stream_v1_test_parse_dump (ModuleStreamFixture *fixture,
gconstpointer user_data)
Expand Down Expand Up @@ -525,6 +671,19 @@ main (int argc, char *argv[])
NULL,
module_stream_test_copy,
NULL);
g_test_add ("/modulemd/v2/modulestream/v1/depends_on_stream",
ModuleStreamFixture,
NULL,
NULL,
module_stream_v1_test_depends_on_stream,
NULL);
g_test_add ("/modulemd/v2/modulestream/v2/depends_on_stream",
ModuleStreamFixture,
NULL,
NULL,
module_stream_v2_test_depends_on_stream,
NULL);


g_test_add ("/modulemd/v2/modulestream/v1/parse_dump",
ModuleStreamFixture,
Expand Down

0 comments on commit 873dc5c

Please sign in to comment.