implemented adding new vars
All checks were successful
Version Check / check-version (pull_request) Successful in 3s
All checks were successful
Version Check / check-version (pull_request) Successful in 3s
This commit is contained in:
@@ -89,14 +89,45 @@ mod tests {
|
||||
use std::io::Write;
|
||||
|
||||
#[test]
|
||||
fn test_parse_properties() {
|
||||
let mut file = NamedTempFile::new().unwrap();
|
||||
writeln!(file, "server.port=8080\ndatabase.host=localhost").unwrap();
|
||||
|
||||
fn test_group_rename_write() {
|
||||
let handler = PropertiesHandler;
|
||||
let vars = handler.parse(file.path()).unwrap();
|
||||
let mut vars = vec![
|
||||
ConfigItem {
|
||||
key: "server".to_string(),
|
||||
path: vec![PathSegment::Key("server".to_string())],
|
||||
value: None,
|
||||
template_value: None,
|
||||
default_value: None,
|
||||
depth: 0,
|
||||
is_group: true,
|
||||
status: ItemStatus::Present,
|
||||
value_type: ValueType::Null,
|
||||
},
|
||||
ConfigItem {
|
||||
key: "port".to_string(),
|
||||
path: vec![PathSegment::Key("server".to_string()), PathSegment::Key("port".to_string())],
|
||||
value: Some("8080".to_string()),
|
||||
template_value: Some("8080".to_string()),
|
||||
default_value: Some("8080".to_string()),
|
||||
depth: 1,
|
||||
is_group: false,
|
||||
status: ItemStatus::Present,
|
||||
value_type: ValueType::String,
|
||||
}
|
||||
];
|
||||
|
||||
// Rename "server" to "srv"
|
||||
vars[0].key = "srv".to_string();
|
||||
vars[0].path = vec![PathSegment::Key("srv".to_string())];
|
||||
|
||||
assert!(vars.iter().any(|v| v.path_string() == "server" && v.is_group));
|
||||
assert!(vars.iter().any(|v| v.path_string() == "server.port" && v.value.as_deref() == Some("8080")));
|
||||
// Update child path
|
||||
vars[1].path = vec![PathSegment::Key("srv".to_string()), PathSegment::Key("port".to_string())];
|
||||
|
||||
let file = NamedTempFile::new().unwrap();
|
||||
handler.write(file.path(), &vars).unwrap();
|
||||
|
||||
let content = std::fs::read_to_string(file.path()).unwrap();
|
||||
assert!(content.contains("srv.port=8080"));
|
||||
assert!(!content.contains("server.port=8080"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user