Skip to content

Commit

Permalink
Modular advisories unit-test fixes
Browse files Browse the repository at this point in the history
- Adds module requires to have more logical test data.
- Removes redundant test.
- Fixes wrong and outdated comments.
  • Loading branch information
kontura authored and j-mracek committed Jun 3, 2021
1 parent 6c2ac67 commit 1ecfa6a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 37 deletions.
6 changes: 6 additions & 0 deletions data/tests/advisories/modules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ data:
license:
module:
- MIT
dependencies:
- requires:
perl: ["5.23"]
profiles:
default:
rpms: ["test-perl-DBI"]
Expand All @@ -52,6 +55,9 @@ data:
license:
module:
- MIT
dependencies:
- requires:
perl: ["5.23"]
profiles:
default:
rpms: ["test-perl-DBI"]
Expand Down
Binary file modified data/tests/advisories/repodata/modules.yaml.gz
Binary file not shown.
Binary file modified data/tests/advisories/repodata/primary.xml.gz
Binary file not shown.
26 changes: 13 additions & 13 deletions data/tests/advisories/repodata/repomd.xml
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<repomd xmlns="http://linux.duke.edu/metadata/repo" xmlns:rpm="http://linux.duke.edu/metadata/rpm">
<revision>1612879414</revision>
<revision>1621268151</revision>
<data type="primary">
<checksum type="sha256">b69e4467719314fdb155872cf9c8e895d5b169c0506c5180c512d693c48f0f4b</checksum>
<open-checksum type="sha256">8606d1f777859f167f7bd0bf8a1d532abedcb4db143b719e631e1040800fd1f0</open-checksum>
<checksum type="sha256">85618a80c1345a3010253df7257766980209f86697d979bfe18ea11707a6047d</checksum>
<open-checksum type="sha256">167f862cc208d46dd58b2702c86abad087383c03c3030ed714c7baeff2d00cca</open-checksum>
<location href="repodata/primary.xml.gz"/>
<timestamp>1612879414</timestamp>
<size>743</size>
<timestamp>1621268151</timestamp>
<size>744</size>
<open-size>2665</open-size>
</data>
<data type="filelists">
<checksum type="sha256">efbf7f021163a3c7698a257351e327102c60bb39a7bdceee77c421f064205e99</checksum>
<open-checksum type="sha256">ca5620e2734574d04d3c01ae5a72f865313369954698d71776076b9cbd831bbd</open-checksum>
<location href="repodata/filelists.xml.gz"/>
<timestamp>1612879414</timestamp>
<timestamp>1621268151</timestamp>
<size>311</size>
<open-size>511</open-size>
</data>
<data type="other">
<checksum type="sha256">6673953e1f28f55b9d4c3f38a9e3c0e0ff88ad06fb693b7f15eb241a81b80d71</checksum>
<open-checksum type="sha256">0997c242bf1b96372d7a625a73de23dced68cae9375baff0c73215a07693b3f4</open-checksum>
<location href="repodata/other.xml.gz"/>
<timestamp>1612879414</timestamp>
<timestamp>1621268151</timestamp>
<size>310</size>
<open-size>507</open-size>
</data>
<data type="modules">
<checksum type="sha256">a815d0669b15b97dd6260713405c79045eeda10aedb6460a0f742b86cc236cca</checksum>
<open-checksum type="sha256">0d1063b74e3a7cb4c7cdc3b2080b1901c347693140765534f8c5c3d8b964778a</open-checksum>
<checksum type="sha256">20062f5451a8da7a8951336f119f6a8f7411286849b53dc8a179c75270b73216</checksum>
<open-checksum type="sha256">6a10d0c26f84f5f74d9ecc379016dd9ed9b9d173a4db17f6dc90665d8563fdea</open-checksum>
<location href="repodata/modules.yaml.gz"/>
<timestamp>1612879414</timestamp>
<size>300</size>
<open-size>1019</open-size>
<timestamp>1621268151</timestamp>
<size>331</size>
<open-size>1117</open-size>
</data>
<data type="updateinfo">
<checksum type="sha256">9d791d16c2adc2d7d4c85b45f2a704edac62a926b09fc20df73207f4190acd49</checksum>
<open-checksum type="sha256">3cf7df860860ac7a4a8e64a1a2d71c1ec43225dacbfe09a0cff80f28be3825da</open-checksum>
<location href="repodata/updateinfo.xml.gz"/>
<timestamp>1612879414</timestamp>
<timestamp>1621268151</timestamp>
<size>708</size>
<open-size>2414</open-size>
</data>
Expand Down
23 changes: 4 additions & 19 deletions tests/libdnf/sack/AdvisoryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,6 @@ void AdvisoryTest::testGetPackages()
CPPUNIT_ASSERT(pkgsvector.size() == 4);
}

void AdvisoryTest::testGetApplicablePackagesModulesNotSetup()
{
std::vector<libdnf::AdvisoryPkg> pkgsvector;

// When modules are not setup all advisory collections are applicable and we get all packages
advisory->getApplicablePackages(pkgsvector);
CPPUNIT_ASSERT(pkgsvector.size() == 4);
CPPUNIT_ASSERT(!g_strcmp0(pkgsvector[0].getNameString(), "test-perl-DBI"));
CPPUNIT_ASSERT(!g_strcmp0(pkgsvector[1].getNameString(), "test-perl-DBI-new-collection-override"));
CPPUNIT_ASSERT(!g_strcmp0(pkgsvector[2].getNameString(), "test-perl-DBI"));
CPPUNIT_ASSERT(!g_strcmp0(pkgsvector[3].getNameString(), "not-present"));
}

void AdvisoryTest::testGetApplicablePackagesModulesSetupNoneEnabled()
{
std::vector<libdnf::AdvisoryPkg> pkgsvector;
Expand All @@ -122,16 +109,14 @@ void AdvisoryTest::testGetApplicablePackagesOneApplicableCollection()
{
std::vector<libdnf::AdvisoryPkg> pkgsvector;

// When I keep enabled only perl-DBI module I get packages from all collections that contain that module
// When I keep enabled only perl module I get packages from all collections that contain that module
libdnf::ModulePackageContainer * modules = dnf_sack_get_module_container(sack);
modules->reset("perl");
modules->reset("perl-DBI");
dnf_sack_filter_modules_v2(sack, modules, nullptr, tmpdir, nullptr, true, false, false);

advisory->getApplicablePackages(pkgsvector);
CPPUNIT_ASSERT(pkgsvector.size() == 3);
CPPUNIT_ASSERT(!g_strcmp0(pkgsvector[0].getNameString(), "test-perl-DBI"));
CPPUNIT_ASSERT(!g_strcmp0(pkgsvector[1].getNameString(), "test-perl-DBI-new-collection-override"));
CPPUNIT_ASSERT(!g_strcmp0(pkgsvector[2].getNameString(), "test-perl-DBI"));
CPPUNIT_ASSERT(pkgsvector.size() == 1);
CPPUNIT_ASSERT(!g_strcmp0(pkgsvector[0].getNameString(), "not-present"));
}

void AdvisoryTest::testGetApplicablePackagesMultipleApplicableCollections()
Expand Down
2 changes: 0 additions & 2 deletions tests/libdnf/sack/AdvisoryTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class AdvisoryTest : public CppUnit::TestCase
CPPUNIT_TEST(testGetSeverity);
CPPUNIT_TEST(testGetTitle);
CPPUNIT_TEST(testGetPackages);
CPPUNIT_TEST(testGetApplicablePackagesModulesNotSetup);
CPPUNIT_TEST(testGetApplicablePackagesModulesSetupNoneEnabled);
CPPUNIT_TEST(testGetApplicablePackagesOneApplicableCollection);
CPPUNIT_TEST(testGetApplicablePackagesMultipleApplicableCollections);
Expand All @@ -38,7 +37,6 @@ class AdvisoryTest : public CppUnit::TestCase
void testGetSeverity();
void testGetTitle();
void testGetPackages();
void testGetApplicablePackagesModulesNotSetup();
void testGetApplicablePackagesModulesSetupNoneEnabled();
void testGetApplicablePackagesOneApplicableCollection();
void testGetApplicablePackagesMultipleApplicableCollections();
Expand Down
6 changes: 3 additions & 3 deletions tests/libdnf/sack/QueryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void QueryTest::testQueryGetAdvisoryPkgs()
HyQuery query = new libdnf::Query(sack);
std::vector<libdnf::AdvisoryPkg> advisoryPkgs;

// When modules are not setup all advisory collections are applicable
// Starting with perl and perl-DBI enabled
query->getAdvisoryPkgs(HY_EQ, advisoryPkgs);
CPPUNIT_ASSERT(advisoryPkgs.size() == 2);
// We get test-perl-DBI twice because its in two collections
Expand All @@ -84,7 +84,7 @@ void QueryTest::testQueryGetAdvisoryPkgs()
query->getAdvisoryPkgs(HY_EQ, advisoryPkgs);
CPPUNIT_ASSERT(advisoryPkgs.size() == 0);

// When I enable a module from multiple collections that contain a present package I get them
// When I enable a module with multiple collections I will receave advisory packages only for active context
CPPUNIT_ASSERT(modules->enable("perl-DBI", "master", false));
dnf_sack_filter_modules_v2(sack, modules, nullptr, tmpdir, nullptr, true, false, false);

Expand All @@ -99,7 +99,7 @@ void QueryTest::testQueryGetAdvisoryPkgs()

void QueryTest::testQueryFilterAdvisory()
{
// When modules are not setup all advisory collections are applicable and there is no modular filtering
// Starting with perl and perl-DBI enabled
HyQuery query = new libdnf::Query(sack);
query->addFilter(HY_PKG_ADVISORY_TYPE, HY_EQ, "enhancement");
CPPUNIT_ASSERT(query->size() == 2);
Expand Down

0 comments on commit 1ecfa6a

Please sign in to comment.