Skip to content

Commit

Permalink
test: For filter_nevra(PackageSet) with comparator
Browse files Browse the repository at this point in the history
  • Loading branch information
m-blaha committed Feb 10, 2023
1 parent 71e1171 commit d95e627
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
59 changes: 59 additions & 0 deletions test/libdnf/rpm/test_package_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,65 @@ void RpmPackageQueryTest::test_filter_nevra_packgset() {
CPPUNIT_ASSERT_EQUAL(expected1, to_vector(query2));
}

void RpmPackageQueryTest::test_filter_nevra_packgset_cmp() {
add_repo_solv("solv-repo1");

// prepare query to compare packages with
PackageQuery patterns(base);
patterns.filter_nevra({"pkg-libs-1:1.2-4.x86_64"});
std::vector<Package> expected = {get_pkg("pkg-libs-1:1.2-4.x86_64")};
CPPUNIT_ASSERT_EQUAL_MESSAGE("Pattern preparation failed", expected, to_vector(patterns));

{
// comparator EQ
PackageQuery query(base);
query.filter_nevra(patterns, libdnf::sack::QueryCmp::EQ);
std::vector<Package> expected = {get_pkg("pkg-libs-1:1.2-4.x86_64")};
CPPUNIT_ASSERT_EQUAL_MESSAGE("EQ comparator failed", expected, to_vector(query));
}

{
// comparator NEQ
PackageQuery query(base);
query.filter_name({"pkg-libs"});
query.filter_nevra(patterns, libdnf::sack::QueryCmp::NEQ);
std::vector<Package> expected = {get_pkg("pkg-libs-0:1.2-3.x86_64"), get_pkg("pkg-libs-1:1.3-4.x86_64")};
CPPUNIT_ASSERT_EQUAL_MESSAGE("NEQ comparator failed", expected, to_vector(query));
}

{
// comparator LT
PackageQuery query(base);
query.filter_nevra(patterns, libdnf::sack::QueryCmp::LT);
std::vector<Package> expected = {get_pkg("pkg-libs-0:1.2-3.x86_64")};
CPPUNIT_ASSERT_EQUAL_MESSAGE("LT comparator failed", expected, to_vector(query));
}

{
// comparator LTE
PackageQuery query(base);
query.filter_nevra(patterns, libdnf::sack::QueryCmp::LTE);
std::vector<Package> expected = {get_pkg("pkg-libs-0:1.2-3.x86_64"), get_pkg("pkg-libs-1:1.2-4.x86_64")};
CPPUNIT_ASSERT_EQUAL_MESSAGE("LTE comparator failed", expected, to_vector(query));
}

{
// comparator GT
PackageQuery query(base);
query.filter_nevra(patterns, libdnf::sack::QueryCmp::GT);
std::vector<Package> expected = {get_pkg("pkg-libs-1:1.3-4.x86_64")};
CPPUNIT_ASSERT_EQUAL_MESSAGE("GT comparator failed", expected, to_vector(query));
}

{
// comparator GTE
PackageQuery query(base);
query.filter_nevra(patterns, libdnf::sack::QueryCmp::GTE);
std::vector<Package> expected = {get_pkg("pkg-libs-1:1.2-4.x86_64"), get_pkg("pkg-libs-1:1.3-4.x86_64")};
CPPUNIT_ASSERT_EQUAL_MESSAGE("GTE comparator failed", expected, to_vector(query));
}
}

void RpmPackageQueryTest::test_filter_name_arch() {
add_repo_solv("solv-repo1");

Expand Down
2 changes: 2 additions & 0 deletions test/libdnf/rpm/test_package_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class RpmPackageQueryTest : public BaseTestCase {
CPPUNIT_TEST(test_filter_name);
CPPUNIT_TEST(test_filter_name_packgset);
CPPUNIT_TEST(test_filter_nevra_packgset);
CPPUNIT_TEST(test_filter_nevra_packgset_cmp);
CPPUNIT_TEST(test_filter_name_arch);
CPPUNIT_TEST(test_filter_name_arch2);
CPPUNIT_TEST(test_filter_nevra);
Expand Down Expand Up @@ -69,6 +70,7 @@ class RpmPackageQueryTest : public BaseTestCase {
void test_filter_name();
void test_filter_name_packgset();
void test_filter_nevra_packgset();
void test_filter_nevra_packgset_cmp();
void test_filter_name_arch();
void test_filter_name_arch2();
void test_filter_nevra();
Expand Down

0 comments on commit d95e627

Please sign in to comment.