-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathPublishChecksStepITest.java
99 lines (87 loc) · 4.83 KB
/
PublishChecksStepITest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package io.jenkins.plugins.checks.steps;
import io.jenkins.plugins.checks.api.ChecksAction;
import io.jenkins.plugins.checks.api.ChecksAnnotation;
import io.jenkins.plugins.checks.api.ChecksConclusion;
import io.jenkins.plugins.checks.api.ChecksDetails;
import io.jenkins.plugins.checks.api.ChecksOutput;
import io.jenkins.plugins.checks.api.ChecksPublisherFactory;
import io.jenkins.plugins.checks.api.ChecksStatus;
import io.jenkins.plugins.checks.util.CapturingChecksPublisher;
import io.jenkins.plugins.util.IntegrationTestWithJenkinsPerTest;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;
import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests the pipeline step to publish checks.
*/
class PublishChecksStepITest extends IntegrationTestWithJenkinsPerTest {
private CapturingChecksPublisher.Factory getFactory() {
return getJenkins().getInstance().getExtensionList(ChecksPublisherFactory.class)
.stream()
.filter(f -> f instanceof CapturingChecksPublisher.Factory)
.map(f -> (CapturingChecksPublisher.Factory) f)
.findAny()
.orElseThrow(() -> new AssertionError("No CapturingChecksPublisher registered as @TestExtension?"));
}
/**
* Tests that the step "publishChecks" can be used in pipeline script.
*
* @throws IOException if fails get log from run
*/
@Test
public void shouldPublishChecksWhenUsingPipeline() throws IOException {
WorkflowJob job = createPipeline();
job.setDefinition(asStage("publishChecks name: 'customized-check', "
+ "summary: 'customized check created in pipeline', title: 'Publish Checks Step', "
+ "text: 'Pipeline support for checks', status: 'IN_PROGRESS', conclusion: 'NONE', "
+ "actions: [[label:'test-label', description:'test-desc', identifier:'test-id']], "
+ "annotations: ["
+ " [path:'Jenkinsfile', startLine:1, endLine:1, message:'test with only required params'], "
+ " [path:'Jenkinsfile', startLine:2, endLine:2, message:'test with all params', "
+ " annotationLevel:'NOTICE', startColumn:0, endColumn:10, title:'integration test', "
+ " rawDetails:'raw details']]"));
assertThat(JenkinsRule.getLog(buildSuccessfully(job)))
.contains("[Pipeline] publishChecks");
assertThat(getFactory().getPublishedChecks().size()).isEqualTo(1);
ChecksDetails details = getFactory().getPublishedChecks().get(0);
assertThat(details.getName()).isPresent().get().isEqualTo("customized-check");
assertThat(details.getOutput()).isPresent();
assertThat(details.getStatus()).isEqualTo(ChecksStatus.IN_PROGRESS);
assertThat(details.getConclusion()).isEqualTo(ChecksConclusion.NONE);
assertThat(details.getActions()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(
new ChecksAction("test-label", "test-desc", "test-id"));
ChecksOutput output = details.getOutput().get();
assertThat(output.getTitle()).isPresent().get().isEqualTo("Publish Checks Step");
assertThat(output.getSummary()).isPresent().get().isEqualTo("customized check created in pipeline");
assertThat(output.getText()).isPresent().get().isEqualTo("Pipeline support for checks");
assertThat(output.getChecksAnnotations()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(
new ChecksAnnotation.ChecksAnnotationBuilder()
.withPath("Jenkinsfile")
.withStartLine(1)
.withEndLine(1)
.withAnnotationLevel(ChecksAnnotation.ChecksAnnotationLevel.WARNING)
.withMessage("test with only required params")
.build(),
new ChecksAnnotation.ChecksAnnotationBuilder()
.withPath("Jenkinsfile")
.withStartLine(2)
.withEndLine(2)
.withAnnotationLevel(ChecksAnnotation.ChecksAnnotationLevel.NOTICE)
.withMessage("test with all params")
.withStartColumn(0)
.withEndColumn(10)
.withTitle("integration test")
.withRawDetails("raw details")
.build());
}
/**
* Provide a {@link CapturingChecksPublisher} to check published checks on each test.
*/
@TestExtension
public static class CapturingChecksPublisherTestExtension extends CapturingChecksPublisher.Factory {
// activate test extension
}
}