Skip to content

Commit

Permalink
Add 'Tests' to all status checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mrginglymus committed Dec 3, 2020
1 parent d1274bc commit c227039
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
14 changes: 8 additions & 6 deletions src/main/java/hudson/tasks/junit/JUnitResultArchiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -98,6 +99,8 @@ public class JUnitResultArchiver extends Recorder implements SimpleBuildStep, JU
private boolean skipPublishingChecks;
private String checksName;

private static final String DEFAULT_CHECKS_NAME = "Tests";

@DataBoundConstructor
public JUnitResultArchiver(String testResults) {
this.testResults = testResults;
Expand Down Expand Up @@ -286,14 +289,13 @@ public static TestResultSummary parseAndSummarize(@Nonnull JUnitTask task, Pipel

if (!task.isSkipPublishingChecks()) {
// If we haven't been provided with a checks name, and we have pipeline test details, set the checks name
// to be a ' / '-joined string of the enclosing blocks names. If all of that ends up being empty or null,
// set a default of 'Tests'
// to be a ' / '-joined string of the enclosing blocks names, plus 'Tests' at the end. If there are no
// enclosing blocks, you'll end up with just 'Tests'.
String checksName = task.getChecksName();
if (checksName == null && pipelineTestDetails != null) {
checksName = StringUtils.join(new ReverseListIterator(pipelineTestDetails.getEnclosingBlockNames()), " / ");
}
if (Util.fixEmpty(checksName) == null) {
checksName = "Tests";
List<String> checksComponents = new ArrayList<>(pipelineTestDetails.getEnclosingBlockNames());
checksComponents.add(0, DEFAULT_CHECKS_NAME);
checksName = StringUtils.join(new ReverseListIterator(checksComponents), " / ");
}
new JUnitChecksPublisher(build, checksName, result, summary).publishChecks(listener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import io.jenkins.plugins.checks.api.ChecksPublisherFactory;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
Expand Down Expand Up @@ -84,7 +83,7 @@ public void extractChecksDetailsPassingTestResults() throws Exception {
ChecksDetails checksDetails = getDetail();

assertThat(checksDetails.getConclusion(), is(ChecksConclusion.SUCCESS));
assertThat(checksDetails.getName().get(), is("first"));
assertThat(checksDetails.getName().get(), is("first / Tests"));

ChecksOutput output = checksDetails.getOutput().get();

Expand Down Expand Up @@ -112,7 +111,7 @@ public void extractChecksDetailsFailingSingleTestResult() throws Exception {
ChecksDetails checksDetails = getDetail();

assertThat(checksDetails.getConclusion(), is(ChecksConclusion.FAILURE));
assertThat(checksDetails.getName().get(), is("first"));
assertThat(checksDetails.getName().get(), is("first / Tests"));

ChecksOutput output = checksDetails.getOutput().get();

Expand All @@ -139,7 +138,7 @@ public void extractChecksDetailsFailingMultipleTests() throws Exception {
ChecksDetails checksDetails = getDetail();

assertThat(checksDetails.getConclusion(), is(ChecksConclusion.FAILURE));
assertThat(checksDetails.getName().get(), is("first"));
assertThat(checksDetails.getName().get(), is("first / Tests"));

ChecksOutput output = checksDetails.getOutput().get();

Expand Down Expand Up @@ -208,6 +207,6 @@ public void extractChecksDetailsNestedStages() throws Exception {

ChecksDetails checksDetails = getDetail();

assertThat(checksDetails.getName().get(), is("first / second"));
assertThat(checksDetails.getName().get(), is("first / second / Tests"));
}
}

0 comments on commit c227039

Please sign in to comment.