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 <[email protected]>
  • Loading branch information
felixfontein committed Feb 9, 2024
1 parent 38ef8a8 commit bd7ca0f
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions functional-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,4 +840,113 @@ 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("encrypt")
.arg("-i")
.arg(file_path.clone())
.output()
.expect("Error running sops")
.status
.success(),
"sops didn't exit successfully"
);
let print_foo = prepare_temp_file(
"print_foo.sh",
r#"#!/bin/bash
echo -E "${foo}"
"#
.as_bytes(),
);
let output = Command::new(SOPS_BINARY_PATH)
.arg("exec-env")
.arg(file_path.clone())
.arg(format!("/bin/bash {}", print_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 print_bar = prepare_temp_file(
"print_bar.sh",
r#"#!/bin/bash
echo -E "${bar}"
"#
.as_bytes(),
);
let output = Command::new(SOPS_BINARY_PATH)
.arg("exec-env")
.arg(file_path.clone())
.arg(format!("/bin/bash {}", print_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 bd7ca0f

Please sign in to comment.