object-introspection/test/integration/runner_common.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

84 lines
1.9 KiB
C
Raw Permalink Normal View History

2022-12-19 14:37:51 +00:00
#pragma once
#include <gtest/gtest.h>
#include <boost/asio.hpp>
#include <boost/process.hpp>
#include <boost/property_tree/ptree.hpp>
#include <filesystem>
#include <future>
#include <iostream>
#include <string>
#include <string_view>
2022-12-19 14:37:51 +00:00
struct OidOpts {
boost::asio::io_context& ctx;
2022-12-19 14:37:51 +00:00
std::string targetArgs;
std::string scriptSource;
};
2023-05-19 16:02:24 +01:00
struct OilOpts {
boost::asio::io_context& ctx;
std::string targetArgs;
};
2022-12-19 14:37:51 +00:00
struct Proc {
boost::asio::io_context& ctx;
2022-12-19 14:37:51 +00:00
boost::process::child proc;
boost::process::child tee_stdout;
boost::process::child tee_stderr;
};
struct OidProc {
Proc target;
Proc oid;
};
class IntegrationBase : public ::testing::Test {
protected:
virtual ~IntegrationBase() = default;
virtual std::string TmpDirStr() = 0;
void TearDown() override;
void SetUp() override;
int exit_code(Proc& proc);
std::optional<std::filesystem::path> writeCustomConfig(
std::string_view filePrefix, std::string_view content);
2022-12-19 14:37:51 +00:00
std::filesystem::path workingDir;
std::string stdout_;
std::string stderr_;
/*
* compare_json
*
* Compares two JSON objects for equality if "expect_eq" is true, or for
* inequality if "expect_eq" is false.
*/
void compare_json(const boost::property_tree::ptree& expected_json,
const boost::property_tree::ptree& actual_json,
const std::string& full_key = "root",
2022-12-19 14:37:51 +00:00
bool expect_eq = true);
};
2023-08-16 20:40:36 +01:00
class OidIntegration : public IntegrationBase {
protected:
std::string TmpDirStr() override;
OidProc runOidOnProcess(OidOpts opts,
std::vector<std::string> extra_args,
std::string configPrefix,
std::string configSuffix);
};
2022-12-19 14:37:51 +00:00
class OilIntegration : public IntegrationBase {
protected:
std::string TmpDirStr() override;
2023-05-19 16:02:24 +01:00
Proc runOilTarget(OilOpts opts,
std::string configPrefix,
std::string configSuffix);
2022-12-19 14:37:51 +00:00
};