Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PublishChecks step: The conclusion should be none when status is not completed #82

Merged
merged 5 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,16 @@ public void setDetailsURL(final String detailsURL) {
this.detailsURL = detailsURL;
}

/**
* Change the status of the Publish Check Step.
* @param status CheckStatus
*/
ThusithaDJ marked this conversation as resolved.
Show resolved Hide resolved
@DataBoundSetter
public void setStatus(final ChecksStatus status) {
this.status = status;
if (status == ChecksStatus.QUEUED || status == ChecksStatus.IN_PROGRESS) {
this.conclusion = ChecksConclusion.NONE;
}
}

@DataBoundSetter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,28 @@
import org.apache.commons.lang3.StringUtils;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.StepExecution;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Objects;

import static org.assertj.core.api.Assertions.assertThat;
import static io.jenkins.plugins.checks.assertions.Assertions.assertThat;
import static org.mockito.Mockito.*;

class PublishChecksStepTest {
@Test
void shouldPublishCheckWithDefaultValues() throws IOException, InterruptedException {
StepContext context = mock(StepContext.class);
private StepContext context;

@BeforeEach
void setup() throws IOException, InterruptedException {
Copy link
Contributor

Choose a reason for hiding this comment

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

In this project, if possible, I normally avoid using @BeforeEach and shared variables between tests. I usually just make a private method like getModifiedPublishChecksStepObject that returns what I want.

this.context = mock(StepContext.class);
when(context.get(Run.class)).thenReturn(mock(Run.class));
when(context.get(TaskListener.class)).thenReturn(TaskListener.NULL);
}

@Test
void shouldPublishCheckWithDefaultValues() throws IOException, InterruptedException {
StepExecution execution = new PublishChecksStep().start(context);
assertThat(execution).isInstanceOf(PublishChecksStep.PublishChecksStepExecution.class);
assertThat(((PublishChecksStep.PublishChecksStepExecution)execution).extractChecksDetails())
Expand All @@ -43,19 +49,53 @@ void shouldPublishCheckWithDefaultValues() throws IOException, InterruptedExcept
}

@Test
void shouldPublishCheckWithSetValues() throws IOException, InterruptedException {
PublishChecksStep step = new PublishChecksStep();
step.setName("Jenkins");
step.setSummary("a check made by Jenkins");
step.setTitle("Jenkins Build");
step.setText("a failed build");
step.setStatus(ChecksStatus.IN_PROGRESS);
step.setConclusion(ChecksConclusion.FAILURE);
step.setDetailsURL("http://ci.jenkins.io");
void shouldPublishCheckWithStatusInProgress() throws IOException, InterruptedException {
PublishChecksStep step = getModifiedPublishChecksStepObject("an in progress build",
ChecksStatus.IN_PROGRESS,null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ChecksStatus.IN_PROGRESS,null);
ChecksStatus.IN_PROGRESS, null);

Same for the next check style warning


StepContext context = mock(StepContext.class);
when(context.get(Run.class)).thenReturn(mock(Run.class));
when(context.get(TaskListener.class)).thenReturn(TaskListener.NULL);
StepExecution execution = step.start(context);
assertThat(execution).isInstanceOf(PublishChecksStep.PublishChecksStepExecution.class);
ThusithaDJ marked this conversation as resolved.
Show resolved Hide resolved
assertThat(((PublishChecksStep.PublishChecksStepExecution)execution).extractChecksDetails())
.usingRecursiveComparison()
.isEqualTo(new ChecksDetails.ChecksDetailsBuilder()
.withName("Jenkins")
.withStatus(ChecksStatus.IN_PROGRESS)
.withConclusion(ChecksConclusion.NONE)
.withDetailsURL("http://ci.jenkins.io")
.withOutput(new ChecksOutput.ChecksOutputBuilder()
.withTitle("Jenkins Build")
.withSummary("a check made by Jenkins")
.withText("an in progress build")
.build())
.build());
}

@Test
void shouldPublishCheckWithStatusQueue() throws IOException, InterruptedException {
PublishChecksStep step = getModifiedPublishChecksStepObject("a queued build",
ChecksStatus.QUEUED,null);

StepExecution execution = step.start(context);
assertThat(execution).isInstanceOf(PublishChecksStep.PublishChecksStepExecution.class);
assertThat(((PublishChecksStep.PublishChecksStepExecution)execution).extractChecksDetails())
.usingRecursiveComparison()
.isEqualTo(new ChecksDetails.ChecksDetailsBuilder()
.withName("Jenkins")
.withStatus(ChecksStatus.QUEUED)
.withConclusion(ChecksConclusion.NONE)
.withDetailsURL("http://ci.jenkins.io")
.withOutput(new ChecksOutput.ChecksOutputBuilder()
.withTitle("Jenkins Build")
.withSummary("a check made by Jenkins")
.withText("a queued build")
.build())
.build());
}

@Test
void shouldPublishCheckWithSetValues() throws IOException, InterruptedException {
PublishChecksStep step = getModifiedPublishChecksStepObject("a failed build",
ChecksStatus.IN_PROGRESS, ChecksConclusion.FAILURE);

StepExecution execution = step.start(context);
assertThat(execution).isInstanceOf(PublishChecksStep.PublishChecksStepExecution.class);
Expand All @@ -81,4 +121,22 @@ void shouldDefinePublishChecksStepDescriptorCorrectly() {
assertThat(descriptor.getDisplayName()).isEqualTo("Publish customized checks to SCM platforms");
assertThat(descriptor.getRequiredContext().toArray()).containsExactlyInAnyOrder(Run.class, TaskListener.class);
}

private PublishChecksStep getModifiedPublishChecksStepObject(final String stepText, final ChecksStatus status,
final ChecksConclusion conclusion) {
PublishChecksStep step = new PublishChecksStep();
step.setName("Jenkins");
step.setSummary("a check made by Jenkins");
step.setTitle("Jenkins Build");
step.setText(stepText);
if (Objects.nonNull(status)) {
step.setStatus(status);
}
if (Objects.nonNull(conclusion)) {
step.setConclusion(conclusion);
}
step.setDetailsURL("http://ci.jenkins.io");

return step;
}
}