Skip to content
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
17 changes: 17 additions & 0 deletions api/src/urls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,23 @@ mod tests {
);
}

/// ADR-0019's `--no-repo` vector: the server names no repository with the nil UUID.
#[test]
fn test_collection_guid_url_generated_without_a_repo() {
let test_case = test_case_with_id("88e5353c-190c-5dce-9d06-0e66c3e062b1");
let ids = TestCaseGuidScope {
test_collection_id: String::from(COLLECTION_ID),
repo_id: Uuid::nil().to_string(),
};

assert_eq!(
test_case_url(&test_case, "tc_123", Some(&ids)),
Ok(String::from(
"https://app.trunk-staging.io/bad-app-org/flaky-tests/collections/tc_123/tests/943a80af-66b0-84bb-ad01-56b3b72fe363"
)),
);
}

#[test]
fn test_collection_guid_url_falls_back_for_an_unparseable_server_id() {
let ids = TestCaseGuidScope {
Expand Down
1 change: 1 addition & 0 deletions cli/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ pub async fn gather_exit_code_and_quarantined_tests_context(
org_url_slug: String::default(),
fetch_status: QuarantineFetchStatus::FetchSkipped,
quarantine_resolution_mode: api::message::QuarantineResolutionMode::Unspecified,
guid_scope: None,
}
} else {
// default to success if no test run result (i.e. `upload`)
Expand Down
8 changes: 8 additions & 0 deletions cli/src/context_quarantine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct QuarantineContext {
pub org_url_slug: String,
pub fetch_status: QuarantineFetchStatus,
pub quarantine_resolution_mode: QuarantineResolutionMode,
pub guid_scope: Option<TestCaseGuidScope>,
}
impl QuarantineContext {
pub fn quarantining(&self, disable_quarantining: bool) -> Quarantining {
Expand All @@ -70,6 +71,7 @@ impl QuarantineContext {
org_url_slug: String::default(),
fetch_status: QuarantineFetchStatus::FetchSkipped,
quarantine_resolution_mode: QuarantineResolutionMode::Unspecified,
guid_scope: None,
}
}

Expand All @@ -82,6 +84,7 @@ impl QuarantineContext {
org_url_slug: String::default(),
fetch_status: QuarantineFetchStatus::FetchFailed(error),
quarantine_resolution_mode: QuarantineResolutionMode::Unspecified,
guid_scope: None,
}
}
}
Expand Down Expand Up @@ -338,6 +341,7 @@ pub async fn gather_quarantine_context(
failures: Vec::default(),
fetch_status: QuarantineFetchStatus::FetchSkipped,
quarantine_resolution_mode: QuarantineResolutionMode::Unspecified,
guid_scope: None,
});
}

Expand Down Expand Up @@ -395,6 +399,7 @@ pub async fn gather_quarantine_context(
org_url_slug: request.org_url_slug.clone(),
fetch_status: quarantine_fetch_status,
quarantine_resolution_mode,
guid_scope,
});
} else {
// quarantining is enabled, continue with quarantine process and update exit code
Expand Down Expand Up @@ -487,6 +492,7 @@ pub async fn gather_quarantine_context(
org_url_slug: request.org_url_slug.clone(),
fetch_status: quarantine_fetch_status,
quarantine_resolution_mode,
guid_scope,
})
}

Expand Down Expand Up @@ -711,6 +717,7 @@ mod tests {
org_url_slug: String::new(),
fetch_status: QuarantineFetchStatus::FetchSucceeded,
quarantine_resolution_mode: QuarantineResolutionMode::Unspecified,
guid_scope: None,
};
assert_eq!(
quarantine_query_result(false, &success_ctx),
Expand Down Expand Up @@ -741,6 +748,7 @@ mod tests {
repo: RepoUrlParts::default(),
org_url_slug: String::new(),
quarantine_resolution_mode: QuarantineResolutionMode::Unspecified,
guid_scope: None,
};
assert_eq!(
quarantine_query_result(false, &repo_disabled_ctx),
Expand Down
2 changes: 2 additions & 0 deletions cli/src/upload_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,8 @@ pub async fn run_upload(
)),
),
};
// A dry run or a failed upload has no upload ids, but a v2 quarantine lookup returns the same pair.
let guid_scope = guid_scope.or_else(|| quarantine_context.guid_scope.clone());
if guid_scope.is_none() && upload_args.test_collection_short_id.is_some() {
tracing::debug!(
"No test collection ids returned for this upload; test links will use the short-link form"
Expand Down
59 changes: 59 additions & 0 deletions cli/tests/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,65 @@ async fn upload_bundle_falls_back_to_short_links_without_collection_ids() {
.stdout(predicate::str::contains("/collections/tc_123/tests/").not());
}

// NOTE: must be multi threaded to start a mock server
#[tokio::test(flavor = "multi_thread")]
async fn failed_v2_upload_links_tests_by_the_quarantine_lookup_ids() {
use axum::routing::post;
use serde_json::{Value, json};

let temp_dir = tempdir().unwrap();
generate_mock_git_repo(&temp_dir);
fs::copy(
get_test_file_path("test_fixtures/junit0_fail.xml"),
temp_dir.path().join("junit.xml"),
)
.unwrap();

let mut builder = MockServerBuilder::new();
builder.route(
"/v1/metrics/getUploadApiVersion",
post(|| async { Json(json!({"apiVersion": "v2"})) }),
);
builder.route(
"/v2/test-collections/:id/quarantine-status",
post(|Json(body): Json<Value>| async move {
let tests: Vec<Value> = body["testIdentifiers"]
.as_array()
.unwrap()
.iter()
.map(|identifier| json!({"clientTestId": identifier["id"], "quarantined": false}))
.collect();
Json(json!({
"testCollectionUuid": MOCK_TEST_COLLECTION_ID,
"repositoryId": MOCK_REPO_ID,
"quarantineEnabled": true,
"tests": tests,
}))
}),
);
builder.route(
"/v2/test-collections/:id/uploads",
post(|| async { (StatusCode::BAD_REQUEST, Json(json!({}))) }),
);
let state = builder.spawn_mock_server().await;

// The GUID hashes MOCK_TEST_COLLECTION_ID, MOCK_REPO_ID and the id of junit0_fail.xml's one test.
CommandBuilder::upload(temp_dir.path(), state.host.clone())
.junit_paths("junit.xml")
.command()
.arg("--test-collection-id")
.arg("tc_123")
.assert()
.failure()
.stdout(predicate::str::contains(format!(
"{}/test-org/flaky-tests/collections/tc_123/tests/ae979ba6-6f93-8657-9f84-0265e5ac404c",
state.host
)))
.stdout(predicate::str::contains("/tests/").count(1))
.stdout(predicate::str::contains("/collections/tc_123/t/").not())
.stdout(predicate::str::contains("?repo=trunk-io%2Fanalytics-cli").not());
}

// NOTE: must be multi threaded to start a mock server
#[tokio::test(flavor = "multi_thread")]
async fn upload_bundle_prints_test_collection_upload_link() {
Expand Down
Loading