5#include <gtest/gtest.h>
13class VMCollectorTest :
public ::testing::Test {
15 void SetUp()
override {
17 std::unordered_map<std::string, std::string> config;
25TEST_F(VMCollectorTest, InitializesSuccessfully) {
31TEST_F(VMCollectorTest, ReturnsCorrectMetricTypes) {
33 EXPECT_FALSE(types.empty());
36 std::vector<std::string> expected_types = {
37 "system.vm.is_virtualized",
38 "system.vm.steal_time"
41 for (
const auto& expected : expected_types) {
42 bool found = std::find(types.begin(), types.end(), expected) != types.end();
43 EXPECT_TRUE(found) <<
"Expected metric type not found: " << expected;
48TEST_F(VMCollectorTest, ConfigurationOptions) {
49 auto collector = std::make_unique<vm_collector>();
51 std::unordered_map<std::string, std::string> config = {
55 EXPECT_TRUE(collector->initialize(config));
59TEST_F(VMCollectorTest, CanBeDisabled) {
60 auto collector = std::make_unique<vm_collector>();
62 std::unordered_map<std::string, std::string> config = {
66 collector->initialize(config);
68 auto metrics = collector->collect();
70 EXPECT_TRUE(metrics.empty());
74TEST_F(VMCollectorTest, TracksStatistics) {
76 EXPECT_TRUE(stats.find(
"collection_count") != stats.end());
77 EXPECT_TRUE(stats.find(
"collection_errors") != stats.end());
81TEST_F(VMCollectorTest, CollectReturnsMetrics) {
84 EXPECT_FALSE(metrics.empty());
86 bool found_is_virt =
false;
87 for (
const auto& m : metrics) {
88 if (m.name ==
"system.vm.is_virtualized") found_is_virt =
true;
90 EXPECT_TRUE(found_is_virt);
94TEST(VMTypeTest, ToStringWorks) {
@ none
Bare metal (or undetected)
std::string vm_type_to_string(vm_type type)
Convert vm_type to string representation.
TEST(AdapterFunctionalityTest, WorksWithoutLogger)
Test Scenario 1: Adapter with NULL logger.
TEST_F(AdaptiveMonitoringTest, AdaptiveConfigDefaults)
std::unique_ptr< battery_collector > collector_
Virtualization metrics collector.