Skip to content

Commit

Permalink
Fix test and use a stub rather than a real Workflow instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Dec 17, 2024
1 parent e2a99a0 commit bd25346
Showing 1 changed file with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package io.jenkins.plugins.forensics.util;

import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

import org.assertj.core.api.ObjectAssert;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition;
Expand All @@ -16,7 +14,6 @@
import hudson.EnvVars;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.ItemGroup;
import hudson.model.Job;
import hudson.model.Run;
import hudson.model.TaskListener;
Expand Down Expand Up @@ -118,14 +115,18 @@ private SCM createScm(final String key) {
return first;
}

@Disabled("TODO rewrite to use JenkinsRule, not Mockito")
@Test
void shouldResolveScmForPipelineWithFlowNode() throws IOException {
WorkflowJob pipeline = createPipeline();
pipeline.setDefinition(createCpsFlowDefinition());
void shouldResolveScmForPipelineWithFlowNode() {
var pipeline = mock(WorkflowJob.class);

Run<?, ?> run = createRunFor(pipeline);
assertThatScmOf(run).isInstanceOf(SCM.class);
var empty = createRunFor(pipeline);
assertThatScmOf(empty).isInstanceOf(NullSCM.class);

var flowDefinition = createCpsFlowDefinition();
when(pipeline.getDefinition()).thenReturn(flowDefinition);

var withScmFromFlowDefinition = createRunFor(pipeline);
assertThatScmOf(withScmFromFlowDefinition).isInstanceOf(SCM.class);
}

private CpsScmFlowDefinition createCpsFlowDefinition() {
Expand All @@ -135,14 +136,6 @@ private CpsScmFlowDefinition createCpsFlowDefinition() {
return flowDefinition;
}

private WorkflowJob createPipeline() throws IOException {
ItemGroup<?> group = mock(ItemGroup.class);
WorkflowJob pipeline = new WorkflowJob(group, "stub");
when(group.getRootDirFor(any())).thenReturn(Files.createTempFile("", "").toFile());
when(group.getFullName()).thenReturn("bla");
return pipeline;
}

@Test
void shouldCreateNullBlamerForPipelineWithNoScm() {
Job<?, ?> pipeline = mock(Job.class, withSettings().extraInterfaces(SCMTriggerItem.class));
Expand Down

0 comments on commit bd25346

Please sign in to comment.