2023-08-04 18:32:09 +02:00
|
|
|
use tracing_test::traced_test;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[traced_test]
|
|
|
|
#[cfg(feature = "json-edit")]
|
|
|
|
pub fn test_can_update_version_in_jq() {
|
|
|
|
use cuddle_please_release_strategy::JsonEditOptions;
|
|
|
|
|
|
|
|
let dir = tempdir::TempDir::new("can_update_version_in_jq").unwrap();
|
|
|
|
let dir_path = dir.path();
|
|
|
|
let json_file = dir_path.join("some-test.json");
|
|
|
|
let initial_content = r#"{
|
|
|
|
"some": {
|
|
|
|
"nested": [
|
|
|
|
{
|
|
|
|
"structure": {
|
|
|
|
"version": "v1.0.1"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#;
|
|
|
|
|
|
|
|
let expected = r#"{
|
|
|
|
"some": {
|
|
|
|
"nested": [
|
|
|
|
{
|
|
|
|
"structure": {
|
|
|
|
"version": "v1.0.2"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#;
|
|
|
|
|
|
|
|
std::fs::write(&json_file, initial_content).unwrap();
|
|
|
|
let actual_file = std::fs::read_to_string(&json_file).unwrap();
|
|
|
|
pretty_assertions::assert_eq!(initial_content, actual_file);
|
|
|
|
|
|
|
|
let edit_options = JsonEditOptions {
|
2023-08-04 18:56:43 +02:00
|
|
|
jq: r#".some.nested[].structure.version=$version"#.into(),
|
2023-08-04 18:32:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
edit_options.execute(&json_file, "v1.0.2").unwrap();
|
|
|
|
|
|
|
|
let actual_file = std::fs::read_to_string(&json_file).unwrap();
|
|
|
|
pretty_assertions::assert_eq!(expected, &actual_file);
|
|
|
|
}
|