This repository was archived by the owner on Dec 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathtest_config.cpp
More file actions
188 lines (185 loc) · 9.17 KB
/
test_config.cpp
File metadata and controls
188 lines (185 loc) · 9.17 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include <catch2/catch_all.hpp>
#include <framework/runtime.hpp>
#include <tests/helpers.hpp>
#include <utils/config.hpp>
namespace fs = std::filesystem;
SCENARIO("Check ManagerSettings Constructor", "[!throws]") {
auto bin_dir = Everest::tests::get_bin_dir().string() + "/";
GIVEN("An invalid prefix, but a valid config file") {
THEN("It should throw BootException") {
CHECK_THROWS_AS(
Everest::ManagerSettings(bin_dir + "non-valid-prefix/", bin_dir + "valid_config/config.yaml"),
Everest::BootException);
}
}
GIVEN("A valid prefix, but a non existing config file") {
THEN("It should throw BootException") {
CHECK_THROWS_AS(Everest::ManagerSettings(bin_dir + "valid_config/", bin_dir + "non-existing-config.yaml"),
Everest::BootException);
}
}
GIVEN("A valid prefix and a valid config file") {
THEN("It should not throw") {
CHECK_NOTHROW(Everest::ManagerSettings(bin_dir + "valid_config/", bin_dir + "valid_config/config.yaml"));
}
}
GIVEN("A broken yaml file") {
// FIXME (aw): this also throws, if the folder doesn't even exists or some other things fail
THEN("It should throw") {
CHECK_THROWS(Everest::ManagerSettings(bin_dir + "broken_yaml/", bin_dir + "broken_yaml/config.yaml"));
}
}
GIVEN("A empty yaml file") {
THEN("It shouldn't throw") {
CHECK_NOTHROW(Everest::ManagerSettings(bin_dir + "empty_yaml/", bin_dir + "empty_yaml/config.yaml"));
}
}
GIVEN("A empty yaml object file") {
THEN("It shouldn't throw") {
CHECK_NOTHROW(
Everest::ManagerSettings(bin_dir + "empty_yaml_object/", bin_dir + "empty_yaml_object/config.yaml"));
}
}
GIVEN("A null yaml file") {
THEN("It shouldn't throw") {
CHECK_NOTHROW(Everest::ManagerSettings(bin_dir + "null_yaml/", bin_dir + "null_yaml/config.yaml"));
}
}
GIVEN("A string yaml file") {
THEN("It should throw Everest::EverestConfigError") {
CHECK_THROWS_AS(Everest::ManagerSettings(bin_dir + "string_yaml/", bin_dir + "string_yaml/config.yaml"),
Everest::BootException);
}
}
}
SCENARIO("Check Config Constructor", "[!throws]") {
auto bin_dir = Everest::tests::get_bin_dir().string() + "/";
GIVEN("A config without modules") {
auto ms = Everest::ManagerSettings(bin_dir + "empty_config/", bin_dir + "empty_config/config.yaml");
auto config = Everest::ManagerConfig(ms);
THEN("It should not contain the module some_module") {
CHECK(!config.contains("some_module"));
}
}
GIVEN("A config file referencing a non existent module") {
auto ms = Everest::ManagerSettings(bin_dir + "missing_module/", bin_dir + "missing_module/config.yaml");
THEN("It should throw Everest::EverestConfigError") {
CHECK_THROWS_AS(Everest::ManagerConfig(ms), Everest::EverestConfigError);
}
}
GIVEN("A config file using a module with broken manifest (missing meta data)") {
auto ms = Everest::ManagerSettings(bin_dir + "broken_manifest_1/", bin_dir + "broken_manifest_1/config.yaml");
THEN("It should throw Everest::EverestConfigError") {
CHECK_THROWS_AS(Everest::ManagerConfig(ms), Everest::EverestConfigError);
}
}
GIVEN("A config file using a module with broken manifest (empty file)") {
auto ms = Everest::ManagerSettings(bin_dir + "broken_manifest_2/", bin_dir + "broken_manifest_2/config.yaml");
THEN("It should throw Everest::EverestConfigError") {
// FIXME: an empty manifest breaks the test?
CHECK_THROWS_AS(Everest::ManagerConfig(ms), Everest::EverestConfigError);
}
}
GIVEN("A config file using a module with broken manifest (broken module config)") {
auto ms = Everest::ManagerSettings(bin_dir + "broken_manifest_3/", bin_dir + "broken_manifest_3/config.yaml");
THEN("It should throw Everest::EverestConfigError") {
CHECK_THROWS_AS(Everest::ManagerConfig(ms), Everest::EverestConfigError);
}
}
GIVEN("A config file using a module with broken manifest (broken implementation config)") {
auto ms = Everest::ManagerSettings(bin_dir + "broken_manifest_4/", bin_dir + "broken_manifest_4/config.yaml");
THEN("It should throw Everest::EverestConfigError") {
CHECK_THROWS_AS(Everest::ManagerConfig(ms), Everest::EverestConfigError);
}
}
GIVEN("A config file with an unknown implementation config") {
auto ms = Everest::ManagerSettings(bin_dir + "unknown_impls/", bin_dir + "unknown_impls/config.yaml");
THEN("It should throw Everest::EverestConfigError") {
CHECK_THROWS_AS(Everest::ManagerConfig(ms), Everest::EverestConfigError);
}
}
GIVEN("A config file with an missing config entry") {
auto ms =
Everest::ManagerSettings(bin_dir + "missing_config_entry/", bin_dir + "missing_config_entry/config.yaml");
THEN("It should throw Everest::EverestConfigError") {
CHECK_THROWS_AS(Everest::ManagerConfig(ms), Everest::EverestConfigError);
}
}
GIVEN("A config file with an missing implementation config entry") {
auto ms = Everest::ManagerSettings(bin_dir + "missing_impl_config_entry/",
bin_dir + "missing_impl_config_entry/config.yaml");
THEN("It should throw Everest::EverestConfigError") {
CHECK_THROWS_AS(Everest::ManagerConfig(ms), Everest::EverestConfigError);
}
}
GIVEN("A config file with an invalid type of an implementation config entry") {
auto ms = Everest::ManagerSettings(bin_dir + "invalid_config_entry_type/",
bin_dir + "invalid_config_entry_type/config.yaml");
THEN("It should throw Everest::EverestConfigError") {
CHECK_THROWS_AS(Everest::ManagerConfig(ms), Everest::EverestConfigError);
}
}
GIVEN("A config file using a module with an invalid interface (missing "
"interface)") {
auto ms = Everest::ManagerSettings(bin_dir + "missing_interface/", bin_dir + "missing_interface/config.yaml");
THEN("It should throw Everest::EverestConfigError") {
CHECK_THROWS_AS(Everest::ManagerConfig(ms), Everest::EverestConfigError);
}
}
GIVEN("A valid config") {
auto ms = Everest::ManagerSettings(bin_dir + "valid_config/", bin_dir + "valid_config/config.yaml");
THEN("It should not throw at all") {
CHECK_NOTHROW(Everest::ManagerConfig(ms));
}
}
GIVEN("A valid config with a valid module") {
auto ms =
Everest::ManagerSettings(bin_dir + "valid_module_config/", bin_dir + "valid_module_config/config.yaml");
THEN("It should not throw at all") {
CHECK_NOTHROW(Everest::ManagerConfig(ms));
}
}
GIVEN("A valid config with a valid module and a user-config applied") {
auto ms = Everest::ManagerSettings(bin_dir + "valid_module_config_userconfig/",
bin_dir + "valid_module_config_userconfig/config.yaml");
THEN("It should not throw at all") {
CHECK_NOTHROW([&]() {
auto mc = Everest::ManagerConfig(ms);
auto main = mc.get_main_config();
CHECK(main.at("valid_module").at("config_module").at("valid_config_entry") == "hi");
}());
}
}
GIVEN("A valid config with a valid module and enabled schema validation") {
auto ms = Everest::ManagerSettings(bin_dir + "valid_module_config_validate/",
bin_dir + "valid_module_config_validate/config.yaml");
THEN("It should not throw at all") {
CHECK_NOTHROW([&]() {
auto mc = Everest::ManagerConfig(ms);
auto interfaces = mc.get_interfaces();
CHECK(interfaces.size() == 1);
CHECK(interfaces.contains("TESTValidManifestCmdVar"));
CHECK(interfaces.at("TESTValidManifestCmdVar").at("main") == "test_interface_cmd_var");
auto types = mc.get_types();
CHECK(types.size() == 1);
CHECK(types.contains("/test_type"));
}());
}
}
GIVEN("A valid config in legacy json format with a valid module") {
auto ms = Everest::ManagerSettings(bin_dir + "valid_module_config_json/",
bin_dir + "valid_module_config_json/config.json");
THEN("It should not throw at all") {
CHECK_NOTHROW(Everest::ManagerConfig(ms));
}
}
GIVEN("A config file that does not exist") {
THEN("It should throw Everest::BootException") {
CHECK_THROWS_AS(Everest::ManagerSettings(bin_dir + "valid_module_config_json/",
bin_dir + "valid_module_config_json/config.yaml"),
Everest::BootException);
}
}
}