Skip to content

Commit

Permalink
Merge pull request #62 from instaclustr/integration_tests
Browse files Browse the repository at this point in the history
Add basic integration tests
  • Loading branch information
cjrolo authored Oct 27, 2023
2 parents c057e22 + 822afa2 commit 09f5182
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/target
*.wav
*.flac
.vscode/settings.json
1 change: 1 addition & 0 deletions brro-compressor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,6 @@ fn main() {

if let Err(e) = process_args(&arguments) {
error!("{}", e);
std::process::exit(1);
}
}
64 changes: 64 additions & 0 deletions brro-compressor/tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use tempfile::tempdir;

#[test]
fn test_noop() {
test_suite("noop");
}

#[test]
fn test_constant() {
test_suite("constant");
}

#[test]
fn test_fft() {
test_suite("fft");
}

fn test_suite(compressor: &str) {
compress_dir(compressor);
compress_file(compressor);
}

fn compress_dir(compressor: &str) {
let tmp_dir = tempdir().unwrap();
let input = tmp_dir.path().join("input");
let output = tmp_dir.path().join("input-compressed");
std::fs::create_dir(&input).unwrap();
std::fs::copy("tests/wavs/memory_used.wav", input.join("1.wav")).unwrap();
std::fs::copy("tests/wavs/uptime.wav", input.join("2.wav")).unwrap();

run_compressor(&[input.to_str().unwrap(), "--compressor", compressor]);
assert!(output.join("1.bro").is_file());
assert!(output.join("2.bro").is_file());
}

fn compress_file(compressor: &str) {
let tmp_dir = tempdir().unwrap();
let path = tmp_dir.path();
std::fs::copy("tests/wavs/memory_used.wav", path.join("1.wav")).unwrap();

run_compressor(&[
path.join("1.wav").to_str().unwrap(),
"--compressor",
compressor,
]);
assert!(path.join("1.bro").is_file());
}

fn run_compressor(args: &[&str]) {
// path to binary set by cargo: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates
let command = std::env!("CARGO_BIN_EXE_brro-compressor");

let status = std::process::Command::new(command)
.args(args)
.status()
.unwrap();

if !status.success() {
panic!(
"Failed to run command {} {:?}, exited with {:?}",
command, args, status
);
}
}
Binary file added brro-compressor/tests/wavs/memory_used.wav
Binary file not shown.
Binary file added brro-compressor/tests/wavs/uptime.wav
Binary file not shown.

0 comments on commit 09f5182

Please sign in to comment.