Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update testing suite to write to a more visible path #21

Merged
merged 2 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/target

.idea

test_runs/
34 changes: 32 additions & 2 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use dcp::VERSION;
use predicates::prelude::*;
use rand::{thread_rng, Rng};
use std::error::Error;
use std::fs::remove_dir_all;

const PRG: &str = "dcp";
const TEST_CONTENT_DIR: &str = "/tmp/dcp_test_run";
const TEST_CONTENT_DIR: &str = "./test_runs";
const DEFAULT_IMAGE: &str = "quay.io/tyslaton/sample-catalog:v0.0.4";
const IMAGE_NO_TAG: &str = "quay.io/tyslaton/sample-catalog";
const SCRATCH_BASE_IMAGE: &str = "quay.io/tflannag/bundles:resolveset-v0.0.2";
Expand All @@ -14,7 +15,22 @@ const SCRATCH_BASE_IMAGE: &str = "quay.io/tflannag/bundles:resolveset-v0.0.2";
// returns a new string with an appended 5 digit string
fn generate_temp_path() -> String {
let random_string = thread_rng().gen_range(10000..99999);
return format!("{}_{}", TEST_CONTENT_DIR, random_string);
format!("{}/{}", TEST_CONTENT_DIR, random_string)
}

// clean_up_test_dir removes the testing directory specified completely.
//
// WARNING: This function is deleting directories recursively, if you are
// using it, be absolutely sure you know what you're doing.
fn clean_up_test_dir(path: &str) {
if path.starts_with(TEST_CONTENT_DIR) {
match remove_dir_all(path) {
Ok(_) => {}
Err(e) => {
eprintln!("failed to delete testing dir {}:{}", path, e);
}
}
}
}

type TestResult = Result<(), Box<dyn Error>>;
Expand Down Expand Up @@ -49,6 +65,8 @@ fn accepts_download_path() -> TestResult {
// verify that content was written to the desired download_path
assert_eq!(std::path::Path::new(path).exists(), true);

clean_up_test_dir(path);

Ok(())
}

Expand All @@ -69,6 +87,8 @@ fn accepts_content_path() -> TestResult {
let specific_content = &format!("{}/{}", path, content_path);
assert_eq!(std::path::Path::new(specific_content).exists(), true);

clean_up_test_dir(path);

Ok(())
}

Expand All @@ -87,6 +107,8 @@ fn fails_invalid_content_path() -> TestResult {
.assert()
.failure();

clean_up_test_dir(path);

Ok(())
}

Expand All @@ -108,6 +130,8 @@ fn accepts_image() -> TestResult {
.assert()
.failure();

clean_up_test_dir(path);

Ok(())
}

Expand All @@ -123,6 +147,8 @@ fn defaults_tag_to_latest() -> TestResult {
.assert()
.success();

clean_up_test_dir(path);

Ok(())
}

Expand All @@ -138,6 +164,8 @@ fn fails_on_just_tag() -> TestResult {
.assert()
.failure();

clean_up_test_dir(path);

Ok(())
}

Expand All @@ -154,5 +182,7 @@ fn accepts_scratch_base_images() -> TestResult {
.assert()
.success();

clean_up_test_dir(path);

Ok(())
}