From 34d6892b54614d77bf55b507981f2d0ce29a8066 Mon Sep 17 00:00:00 2001 From: Stefano Bonicatti Date: Fri, 5 Jun 2020 20:22:52 +0200 Subject: [PATCH] Add validate_container_rows helper for integration tests This simple helper takes a table name and an already prepared rows map to add the container columns, which are normally hidden, and call validate_rows on it. We use this function in deb_packages, rpm_packages, npm_packages, os_version integration tests. --- tests/integration/tables/deb_packages.cpp | 6 +----- tests/integration/tables/helper.cpp | 9 +++++++++ tests/integration/tables/helper.h | 2 ++ tests/integration/tables/npm_packages.cpp | 6 +----- tests/integration/tables/os_version.cpp | 8 +------- tests/integration/tables/rpm_packages.cpp | 6 +----- 6 files changed, 15 insertions(+), 22 deletions(-) diff --git a/tests/integration/tables/deb_packages.cpp b/tests/integration/tables/deb_packages.cpp index 74c8aa45d38..92fa47d6988 100644 --- a/tests/integration/tables/deb_packages.cpp +++ b/tests/integration/tables/deb_packages.cpp @@ -51,11 +51,7 @@ TEST_F(DebPackages, test_sanity) { ASSERT_EQ(all_packages.count("dpkg"), 1u); if (isPlatform(PlatformType::TYPE_LINUX)) { - rows = execute_query( - "select *, pid_with_namespace, mount_namespace_id from deb_packages"); - row_map["pid_with_namespace"] = IntType; - row_map["mount_namespace_id"] = NormalType; - validate_rows(rows, row_map); + validate_container_rows("deb_packages", row_map); } } else { diff --git a/tests/integration/tables/helper.cpp b/tests/integration/tables/helper.cpp index 6d017467512..80d5c4f3487 100644 --- a/tests/integration/tables/helper.cpp +++ b/tests/integration/tables/helper.cpp @@ -304,6 +304,15 @@ bool validate_value_using_flags(const std::string& value, int flags) { return true; } +void validate_container_rows(const std::string& table_name, + ValidationMap& validation_map) { + auto rows = execute_query( + "select *, pid_with_namespace, mount_namespace_id from " + table_name); + validation_map["pid_with_namespace"] = IntType; + validation_map["mount_namespace_id"] = NormalType; + validate_rows(rows, validation_map); +} + void setUpEnvironment() { Initializer::platformSetup(); registryAndPluginInit(); diff --git a/tests/integration/tables/helper.h b/tests/integration/tables/helper.h index 1270d1f5acd..15636e041a2 100644 --- a/tests/integration/tables/helper.h +++ b/tests/integration/tables/helper.h @@ -89,6 +89,8 @@ void validate_row(const Row& row, const ValidationMap& validation_map); void validate_rows(const std::vector& rows, const ValidationMap& validation_map); bool validate_value_using_flags(const std::string& value, int flags); +void validate_container_rows(const std::string& table_name, + ValidationMap& validation_map); bool is_valid_hex(const std::string& value); void setUpEnvironment(); diff --git a/tests/integration/tables/npm_packages.cpp b/tests/integration/tables/npm_packages.cpp index 02ff3e392b2..9058606c529 100644 --- a/tests/integration/tables/npm_packages.cpp +++ b/tests/integration/tables/npm_packages.cpp @@ -38,11 +38,7 @@ TEST_F(NpmPackagesTest, test_sanity) { validate_rows(data, row_map); if (isPlatform(PlatformType::TYPE_LINUX)) { - data = execute_query( - "select *, pid_with_namespace, mount_namespace_id from npm_packages"); - row_map["pid_with_namespace"] = IntType; - row_map["mount_namespace_id"] = NormalType; - validate_rows(data, row_map); + validate_container_rows("npm_packages", row_map); } } diff --git a/tests/integration/tables/os_version.cpp b/tests/integration/tables/os_version.cpp index a5616db77d1..e36645f2a03 100644 --- a/tests/integration/tables/os_version.cpp +++ b/tests/integration/tables/os_version.cpp @@ -47,13 +47,7 @@ TEST_F(OsVersion, test_sanity) { // Query again with hidden columns too if (isPlatform(PlatformType::TYPE_LINUX)) { - data = execute_query( - "select *, pid_with_namespace, mount_namespace_id from os_version"); - - row_map["pid_with_namespace"] = IntType; - row_map["mount_namespace_id"] = NormalType; - - validate_rows(data, row_map); + validate_container_rows("os_version", row_map); } } diff --git a/tests/integration/tables/rpm_packages.cpp b/tests/integration/tables/rpm_packages.cpp index 10cfd409933..9e20317c510 100644 --- a/tests/integration/tables/rpm_packages.cpp +++ b/tests/integration/tables/rpm_packages.cpp @@ -43,11 +43,7 @@ TEST_F(rpmPackages, test_sanity) { validate_rows(rows, row_map); if (isPlatform(PlatformType::TYPE_LINUX)) { - rows = execute_query( - "select *, pid_with_namespace, mount_namespace_id from rpm_packages"); - row_map["pid_with_namespace"] = IntType; - row_map["mount_namespace_id"] = NormalType; - validate_rows(rows, row_map); + validate_container_rows("rpm_packages", row_map); } } else { LOG(WARNING) << "Empty results of query from 'rpm_packages', assume there "