Skip to content

Commit

Permalink
Add tests for Advisory, Query, DnfPackage regarding advisory collections
Browse files Browse the repository at this point in the history
  • Loading branch information
kontura authored and j-mracek committed Feb 18, 2021
1 parent a3dd17f commit 348b753
Show file tree
Hide file tree
Showing 19 changed files with 663 additions and 0 deletions.
60 changes: 60 additions & 0 deletions data/tests/advisories/modules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
document: modulemd
version: 2
data:
name: perl
stream: 5.23
version: 1
context: aa
arch: x86_64
summary: Perl
description: Perl
license:
module:
- MIT
profiles:
default:
rpms: ["test-perl"]
artifacts:
rpms: ["test-perl-0:5.24-1.module_el8+5182+8241aed2.x86_64"]
...
---
document: modulemd
version: 2
data:
name: perl-DBI
stream: master
version: 2
context: 2b
arch: x86_64
summary: Perl-DBI
description: Perl-DBI
license:
module:
- MIT
profiles:
default:
rpms: ["test-perl-DBI"]
artifacts:
rpms: ["test-perl-DBI-0:1-2.module_el8+6587+9879afr5.x86_64"]
...
---
document: modulemd
version: 2
data:
name: perl-DBI
stream: master
version: 2
context: 2c
arch: x86_64
summary: Perl-DBI
description: Perl-DBI
license:
module:
- MIT
profiles:
default:
rpms: ["test-perl-DBI"]
artifacts:
rpms: ["test-perl-DBI-0:1-2.module_el8+6745+9879ate3.x86_64"]
...
6 changes: 6 additions & 0 deletions data/tests/advisories/recreate
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash

THISDIR=$(readlink -f $(dirname $0))
cd $THISDIR
createrepo_c --no-database --simple-md-filenames .
modifyrepo_c ./updateinfo.xml repodata --simple-md-filenames
Binary file added data/tests/advisories/repodata/filelists.xml.gz
Binary file not shown.
Binary file added data/tests/advisories/repodata/modules.yaml.gz
Binary file not shown.
Binary file added data/tests/advisories/repodata/other.xml.gz
Binary file not shown.
Binary file added data/tests/advisories/repodata/primary.xml.gz
Binary file not shown.
44 changes: 44 additions & 0 deletions data/tests/advisories/repodata/repomd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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>
<data type="primary">
<checksum type="sha256">b69e4467719314fdb155872cf9c8e895d5b169c0506c5180c512d693c48f0f4b</checksum>
<open-checksum type="sha256">8606d1f777859f167f7bd0bf8a1d532abedcb4db143b719e631e1040800fd1f0</open-checksum>
<location href="repodata/primary.xml.gz"/>
<timestamp>1612879414</timestamp>
<size>743</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>
<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>
<size>310</size>
<open-size>507</open-size>
</data>
<data type="modules">
<checksum type="sha256">a815d0669b15b97dd6260713405c79045eeda10aedb6460a0f742b86cc236cca</checksum>
<open-checksum type="sha256">0d1063b74e3a7cb4c7cdc3b2080b1901c347693140765534f8c5c3d8b964778a</open-checksum>
<location href="repodata/modules.yaml.gz"/>
<timestamp>1612879414</timestamp>
<size>300</size>
<open-size>1019</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>
<size>708</size>
<open-size>2414</open-size>
</data>
</repomd>
Binary file added data/tests/advisories/repodata/updateinfo.xml.gz
Binary file not shown.
Binary file not shown.
Binary file not shown.
47 changes: 47 additions & 0 deletions data/tests/advisories/updateinfo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<updates>
<update from="secresponseteam@foo.bar" status="final" type="enhancement" version="3">
<id>FEDORA-2019-0329090518</id>
<title>glibc bug fix</title>
<issued date="2019-03-29 00:00:00"/>
<updated date="2019-03-29 00:00:00"/>
<severity>none</severity>
<rights>Everyone has them</rights>
<summary>summary_1</summary>
<description>Enhance some stuff</description>
<references>
<reference href="https://foobar/foobarupdate_2" id="2222" type="bugzilla" title="222"/>
<reference href="https://foobar/foobarupdate_2" id="2222" type="cve" title="CVE-2999"/>
</references>
<pkglist>
<collection short="named collection">
<name>Foo component</name>
<module name="perl-DBI" stream="master" version="2" context="2c" arch="x86_64"/>
<module name="non" stream="existing" version="2" context="module" arch="x86_64"/>
<package name="test-perl-DBI" version="1" release="2.module_el8+6745+9879ate3" epoch="0" arch="x86_64" src="http://www.foo.org">
<filename>perl-DBI-1-2.module_el8+6745+9879ate3.spec</filename>
<reboot_suggested/>
</package>
<package name="test-perl-DBI-new-collection-override" version="1" release="2.module_el8+6745+9879ate3" epoch="0" arch="x86_64" src="http://www.foo.org">
<filename>perl-DBI-1-2.module_el8+6745+9879ate3.spec</filename>
<reboot_suggested/>
</package>
</collection>
<collection short="unreal collection">
<name>Foo component</name>
<module name="perl-DBI" stream="master" version="2" context="2b" arch="x86_64"/>
<package name="test-perl-DBI" version="1" release="2.module_el8+6587+9879afr5" epoch="0" arch="x86_64" src="http://www.foo.org">
<filename>perl-DBI-1-2.module_el8+6587+9879afr5.spec</filename>
<reboot_suggested/>
</package>
</collection>
<collection short="perl collection">
<name>perl component</name>
<module name="perl" stream="5.23" version="2" context="aa" arch="x86_64"/>
<package name="not-present" version="5.24" release="1.module_el8+5182+8241aed2" epoch="0" arch="x86_64" src="http://www.foo.org">
<filename>not-present-0:5.24-1.module_el8+5182+8241aed2.x86_64</filename>
</package>
</collection>
</pkglist>
</update>
</updates>
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ add_subdirectory(libdnf/module/modulemd)
add_subdirectory(libdnf/module)
add_subdirectory(libdnf/repo)
add_subdirectory(libdnf/transaction)
add_subdirectory(libdnf/sack)
add_subdirectory(hawkey)
add_subdirectory(libdnf)

Expand Down
153 changes: 153 additions & 0 deletions tests/libdnf/sack/AdvisoryTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#include "AdvisoryTest.hpp"

#include "libdnf/dnf-sack-private.hpp"
#include "libdnf/hy-iutil-private.hpp"

CPPUNIT_TEST_SUITE_REGISTRATION(AdvisoryTest);

#define UNITTEST_DIR "/tmp/libdnfXXXXXX"

void AdvisoryTest::setUp()
{
g_autoptr(GError) error = nullptr;

tmpdir = g_strdup(UNITTEST_DIR);
char *retptr = mkdtemp(tmpdir);
CPPUNIT_ASSERT(retptr);

sack = dnf_sack_new();
// Cache should not be needed, setting just to be safe
dnf_sack_set_cachedir(sack, tmpdir);
dnf_sack_set_arch(sack, "x86_64", NULL);
dnf_sack_setup(sack, 0, NULL);
repo = hy_repo_create("test_advisory_repo");
std::string repodata = std::string(TESTDATADIR "/advisories/repodata/");
hy_repo_set_string(repo, HY_REPO_MD_FN, (repodata + "repomd.xml").c_str());
hy_repo_set_string(repo, HY_REPO_PRIMARY_FN, (repodata + "primary.xml.gz").c_str());
hy_repo_set_string(repo, HY_REPO_UPDATEINFO_FN, (repodata + "updateinfo.xml.gz").c_str());
hy_repo_set_string(repo, MODULES_FN, (repodata + "modules.yaml.gz").c_str());
dnf_sack_load_repo(sack, repo, DNF_SACK_LOAD_FLAG_USE_UPDATEINFO, &error);

HyQuery query = new libdnf::Query(sack);
std::vector<libdnf::AdvisoryPkg> advisoryPkgs;
query->getAdvisoryPkgs(HY_EQ, advisoryPkgs);

CPPUNIT_ASSERT(advisoryPkgs.size() > 0);
advisory = advisoryPkgs[0].getAdvisory();
delete query;
}

void AdvisoryTest::tearDown()
{
dnf_remove_recursive_v2(tmpdir, NULL);
delete repo;
delete advisory;
g_object_unref(sack);
g_free(tmpdir);
}

void AdvisoryTest::testGetName()
{
CPPUNIT_ASSERT(!strcmp(advisory->getName(), "FEDORA-2019-0329090518"));
}

void AdvisoryTest::testGetKind()
{
CPPUNIT_ASSERT(advisory->getKind() == DNF_ADVISORY_KIND_ENHANCEMENT);
}

void AdvisoryTest::testGetDescription()
{
CPPUNIT_ASSERT(!strcmp(advisory->getDescription(), "Enhance some stuff"));
}

void AdvisoryTest::testGetRights()
{
CPPUNIT_ASSERT(!strcmp(advisory->getRights(), "Everyone has them"));
}

void AdvisoryTest::testGetSeverity()
{
CPPUNIT_ASSERT(!strcmp(advisory->getSeverity(), "none"));
}

void AdvisoryTest::testGetTitle()
{
CPPUNIT_ASSERT(!strcmp(advisory->getTitle(), "glibc bug fix"));
}

void AdvisoryTest::testGetPackages()
{
std::vector<libdnf::AdvisoryPkg> pkgsvector;
advisory->getPackages(pkgsvector);
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;

// When module are setup but none are enabled no collections are applicable -> no packages
dnf_sack_filter_modules_v2(sack, nullptr, nullptr, tmpdir, nullptr, false, false, false);
advisory->getApplicablePackages(pkgsvector);
CPPUNIT_ASSERT(pkgsvector.size() == 0);
}

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

// When I enable a module I get packages from all collections that contain that module
dnf_sack_filter_modules_v2(sack, nullptr, nullptr, tmpdir, nullptr, false, false, false);
libdnf::ModulePackageContainer * modules = dnf_sack_get_module_container(sack);
CPPUNIT_ASSERT(modules->enable("perl-DBI", "master"));
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"));
}

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

// When I enable modules from multiple collections -> I get packages from all applicable collections
dnf_sack_filter_modules_v2(sack, nullptr, nullptr, tmpdir, nullptr, false, false, false);
libdnf::ModulePackageContainer * modules = dnf_sack_get_module_container(sack);
CPPUNIT_ASSERT(modules->enable("perl", "5.23"));
CPPUNIT_ASSERT(modules->enable("perl-DBI", "master"));
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::testGetModules()
{
std::vector<libdnf::AdvisoryModule> modulesvector;
modulesvector = advisory->getModules();
CPPUNIT_ASSERT(modulesvector.size() == 4);
}

void AdvisoryTest::testGetReferences()
{
std::vector<libdnf::AdvisoryRef> refsvector;
advisory->getReferences(refsvector);
CPPUNIT_ASSERT(refsvector.size() == 2);
}
57 changes: 57 additions & 0 deletions tests/libdnf/sack/AdvisoryTest.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef LIBDNF_ADVISORYTEST_HPP
#define LIBDNF_ADVISORYTEST_HPP

#include <cppunit/TestCase.h>
#include <cppunit/extensions/HelperMacros.h>
#include <memory>

#include <libdnf/sack/advisory.hpp>
#include <libdnf/sack/advisorymodule.hpp>
#include <libdnf/sack/query.hpp>

class AdvisoryTest : public CppUnit::TestCase
{
CPPUNIT_TEST_SUITE(AdvisoryTest);
CPPUNIT_TEST(testGetName);
CPPUNIT_TEST(testGetKind);
CPPUNIT_TEST(testGetDescription);
CPPUNIT_TEST(testGetRights);
CPPUNIT_TEST(testGetSeverity);
CPPUNIT_TEST(testGetTitle);
CPPUNIT_TEST(testGetPackages);
CPPUNIT_TEST(testGetApplicablePackagesModulesNotSetup);
CPPUNIT_TEST(testGetApplicablePackagesModulesSetupNoneEnabled);
CPPUNIT_TEST(testGetApplicablePackagesOneApplicableCollection);
CPPUNIT_TEST(testGetApplicablePackagesMultipleApplicableCollections);
CPPUNIT_TEST(testGetModules);
CPPUNIT_TEST(testGetReferences);
CPPUNIT_TEST_SUITE_END();

public:
void setUp() override;
void tearDown() override;

void testGetName();
void testGetKind();
void testGetDescription();
void testGetRights();
void testGetSeverity();
void testGetTitle();
void testGetPackages();
void testGetApplicablePackagesModulesNotSetup();
void testGetApplicablePackagesModulesSetupNoneEnabled();
void testGetApplicablePackagesOneApplicableCollection();
void testGetApplicablePackagesMultipleApplicableCollections();
void testGetModules();
void testGetReferences();

private:
DnfContext *context = nullptr;
DnfSack *sack = nullptr;
HyRepo repo = nullptr;
libdnf::Advisory *advisory = nullptr;
char* tmpdir = nullptr;
};


#endif //LIBDNF_ADVISORYTEST_HPP
15 changes: 15 additions & 0 deletions tests/libdnf/sack/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(LIBDNF_TEST_SOURCES
${LIBDNF_TEST_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/AdvisoryTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/QueryTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/DnfPackageTest.cpp
PARENT_SCOPE
)

set(LIBDNF_TEST_HEADERS
${LIBDNF_TEST_HEADERS}
${CMAKE_CURRENT_SOURCE_DIR}/AdvisoryTest.hpp
${CMAKE_CURRENT_SOURCE_DIR}/QueryTest.hpp
${CMAKE_CURRENT_SOURCE_DIR}/DnfPackageTest.hpp
PARENT_SCOPE
)
Loading

0 comments on commit 348b753

Please sign in to comment.