Skip to content

Commit

Permalink
modules: Add a test for enabling default modules
Browse files Browse the repository at this point in the history
  • Loading branch information
pkratoch committed Jan 25, 2024
1 parent 074ab10 commit d60e8da
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/libdnf5/module/test_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,50 @@ void ModuleTest::test_module_enable() {
}


void ModuleTest::test_module_enable_default() {
add_repo_repomd("repomd-modules");

// Add module enable goal operation
libdnf5::Goal goal(base);
goal.add_module_enable("NoStaticContext", libdnf5::GoalJobSettings());
auto transaction = goal.resolve();

// Active modules contain the enabled NoStaticContext with its default stream latest, its dependency gooseberry
// and the default stream of module berries
std::vector<std::string> expected_active_module_specs{
"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<std::string> active_module_specs;
for (auto & module_item : base.get_module_sack()->get_active_modules()) {
active_module_specs.push_back(module_item->get_full_identifier());
}
std::sort(active_module_specs.begin(), active_module_specs.end());
CPPUNIT_ASSERT_EQUAL(expected_active_module_specs, active_module_specs);

// Run the transaction
CPPUNIT_ASSERT_EQUAL(libdnf5::base::Transaction::TransactionRunResult::SUCCESS, transaction.run());

auto system_state = (base.*get(priv_impl()))->get_system_state();

// Module NoStaticContext is ENABLED because it was explicitly enabled
CPPUNIT_ASSERT_EQUAL(
libdnf5::system::ModuleState({"latest", ModuleStatus::ENABLED, {}}),
system_state.get_module_state("NoStaticContext"));
// Module goosebery is ENABLED because module NoStaticContext requires it
CPPUNIT_ASSERT_EQUAL(
libdnf5::system::ModuleState({"5.5", ModuleStatus::ENABLED, {}}), system_state.get_module_state("gooseberry"));

// None of the other modules are ENABLED
for (auto [name, module_state] : system_state.get_module_states()) {
if (name != "NoStaticContext" && name != "gooseberry") {
CPPUNIT_ASSERT_EQUAL(libdnf5::system::ModuleState({"", ModuleStatus::AVAILABLE, {}}), module_state);
}
}
}


void ModuleTest::test_module_disable() {
add_repo_repomd("repomd-modules");

Expand Down
2 changes: 2 additions & 0 deletions test/libdnf5/module/test_module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ModuleTest : public BaseTestCase {
CPPUNIT_TEST(test_query_spec);
CPPUNIT_TEST(test_module_db);
CPPUNIT_TEST(test_module_enable);
CPPUNIT_TEST(test_module_enable_default);
CPPUNIT_TEST(test_module_disable);
CPPUNIT_TEST(test_module_disable_enabled);
CPPUNIT_TEST(test_module_reset);
Expand All @@ -54,6 +55,7 @@ class ModuleTest : public BaseTestCase {
void test_query_spec();
void test_module_db();
void test_module_enable();
void test_module_enable_default();
void test_module_disable();
void test_module_disable_enabled();
void test_module_reset();
Expand Down

0 comments on commit d60e8da

Please sign in to comment.