From 3dd64bb85ac916628b57130f927116dda2e3bfc5 Mon Sep 17 00:00:00 2001 From: Dylan Frankland Date: Wed, 8 Jan 2025 12:28:51 -0800 Subject: [PATCH] do not quarantine when no junit files found --- cli-tests/src/test.rs | 45 ++++++++++++++++++++++++++++++++++++++--- cli-tests/src/upload.rs | 32 +++++++++++++++++++++++++++++ cli/src/runner.rs | 14 +++++++------ 3 files changed, 82 insertions(+), 9 deletions(-) diff --git a/cli-tests/src/test.rs b/cli-tests/src/test.rs index 4793093d..713953cf 100644 --- a/cli-tests/src/test.rs +++ b/cli-tests/src/test.rs @@ -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() { @@ -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(); diff --git a/cli-tests/src/upload.rs b/cli-tests/src/upload.rs index a3572d98..ef416ab4 100644 --- a/cli-tests/src/upload.rs +++ b/cli-tests/src/upload.rs @@ -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}"); +} diff --git a/cli/src/runner.rs b/cli/src/runner.rs index 9addc971..e0331184 100644 --- a/cli/src/runner.rs +++ b/cli/src/runner.rs @@ -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");