-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprobe_config_test.cc
65 lines (49 loc) · 1.85 KB
/
probe_config_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <utility>
#include <base/json/json_reader.h>
#include <base/values.h>
#include <brillo/map_utils.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "runtime_probe/functions/sysfs.h"
#include "runtime_probe/probe_config.h"
namespace runtime_probe {
TEST(ProbeConfigTest, LoadConfig) {
const char* config_content = R"({
"sysfs_battery": {
"generic": {
"eval": {
"sysfs": {
"dir_path": "/sys/class/power_supply/BAT0",
"keys": ["model_name", "charge_full_design", "cycle_count"]
}
},
"keys": [],
"expect": {},
"information": {}
}
}
})";
auto dict_value = base::JSONReader::Read(config_content);
EXPECT_TRUE(dict_value.has_value());
auto probe_config = ProbeConfig::FromValue(*dict_value);
EXPECT_NE(probe_config, nullptr);
EXPECT_THAT(brillo::GetMapKeys(probe_config->category_),
::testing::UnorderedElementsAre("sysfs_battery"));
const auto& category = probe_config->category_["sysfs_battery"];
EXPECT_EQ(category->category_name_, "sysfs_battery");
EXPECT_THAT(brillo::GetMapKeys(category->component_),
::testing::UnorderedElementsAre("generic"));
const auto& probe_statement = category->component_["generic"];
EXPECT_EQ(probe_statement->component_name_, "generic");
EXPECT_EQ(probe_statement->key_.size(), 0);
EXPECT_NE(probe_statement->expect_, nullptr);
EXPECT_EQ(probe_statement->information_->DictSize(), 0);
EXPECT_NE(probe_statement->eval_, nullptr);
const SysfsFunction* probe_function =
dynamic_cast<SysfsFunction*>(probe_statement->eval_.get());
EXPECT_NE(probe_function, nullptr);
}
} // namespace runtime_probe