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
3 changes: 3 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Delete huge unnecessary tools folder
run: rm -rf /opt/hostedtoolcache

- name: Setup Rust & Cargo
uses: ./.github/actions/setup_rust_cargo

Expand Down
6 changes: 3 additions & 3 deletions cli-tests/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ async fn upload_bundle() {
assert_eq!(report.test_build_information, None);
assert_eq!(report.test_case_runs.len(), 500);
let test_case_run = &report.test_case_runs[0];
assert!(test_case_run.id.is_empty());
assert!(!test_case_run.id.is_empty());
assert!(!test_case_run.name.is_empty());
assert!(!test_case_run.classname.is_empty());
assert!(!test_case_run.file.is_empty());
Expand Down Expand Up @@ -318,7 +318,7 @@ async fn upload_bundle_using_bep() {
assert_eq!(test_build_information.label, "//path:test");

let test_case_run = &report.test_case_runs[0];
assert!(test_case_run.id.is_empty());
assert!(!test_case_run.id.is_empty());
assert!(!test_case_run.name.is_empty());
assert!(!test_case_run.classname.is_empty());
assert!(!test_case_run.file.is_empty());
Expand Down Expand Up @@ -393,7 +393,7 @@ async fn upload_bundle_using_xcresult() {
assert_eq!(test_result.test_build_information, None);
assert_eq!(test_result.test_case_runs.len(), 17);
let test_case_run = &test_result.test_case_runs[0];
assert!(test_case_run.id.is_empty());
assert!(!test_case_run.id.is_empty());
assert!(!test_case_run.name.is_empty());
assert!(!test_case_run.classname.is_empty());
assert_eq!(test_case_run.line, 0);
Expand Down
225 changes: 225 additions & 0 deletions context/src/junit/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ impl JunitParser {
)
});
test_case_run.is_quarantined = quarantined_test_ids.contains(&test_case_id);
test_case_run.id = test_case_id;

test_case_run.file = file;
test_case_run.line = test_case
Expand Down Expand Up @@ -1064,6 +1065,216 @@ mod tests {
})
);
assert_eq!(test_case_run1.line, 5);
// Verify that the ID field is set correctly (generated from gen_info_id)
assert_eq!(
test_case_run1.id,
gen_info_id(
org_slug.as_str(),
repo.repo_full_name().as_str(),
Some("test.java"),
Some("test"),
Some("testsuite"),
Some("test_variant_truncation1"),
None,
"",
)
);

let test_case_run2 = &test_case_runs[1];
assert_eq!(test_case_run2.name, "test_variant_truncation2");
assert_eq!(test_case_run2.parent_name, "testsuite");
assert_eq!(test_case_run2.classname, "");
assert_eq!(test_case_run2.status, TestCaseRunStatus::Failure as i32);
assert_eq!(test_case_run2.status_output_message, "Test failed");
assert_eq!(test_case_run2.file, "test.java");
assert_eq!(test_case_run2.attempt_number, 0);
assert!(!test_case_run2.is_quarantined);
// Verify that the ID field is set correctly for test_case_run2
assert_eq!(
test_case_run2.id,
gen_info_id(
org_slug.as_str(),
repo.repo_full_name().as_str(),
Some("test.java"),
None, // No classname for test_case_run2
Some("testsuite"),
Some("test_variant_truncation2"),
None,
"",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get a second case to test that we're getting the right id with a variant set? (There's a variant_wrapper function in the same file that defines gen_info_id for the correct behaviour)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even before this change, it looks like variant wasn't set up to be supported with xcresult. No customers have needed it yet, so I'll add a ticket to track.

)
);
}

#[test]
fn test_into_test_case_runs_with_custom_id() {
// Test that custom IDs from xcresult (or other sources) are preserved
let mut junit_parser = JunitParser::new();
let file_contents = r#"
<xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="testsuite" timestamp="2023-10-01T12:00:00Z" time="0.002">
<testcase id="custom-uuid-1234-5678" file="test.swift" classname="TestClass" name="test_with_custom_id" time="0.001">
</testcase>
</testsuite>
</testsuites>
"#;
let parsed_results = junit_parser.parse(BufReader::new(file_contents.as_bytes()));
assert!(parsed_results.is_ok());

let org_slug = "org-url-slug".to_string();
let repo = RepoUrlParts {
host: "repo-host".into(),
owner: "repo-owner".into(),
name: "repo-name".into(),
};

let test_case_runs = junit_parser.into_test_case_runs(None, &org_slug, &repo, &[]);
assert_eq!(test_case_runs.len(), 1);
let test_case_run = &test_case_runs[0];

// Verify that the custom ID from the XML is preserved
assert_eq!(test_case_run.id, "custom-uuid-1234-5678");
assert_eq!(test_case_run.name, "test_with_custom_id");
assert_eq!(test_case_run.file, "test.swift");
assert_eq!(test_case_run.classname, "TestClass");
}

#[test]
fn test_into_test_case_runs_mixed_ids() {
// Test mix of custom IDs and generated IDs
let mut junit_parser = JunitParser::new();
let file_contents = r#"
<xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="testsuite" timestamp="2023-10-01T12:00:00Z" time="0.002">
<testcase id="xcresult-uuid-abcd" file="test.swift" classname="TestClass" name="test_with_id" time="0.001">
</testcase>
<testcase file="test.swift" classname="TestClass" name="test_without_id" time="0.001">
</testcase>
</testsuite>
</testsuites>
"#;
let parsed_results = junit_parser.parse(BufReader::new(file_contents.as_bytes()));
assert!(parsed_results.is_ok());

let org_slug = "org-url-slug".to_string();
let repo = RepoUrlParts {
host: "repo-host".into(),
owner: "repo-owner".into(),
name: "repo-name".into(),
};

let test_case_runs = junit_parser.into_test_case_runs(None, &org_slug, &repo, &[]);
assert_eq!(test_case_runs.len(), 2);

// First test case should have the custom ID
let test_case_run1 = &test_case_runs[0];
assert_eq!(test_case_run1.id, "xcresult-uuid-abcd");
assert_eq!(test_case_run1.name, "test_with_id");

// Second test case should have a generated ID
let test_case_run2 = &test_case_runs[1];
assert_eq!(
test_case_run2.id,
gen_info_id(
org_slug.as_str(),
repo.repo_full_name().as_str(),
Some("test.swift"),
Some("TestClass"),
Some("testsuite"),
Some("test_without_id"),
None,
"",
)
);
assert_eq!(test_case_run2.name, "test_without_id");
}

#[test]
fn test_into_test_case_runs_original() {
let mut junit_parser = JunitParser::new();
let file_contents = r#"
<xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="testsuite" timestamp="2023-10-01T12:00:00Z" time="0.002">
<testcase file="test.java" line="5" classname="test" name="test_variant_truncation1" time="0.001">
<failure message="Test failed" type="java.lang.AssertionError">
<![CDATA[Expected: <true> but was: <false>]]>
</failure>
</testcase>
<testcase file="test.java" name="test_variant_truncation2" time="0.001">
<failure message="Test failed"/>
</testcase>
</testsuite>
</testsuites>
"#;
let parsed_results = junit_parser.parse(BufReader::new(file_contents.as_bytes()));
assert!(parsed_results.is_ok());

let org_slug = "org-url-slug".to_string();
let repo = RepoUrlParts {
host: "repo-host".into(),
owner: "repo-owner".into(),
name: "repo-name".into(),
};

let test_case_runs = junit_parser.into_test_case_runs(
None,
&org_slug,
&repo,
&[gen_info_id(
org_slug.as_str(),
repo.repo_full_name().as_str(),
Some("test.java"),
Some("test"),
Some("testsuite"),
Some("test_variant_truncation1"),
None,
"",
)],
);
assert_eq!(test_case_runs.len(), 2);
let test_case_run1 = &test_case_runs[0];
assert_eq!(test_case_run1.name, "test_variant_truncation1");
assert_eq!(test_case_run1.parent_name, "testsuite");
assert_eq!(test_case_run1.classname, "test");
assert_eq!(test_case_run1.status, TestCaseRunStatus::Failure as i32);
assert_eq!(
test_case_run1.status_output_message,
"Expected: <true> but was: <false>"
);
assert_eq!(test_case_run1.file, "test.java");
assert_eq!(test_case_run1.attempt_number, 0);
assert!(test_case_run1.is_quarantined);
assert_eq!(
test_case_run1.started_at,
Some(Timestamp {
seconds: 1696161600,
nanos: 0
})
);
assert_eq!(
test_case_run1.finished_at,
Some(Timestamp {
seconds: 1696161600,
nanos: 1000000
})
);
assert_eq!(test_case_run1.line, 5);
// Verify that the ID field is set correctly (generated from gen_info_id)
assert_eq!(
test_case_run1.id,
gen_info_id(
org_slug.as_str(),
repo.repo_full_name().as_str(),
Some("test.java"),
Some("test"),
Some("testsuite"),
Some("test_variant_truncation1"),
None,
"",
)
);

let test_case_run2 = &test_case_runs[1];
assert_eq!(test_case_run2.name, "test_variant_truncation2");
Expand All @@ -1074,6 +1285,20 @@ mod tests {
assert_eq!(test_case_run2.file, "test.java");
assert_eq!(test_case_run2.attempt_number, 0);
assert!(!test_case_run2.is_quarantined);
// Verify that the ID field is set correctly for test_case_run2
assert_eq!(
test_case_run2.id,
gen_info_id(
org_slug.as_str(),
repo.repo_full_name().as_str(),
Some("test.java"),
None, // No classname for test_case_run2
Some("testsuite"),
Some("test_variant_truncation2"),
None,
"",
)
);
assert_eq!(
test_case_run2.started_at,
Some(Timestamp {
Expand Down
2 changes: 1 addition & 1 deletion xcresult/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ tracing = "0.1.41"
uuid = { version = "1.10.0", features = ["v5"] }

[dev-dependencies]
context = { path = "../context" }
context = { path = "../context", features = ["bindings"] }
flate2 = "1.0.34"
pretty_assertions = "0.6"
tar = "0.4.42"
Expand Down
Loading
Loading