Skip to content

Commit

Permalink
Add basic functional tests for exec-file and exec-env.
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Fontein <felix@fontein.de>
  • Loading branch information
felixfontein committed Dec 29, 2023
1 parent 1a7ed1d commit 0189541
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions functional-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,4 +790,99 @@ b: ba"#
.expect("couldn't read output file contents");
assert_ne!(contents, "", "Output file is empty");
}

#[test]
fn exec_env() {
let file_path = prepare_temp_file(
"test_exec_env.yaml",
r#"foo: bar
bar: |-
baz
bam
"#
.as_bytes(),
);
assert!(
Command::new(SOPS_BINARY_PATH)
.arg("-e")
.arg("-i")
.arg(file_path.clone())
.output()
.expect("Error running sops")
.status
.success(),
"sops didn't exit successfully"
);
let output = Command::new(SOPS_BINARY_PATH)
.arg("exec-env")
.arg(file_path.clone())
.arg("echo \"$foo\"")
.output()
.expect("Error running sops");
assert!(output.status.success(), "sops didn't exit successfully");
println!(
"stdout: {}, stderr: {}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
assert_eq!(String::from_utf8_lossy(&output.stdout), "bar\n");
let output = Command::new(SOPS_BINARY_PATH)
.arg("exec-env")
.arg(file_path.clone())
.arg("echo \"$bar\"")
.output()
.expect("Error running sops");
assert!(output.status.success(), "sops didn't exit successfully");
println!(
"stdout: {}, stderr: {}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
assert_eq!(String::from_utf8_lossy(&output.stdout), "baz\\nbam\n");
}

#[test]
fn exec_file() {
let file_path = prepare_temp_file(
"test_exec_file.yaml",
r#"foo: bar
bar: |-
baz
bam
"#
.as_bytes(),
);
assert!(
Command::new(SOPS_BINARY_PATH)
.arg("-e")
.arg("-i")
.arg(file_path.clone())
.output()
.expect("Error running sops")
.status
.success(),
"sops didn't exit successfully"
);
let output = Command::new(SOPS_BINARY_PATH)
.arg("exec-file")
.arg("--output-type")
.arg("json")
.arg(file_path.clone())
.arg("cat {}")
.output()
.expect("Error running sops");
assert!(output.status.success(), "sops didn't exit successfully");
println!(
"stdout: {}, stderr: {}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
assert_eq!(
String::from_utf8_lossy(&output.stdout),
r#"{
"foo": "bar",
"bar": "baz\nbam"
}"#
);
}
}

0 comments on commit 0189541

Please sign in to comment.