Skip to content

Commit da6ee99

Browse files
committed
feat: move new to from infra-config to the test block
1 parent 34aa76f commit da6ee99

File tree

1 file changed

+62
-57
lines changed

1 file changed

+62
-57
lines changed

agent-control/src/cli/on_host/host_monitoring_gen/infra_config.rs

Lines changed: 62 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ impl Default for InfraConfig {
4646
}
4747

4848
impl InfraConfig {
49-
#[allow(dead_code)]
50-
fn new(
51-
values: HashMap<String, serde_yaml::Value>,
52-
deletions: Vec<serde_yaml::Value>,
53-
) -> InfraConfig {
54-
InfraConfig { values, deletions }
55-
}
5649

5750
pub fn with_custom_attributes(mut self, custom_attributes: &str) -> Result<Self, CliError> {
5851
if !custom_attributes.trim().is_empty() {
@@ -94,6 +87,11 @@ impl InfraConfig {
9487
&self.values
9588
}
9689

90+
/// generate_agent_type_config_mapping is creating the config_mapping required to properly
91+
/// migrate the infra config file.
92+
/// It defines the agent_type_fqn to look for in the agents config and the paths where the configs and folders are placed.
93+
/// A file path contains also the option to add overwrites and deletions, overwrites allow
94+
/// adding or replacing attributes and deletions defines keys to be removed from the config.
9795
pub fn generate_agent_type_config_mapping(
9896
self,
9997
config_mapping: &str,
@@ -184,6 +182,15 @@ mod tests {
184182
- yaml
185183
"#;
186184

185+
impl InfraConfig {
186+
fn new(
187+
values: HashMap<String, serde_yaml::Value>,
188+
deletions: Vec<serde_yaml::Value>,
189+
) -> InfraConfig {
190+
InfraConfig { values, deletions }
191+
}
192+
}
193+
187194
#[test]
188195
fn test_generate_agent_type_config_mapping() {
189196
let mut values = HashMap::new();
@@ -231,56 +238,54 @@ mod tests {
231238
// Parse the YAML content
232239
let parsed_values: serde_yaml::Value = serde_yaml::from_str(&result).unwrap();
233240

234-
if let serde_yaml::Value::Mapping(map) = parsed_values {
235-
if let Some(serde_yaml::Value::Mapping(config_agent_map)) =
236-
map.get(serde_yaml::Value::String("config_agent".to_string()))
237-
{
238-
assert_eq!(
239-
config_agent_map.get(serde_yaml::Value::String(
240-
"status_server_enabled".to_string()
241-
)),
242-
Some(&serde_yaml::Value::Bool(true))
243-
);
244-
assert_eq!(
245-
config_agent_map.get(serde_yaml::Value::String(
246-
"enable_process_metrics".to_string()
247-
)),
248-
Some(&serde_yaml::Value::Bool(true))
249-
);
250-
assert_eq!(
251-
config_agent_map.get(serde_yaml::Value::String("license_key".to_string())),
252-
Some(&serde_yaml::Value::String(
253-
"{{NEW_RELIC_LICENSE_KEY}}".to_string()
254-
))
255-
);
256-
assert_eq!(
257-
config_agent_map
258-
.get(serde_yaml::Value::String("status_server_port".to_string())),
259-
Some(&serde_yaml::Value::Number(serde_yaml::Number::from(18003)))
260-
);
261-
assert_eq!(
262-
config_agent_map.get(serde_yaml::Value::String("staging".to_string())),
263-
Some(&serde_yaml::Value::Bool(true))
264-
);
265-
assert_eq!(
266-
config_agent_map.get(serde_yaml::Value::String("proxy".to_string())),
267-
Some(&serde_yaml::Value::String(
268-
"http://proxy.example.com".to_string()
269-
))
270-
);
271-
let mut custom_attributes = serde_yaml::Mapping::new();
272-
custom_attributes.insert(
273-
serde_yaml::Value::String("custom_key".to_string()),
274-
serde_yaml::Value::String("custom_value".to_string()),
275-
);
276-
assert_eq!(
277-
config_agent_map
278-
.get(serde_yaml::Value::String("custom_attributes".to_string())),
279-
Some(&serde_yaml::Value::Mapping(custom_attributes))
280-
);
281-
}
282-
} else {
283-
panic!("Expected a YAML mapping");
241+
let serde_yaml::Value::Mapping(map) = parsed_values else { panic!("Expected a YAML mapping") };
242+
if let Some(serde_yaml::Value::Mapping(config_agent_map)) =
243+
map.get(serde_yaml::Value::String("config_agent".to_string()))
244+
{
245+
assert_eq!(
246+
config_agent_map.get(serde_yaml::Value::String(
247+
"status_server_enabled".to_string()
248+
)),
249+
Some(&serde_yaml::Value::Bool(true))
250+
);
251+
assert_eq!(
252+
config_agent_map.get(serde_yaml::Value::String(
253+
"enable_process_metrics".to_string()
254+
)),
255+
Some(&serde_yaml::Value::Bool(true))
256+
);
257+
assert_eq!(
258+
config_agent_map.get(serde_yaml::Value::String("license_key".to_string())),
259+
Some(&serde_yaml::Value::String(
260+
"{{NEW_RELIC_LICENSE_KEY}}".to_string()
261+
))
262+
);
263+
assert_eq!(
264+
config_agent_map
265+
.get(serde_yaml::Value::String("status_server_port".to_string())),
266+
Some(&serde_yaml::Value::Number(serde_yaml::Number::from(18003)))
267+
);
268+
assert_eq!(
269+
config_agent_map.get(serde_yaml::Value::String("staging".to_string())),
270+
Some(&serde_yaml::Value::Bool(true))
271+
);
272+
assert_eq!(
273+
config_agent_map.get(serde_yaml::Value::String("proxy".to_string())),
274+
Some(&serde_yaml::Value::String(
275+
"http://proxy.example.com".to_string()
276+
))
277+
);
278+
let mut custom_attributes = serde_yaml::Mapping::new();
279+
custom_attributes.insert(
280+
serde_yaml::Value::String("custom_key".to_string()),
281+
serde_yaml::Value::String("custom_value".to_string()),
282+
);
283+
assert_eq!(
284+
config_agent_map
285+
.get(serde_yaml::Value::String("custom_attributes".to_string())),
286+
Some(&serde_yaml::Value::Mapping(custom_attributes))
287+
);
284288
}
289+
285290
}
286291
}

0 commit comments

Comments
 (0)