Skip to content

Commit

Permalink
modules: Add a new module stream to test data
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pkratoch committed Jan 9, 2024
1 parent 3539458 commit 88836e4
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 22 deletions.
28 changes: 28 additions & 0 deletions test/data/repos-repomd/repomd-modules/repodata/modules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -268,3 +287,12 @@ data:
profiles:
main: [minimal]
...
---
document: modulemd-defaults
version: 1
data:
module: NoStaticContext
stream: latest
profiles:
main: [minimal]
...
4 changes: 2 additions & 2 deletions test/data/repos-repomd/repomd-modules/repodata/repomd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<open-size>864433</open-size>
</data>
<data type="modules">
<checksum type="sha256">3afb8a29deb024cf0bfecf0623d1a0feb11d0ca77e4564f5137cbd3fd91a718a</checksum>
<open-checksum type="sha256">3afb8a29deb024cf0bfecf0623d1a0feb11d0ca77e4564f5137cbd3fd91a718a</open-checksum>
<checksum type="sha256">1f1a76629e8eeb80db6d5de9d43a36529882e2864c97283288f24d03ec31748b</checksum>
<open-checksum type="sha256">1f1a76629e8eeb80db6d5de9d43a36529882e2864c97283288f24d03ec31748b</open-checksum>
<location href="repodata/modules.yaml" />
<timestamp>1641802880</timestamp>
<size>492</size>
Expand Down
56 changes: 36 additions & 20 deletions test/libdnf5/module/test_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -108,7 +108,10 @@ void ModuleTest::test_resolve() {
CPPUNIT_ASSERT_EQUAL(ModuleSack::ModuleErrorType::NO_ERROR, module_sack->resolve_active_module_items().second);

std::vector<std::string> 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<std::string> active_module_specs;

for (auto & module_item : module_sack->get_active_modules()) {
Expand Down Expand Up @@ -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());
}

{
Expand All @@ -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());
}

{
Expand Down Expand Up @@ -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<std::string> 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",
Expand Down Expand Up @@ -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<std::string> 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<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());
Expand Down Expand Up @@ -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<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());
Expand All @@ -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);
}
}
Expand All @@ -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<std::string> 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<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());
Expand Down Expand Up @@ -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<std::string> 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",
Expand Down

0 comments on commit 88836e4

Please sign in to comment.