osquery-1/osquery/config/config_tests.cpp

59 lines
1.3 KiB
C++
Raw Normal View History

2014-07-31 00:35:19 +00:00
// Copyright 2004-present Facebook. All Rights Reserved.
#include "osquery/config.h"
#include "osquery/config/plugin.h"
#include <gtest/gtest.h>
#include "osquery/core.h"
#include "osquery/status.h"
2014-07-31 00:35:19 +00:00
#include "osquery/registry.h"
namespace core = osquery::core;
using osquery::Status;
2014-07-31 00:35:19 +00:00
2014-08-15 07:25:30 +00:00
namespace osquery {
namespace config {
2014-07-31 00:35:19 +00:00
class ConfigTests : public testing::Test {
2014-08-15 07:25:30 +00:00
public:
ConfigTests() { osquery::InitRegistry::get().run(); }
2014-07-31 00:35:19 +00:00
};
TEST_F(ConfigTests, test_queries_execute) {
auto c = Config::getInstance();
for (const auto& i : c->getScheduledQueries()) {
int err;
auto r = core::aggregateQuery(i.query, err);
EXPECT_EQ(err, 0);
}
}
class TestConfigPlugin : public ConfigPlugin {
2014-08-15 07:25:30 +00:00
public:
2014-07-31 00:35:19 +00:00
TestConfigPlugin() {}
std::pair<Status, std::string> genConfig() {
return std::make_pair(Status(0, "OK"), "foobar");
}
virtual ~TestConfigPlugin() {}
};
2014-08-15 07:25:30 +00:00
REGISTER_CONFIG_PLUGIN("test",
std::make_shared<osquery::config::TestConfigPlugin>());
2014-07-31 00:35:19 +00:00
TEST_F(ConfigTests, test_plugin) {
auto p = REGISTERED_CONFIG_PLUGINS.at("test")->genConfig();
EXPECT_EQ(p.first.ok(), true);
EXPECT_EQ(p.first.toString(), "OK");
EXPECT_EQ(p.second, "foobar");
}
2014-08-15 07:25:30 +00:00
}
}
2014-07-31 00:35:19 +00:00
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}