From 3fb6bba2300b3d608622ab443f669756cebb7383 Mon Sep 17 00:00:00 2001 From: Pavla Kratochvilova Date: Mon, 8 Jan 2024 12:49:04 +0100 Subject: [PATCH] modules: Add a new module stream to test data A new stream of the NoStaticContext module is added and it's also added to defaults. The stream is needed so that there is a module with more than one stream and one default stream. Because of changing the defaults, many tests need to be updated, since the module stream gets enabled whenever there is any enable operation. --- .../repomd-modules/repodata/modules.yaml | 28 ++++++++++ .../repomd-modules/repodata/repomd.xml | 4 +- test/libdnf5/module/test_module.cpp | 56 ++++++++++++------- 3 files changed, 66 insertions(+), 22 deletions(-) diff --git a/test/data/repos-repomd/repomd-modules/repodata/modules.yaml b/test/data/repos-repomd/repomd-modules/repodata/modules.yaml index 87a8cdb74..c6f45c5f3 100644 --- a/test/data/repos-repomd/repomd-modules/repodata/modules.yaml +++ b/test/data/repos-repomd/repomd-modules/repodata/modules.yaml @@ -259,6 +259,25 @@ data: - requires: gooseberry: [5.4] ... +--- + document: modulemd + version: 2 + data: + name: NoStaticContext + stream: latest + version: 1 + arch: x86_64 + summary: Test module + description: Test module + license: + module: [MIT] + profiles: + minimal: + rpms: [] + dependencies: + - requires: + gooseberry: [5.5] +... --- document: modulemd-defaults version: 1 @@ -268,3 +287,12 @@ data: profiles: main: [minimal] ... +--- +document: modulemd-defaults +version: 1 +data: + module: NoStaticContext + stream: latest + profiles: + main: [minimal] +... diff --git a/test/data/repos-repomd/repomd-modules/repodata/repomd.xml b/test/data/repos-repomd/repomd-modules/repodata/repomd.xml index 1f2478850..47df9669d 100644 --- a/test/data/repos-repomd/repomd-modules/repodata/repomd.xml +++ b/test/data/repos-repomd/repomd-modules/repodata/repomd.xml @@ -9,8 +9,8 @@ 864433 - 3afb8a29deb024cf0bfecf0623d1a0feb11d0ca77e4564f5137cbd3fd91a718a - 3afb8a29deb024cf0bfecf0623d1a0feb11d0ca77e4564f5137cbd3fd91a718a + 1f1a76629e8eeb80db6d5de9d43a36529882e2864c97283288f24d03ec31748b + 1f1a76629e8eeb80db6d5de9d43a36529882e2864c97283288f24d03ec31748b 1641802880 492 diff --git a/test/libdnf5/module/test_module.cpp b/test/libdnf5/module/test_module.cpp index 9be4a5c1f..4a3aa0ad2 100644 --- a/test/libdnf5/module/test_module.cpp +++ b/test/libdnf5/module/test_module.cpp @@ -60,7 +60,7 @@ void ModuleTest::test_load() { add_repo_repomd("repomd-modules"); auto module_sack = base.get_module_sack(); - CPPUNIT_ASSERT_EQUAL((size_t)11, module_sack->get_modules().size()); + CPPUNIT_ASSERT_EQUAL((size_t)12, module_sack->get_modules().size()); ModuleQuery query = ModuleQuery(base, false); query.filter_name("meson"); @@ -108,7 +108,10 @@ void ModuleTest::test_resolve() { CPPUNIT_ASSERT_EQUAL(ModuleSack::ModuleErrorType::NO_ERROR, module_sack->resolve_active_module_items().second); std::vector expected_active_module_specs{ - "berries:main:4:6c81f848:x86_64", "gooseberry:5.5:2:72aaf46b6:x86_64", "gooseberry:5.5:3:72aaf46b6:x86_64"}; + "NoStaticContext:latest:1::x86_64", + "berries:main:4:6c81f848:x86_64", + "gooseberry:5.5:2:72aaf46b6:x86_64", + "gooseberry:5.5:3:72aaf46b6:x86_64"}; std::vector active_module_specs; for (auto & module_item : module_sack->get_active_modules()) { @@ -198,7 +201,7 @@ void ModuleTest::test_query_latest() { { // Check we can see all the modules, even ones with duplicit nscva ModuleQuery query(base, false); - CPPUNIT_ASSERT_EQUAL((size_t)14, query.size()); + CPPUNIT_ASSERT_EQUAL((size_t)15, query.size()); } { @@ -210,13 +213,13 @@ void ModuleTest::test_query_latest() { { ModuleQuery query(base, false); query.filter_latest(); - CPPUNIT_ASSERT_EQUAL((size_t)12, query.size()); + CPPUNIT_ASSERT_EQUAL((size_t)13, query.size()); } { ModuleQuery query(base, false); query.filter_latest(-1); - CPPUNIT_ASSERT_EQUAL((size_t)11, query.size()); + CPPUNIT_ASSERT_EQUAL((size_t)12, query.size()); } { @@ -635,8 +638,10 @@ void ModuleTest::test_module_enable() { goal.add_module_enable("fruit-salad:main", libdnf5::GoalJobSettings()); auto transaction = goal.resolve(); - // Active modules contain the enabled fruit-salad, its dependency gooseberry and the default stream of module berries + // Active modules contain the enabled fruit-salad, its dependency gooseberry and the default streams of modules + // NoStaticContext and berries std::vector expected_active_module_specs{ + "NoStaticContext:latest:1::x86_64", "berries:main:4:6c81f848:x86_64", "fruit-salad:main:12:2241675a:x86_64", "gooseberry:5.5:2:72aaf46b6:x86_64", @@ -678,9 +683,12 @@ void ModuleTest::test_module_disable() { goal.add_module_disable("fruit-salad:main", libdnf5::GoalJobSettings()); auto transaction = goal.resolve(); - // Active modules contain the the default stream of module berries and its dependency gooseberry:5.5 + // Active modules contain the the default streams of modules NoStaticContext and berries and their dependency gooseberry:5.5 std::vector expected_active_module_specs{ - "berries:main:4:6c81f848:x86_64", "gooseberry:5.5:2:72aaf46b6:x86_64", "gooseberry:5.5:3:72aaf46b6:x86_64"}; + "NoStaticContext:latest:1::x86_64", + "berries:main:4:6c81f848:x86_64", + "gooseberry:5.5:2:72aaf46b6:x86_64", + "gooseberry:5.5:3:72aaf46b6:x86_64"}; std::vector active_module_specs; for (auto & module_item : base.get_module_sack()->get_active_modules()) { active_module_specs.push_back(module_item->get_full_identifier()); @@ -709,17 +717,19 @@ void ModuleTest::test_module_disable() { void ModuleTest::test_module_disable_enabled() { add_repo_repomd("repomd-modules"); - // Set state of module berries to ENABLED - (base.*get(priv_impl())) - ->get_system_state() - .set_module_state("berries", libdnf5::system::ModuleState({"main", ModuleStatus::ENABLED, {}})); + // Set state of modules NoStaticContext and berries to ENABLED + auto & system_state = (base.*get(priv_impl()))->get_system_state(); + system_state.set_module_state( + "NoStaticContext", libdnf5::system::ModuleState({"latest", ModuleStatus::ENABLED, {}})); + system_state.set_module_state("berries", libdnf5::system::ModuleState({"main", ModuleStatus::ENABLED, {}})); // Add module disable goal operation libdnf5::Goal goal(base); + goal.add_module_disable("NoStaticContext", libdnf5::GoalJobSettings()); goal.add_module_disable("berries", libdnf5::GoalJobSettings()); auto transaction = goal.resolve(); - // Active modules don't contain anything, because the only module that had a default stream was enabled + // Active modules don't contain anything, because the only modules that had default streams were disabled std::vector active_module_specs; for (auto & module_item : base.get_module_sack()->get_active_modules()) { active_module_specs.push_back(module_item->get_full_identifier()); @@ -729,15 +739,16 @@ void ModuleTest::test_module_disable_enabled() { // Run the transaction CPPUNIT_ASSERT_EQUAL(libdnf5::base::Transaction::TransactionRunResult::SUCCESS, transaction.run()); - auto system_state = (base.*get(priv_impl()))->get_system_state(); - - // Module berries is DISABLED because it was explicitly disabled + // Modules NoStaticContext and berries are DISABLED because they were explicitly disabled + CPPUNIT_ASSERT_EQUAL( + libdnf5::system::ModuleState({"", ModuleStatus::DISABLED, {}}), + system_state.get_module_state("NoStaticContext")); CPPUNIT_ASSERT_EQUAL( libdnf5::system::ModuleState({"", ModuleStatus::DISABLED, {}}), system_state.get_module_state("berries")); // None of the other modules is DISABLED for (auto [name, module_state] : system_state.get_module_states()) { - if (name != "berries") { + if (name != "NoStaticContext" && name != "berries") { CPPUNIT_ASSERT_EQUAL(libdnf5::system::ModuleState({"", ModuleStatus::AVAILABLE, {}}), module_state); } } @@ -757,9 +768,13 @@ void ModuleTest::test_module_reset() { goal.add_module_reset("berries", libdnf5::GoalJobSettings()); auto transaction = goal.resolve(); - // Active modules contain the the default stream of module berries and its dependency gooseberry:5.5 + // Active modules contain the the default streams of modules NoStaticContext and berries and their dependency + // gooseberry:5.5 std::vector expected_active_module_specs{ - "berries:main:4:6c81f848:x86_64", "gooseberry:5.5:2:72aaf46b6:x86_64", "gooseberry:5.5:3:72aaf46b6:x86_64"}; + "NoStaticContext:latest:1::x86_64", + "berries:main:4:6c81f848:x86_64", + "gooseberry:5.5:2:72aaf46b6:x86_64", + "gooseberry:5.5:3:72aaf46b6:x86_64"}; std::vector active_module_specs; for (auto & module_item : base.get_module_sack()->get_active_modules()) { active_module_specs.push_back(module_item->get_full_identifier()); @@ -788,8 +803,9 @@ void ModuleTest::test_module_globs() { auto transaction = goal.resolve(); // Active modules contain the enabled fruit-salad and vegetable-salad, its dependency gooseberry and the default - // stream of module berries + // streams of modules NoStaticContext and berries std::vector expected_active_module_specs{ + "NoStaticContext:latest:1::x86_64", "berries:main:4:6c81f848:x86_64", "fruit-salad:main:12:2241675a:x86_64", "gooseberry:5.5:2:72aaf46b6:x86_64",