-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46c2ffb
commit 8e5210b
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::error::Error; | ||
|
||
use hq_rs::{parser::Field, write}; | ||
|
||
#[test] | ||
fn attr() -> Result<(), Box<dyn Error>> { | ||
// filter '.version' | ||
let fields = vec![Field::new("version")]; | ||
// hcl: | ||
// version = "test" | ||
let mut body = utilities::edit_hcl("version = \"test\"")?; | ||
|
||
let value: hcl_edit::expr::Expression = "\"new_value\"".parse()?; | ||
|
||
write(fields, &mut body, &value)?; | ||
|
||
assert_eq!("version = \"new_value\"", body.to_string()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn block_attr() -> Result<(), Box<dyn Error>> { | ||
// filter '.options.enabled' | ||
let fields = vec![Field::new("options"), Field::new("enabled")]; | ||
// hcl: | ||
// options { enabled = false } | ||
let mut body = utilities::edit_hcl("options { enabled = false }")?; | ||
|
||
let value: hcl_edit::expr::Expression = "true".parse()?; | ||
|
||
write(fields, &mut body, &value)?; | ||
|
||
assert_eq!("options { enabled = true }", body.to_string()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn labeled_block_attr() -> Result<(), Box<dyn Error>> { | ||
// filter '.module[label="cool-module"].version' | ||
let fields = vec![ | ||
Field::labeled("module", &["cool-module"]), | ||
Field::new("version"), | ||
]; | ||
// hcl: | ||
// module "cool-module" { version = "1.0" } | ||
let mut body = utilities::edit_hcl("module \"cool-module\" { version = \"1.0\" }")?; | ||
|
||
let value: hcl_edit::expr::Expression = "\"2.0\"".parse()?; | ||
|
||
write(fields, &mut body, &value)?; | ||
|
||
assert_eq!( | ||
"module \"cool-module\" { version = \"2.0\" }", | ||
body.to_string() | ||
); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ pulish = false | |
|
||
[dependencies] | ||
hcl-rs = "0.17" | ||
hcl-edit = "0.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters