Skip to content

Commit

Permalink
Merging 3dd64bb into trunk-temp/pr-279/38c277ac-fcce-498f-bc6d-589c7c…
Browse files Browse the repository at this point in the history
…e61514
  • Loading branch information
trunk-io[bot] authored Jan 11, 2025
2 parents a3ae3f0 + 3dd64bb commit 5e3e059
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 9 deletions.
45 changes: 42 additions & 3 deletions cli-tests/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::utils::{
generate_mock_codeowners, generate_mock_git_repo, generate_mock_valid_junit_xmls, CARGO_RUN,
};
use assert_cmd::Command;
use predicates::prelude::*;
use tempfile::tempdir;
use test_utils::mock_server::MockServerBuilder;

use crate::utils::{
generate_mock_codeowners, generate_mock_git_repo, generate_mock_valid_junit_xmls, CARGO_RUN,
};

// NOTE: must be multi threaded to start a mock server
#[tokio::test(flavor = "multi_thread")]
async fn test_command_succeeds_with_successful_upload() {
Expand Down Expand Up @@ -75,6 +77,43 @@ async fn test_command_fails_with_successful_upload() {
.code(1);
}

#[tokio::test(flavor = "multi_thread")]
async fn test_command_fails_with_no_junit_files_no_quarantine_successful_upload() {
let temp_dir = tempdir().unwrap();
generate_mock_git_repo(&temp_dir);
generate_mock_codeowners(&temp_dir);

let state = MockServerBuilder::new().spawn_mock_server().await;

let args = &[
"test",
"--junit-paths",
"./*",
"--org-url-slug",
"test-org",
"--token",
"test-token",
"bash",
"-c",
"exit 128",
];

let assert = Command::new(CARGO_RUN.path())
.current_dir(&temp_dir)
.env("TRUNK_PUBLIC_API_ADDRESS", &state.host)
.env("CI", "1")
.env("GITHUB_JOB", "test-job")
.args(args)
.assert()
.failure()
.code(128)
.stderr(predicate::str::contains(
"No JUnit files found, not quarantining any tests",
));

println!("{assert}");
}

#[tokio::test(flavor = "multi_thread")]
async fn test_command_succeeds_with_upload_not_connected() {
let temp_dir = tempdir().unwrap();
Expand Down
32 changes: 32 additions & 0 deletions cli-tests/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,35 @@ async fn upload_bundle_when_server_down() {

println!("{assert}");
}

#[tokio::test(flavor = "multi_thread")]
async fn upload_bundle_with_no_junit_files_no_quarantine_successful_upload() {
let temp_dir = tempdir().unwrap();
generate_mock_git_repo(&temp_dir);

let state = MockServerBuilder::new().spawn_mock_server().await;

let assert = Command::new(CARGO_RUN.path())
.current_dir(&temp_dir)
.env("TRUNK_PUBLIC_API_ADDRESS", &state.host)
.env("CI", "1")
.env("GITHUB_JOB", "test-job")
.args([
"upload",
"--junit-paths",
"./*",
"--org-url-slug",
"test-org",
"--token",
"test-token",
])
.assert()
.code(0)
.success()
.stderr(predicate::str::contains(
"No JUnit files found, not quarantining any tests",
));

// HINT: View CLI output with `cargo test -- --nocapture`
println!("{assert}");
}
14 changes: 8 additions & 6 deletions cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,16 @@ pub async fn run_quarantine(
)
});

if let Some(exit_code) = test_run_exit_code {
if failed_tests_extractor.failed_tests().is_empty() && exit_code != EXIT_SUCCESS {
log::warn!("Command failed but no test failures were found!");
}
}

let exit_code = test_run_exit_code.unwrap_or_else(|| failed_tests_extractor.exit_code());

if file_set_builder.no_files_found() {
log::info!("No JUnit files found, not quarantining any tests");
return QuarantineRunResult {
exit_code,
..Default::default()
};
}

let quarantine_config: api::QuarantineConfig =
if !failed_tests_extractor.failed_tests().is_empty() {
log::info!("Checking if failed tests can be quarantined");
Expand Down

0 comments on commit 5e3e059

Please sign in to comment.