cuddle-please/crates/cuddle-please-release-strategy/tests/json_edit.rs
kjuulh 56b44cf2e2
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
fix(json-edit): with actual arg instead of stupid str replace
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-04 18:56:43 +02:00

51 lines
1.1 KiB
Rust

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 {
jq: r#".some.nested[].structure.version=$version"#.into(),
};
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);
}