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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

* [Issue #335](https://github.com/manheim/terraform-pipeline/issues/335) Testing: Rename DummyJenkinsfile to MockWorkflowScript to better distinguish Jenkinsfile references.
* [Issue #271](https://github.com/manheim/terraform-pipeline/issues/271) Testing: Cleanup Test resets for any static state. New Resettable and ResetStaticStateExtension available.
* [Issue #332](https://github.com/manheim/terraform-pipeline/issues/332) Upgrade from Junit 4 to 5.7, upgrade hamcrest from 1.3 to 2.2, remove junit-hierarchicalcontextrunner dependency

Expand Down
62 changes: 31 additions & 31 deletions test/AgentNodePluginTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import org.junit.jupiter.api.extension.ExtendWith

@ExtendWith(ResetStaticStateExtension.class)
class AgentNodePluginTest {
private createJenkinsfileSpy() {
def dummyJenkinsfile = spy(new DummyJenkinsfile())
dummyJenkinsfile.docker = dummyJenkinsfile
private createOriginalSpy() {
def workflowScript = spy(new MockWorkflowScript())
workflowScript.docker = workflowScript

return dummyJenkinsfile
return workflowScript
}

@Nested
Expand Down Expand Up @@ -101,7 +101,7 @@ class AgentNodePluginTest {
def innerClosure = spy { -> }

def agentClosure = plugin.addAgent()
agentClosure.delegate = new DummyJenkinsfile()
agentClosure.delegate = new MockWorkflowScript()
agentClosure(innerClosure)

verify(innerClosure).call()
Expand All @@ -110,28 +110,28 @@ class AgentNodePluginTest {
@Test
void usesTheGivenDockerImage() {
def plugin = new AgentNodePlugin()
def jenkinsfile = createJenkinsfileSpy()
def original = createOriginalSpy()

def agentClosure = plugin.addAgent()
agentClosure.delegate = jenkinsfile
agentClosure.delegate = original
agentClosure { -> }

verify(jenkinsfile).image(expectedImage)
verify(original).image(expectedImage)
}

@Test
void usesTheGivenDockerOptions() {
def expectedOptions = 'someOptions'
AgentNodePlugin.withAgentDockerImageOptions(expectedOptions)
def plugin = new AgentNodePlugin()
def jenkinsfile = createJenkinsfileSpy()
jenkinsfile.docker = jenkinsfile
def original = createOriginalSpy()
original.docker = original

def agentClosure = plugin.addAgent()
agentClosure.delegate = jenkinsfile
agentClosure.delegate = original
agentClosure { -> }

verify(jenkinsfile).inside(eq(expectedOptions), anyObject())
verify(original).inside(eq(expectedOptions), anyObject())
}
}

Expand All @@ -150,7 +150,7 @@ class AgentNodePluginTest {
def innerClosure = spy { -> }

def agentClosure = plugin.addAgent()
agentClosure.delegate = new DummyJenkinsfile()
agentClosure.delegate = new MockWorkflowScript()
agentClosure(innerClosure)

verify(innerClosure).call()
Expand All @@ -160,27 +160,27 @@ class AgentNodePluginTest {
void usesTheGivenDockerImage() {
AgentNodePlugin.withAgentDockerfile()
def plugin = new AgentNodePlugin()
def jenkinsfile = createJenkinsfileSpy()
def original = createOriginalSpy()

def agentClosure = plugin.addAgent()
agentClosure.delegate = jenkinsfile
agentClosure.delegate = original
agentClosure { -> }

verify(jenkinsfile).build(eq(expectedImage), anyString())
verify(original).build(eq(expectedImage), anyString())
}

@Test
void worksWithoutBuildOptions() {
def expectedBuildCommand = '-f Dockerfile .'
AgentNodePlugin.withAgentDockerfile('Dockerfile')
def plugin = new AgentNodePlugin()
def jenkinsfile = createJenkinsfileSpy()
def original = createOriginalSpy()

def agentClosure = plugin.addAgent()
agentClosure.delegate = jenkinsfile
agentClosure.delegate = original
agentClosure { -> }

verify(jenkinsfile).build(anyString(), eq(expectedBuildCommand))
verify(original).build(anyString(), eq(expectedBuildCommand))
}

@Test
Expand All @@ -189,40 +189,40 @@ class AgentNodePluginTest {
AgentNodePlugin.withAgentDockerfile()
.withAgentDockerBuildOptions(expectedOptions)
def plugin = new AgentNodePlugin()
def jenkinsfile = createJenkinsfileSpy()
def original = createOriginalSpy()

def agentClosure = plugin.addAgent()
agentClosure.delegate = jenkinsfile
agentClosure.delegate = original
agentClosure { -> }

verify(jenkinsfile).build(anyString(), contains(expectedOptions))
verify(original).build(anyString(), contains(expectedOptions))
}

@Test
void usesFileNamedDockerfileByDefault() {
AgentNodePlugin.withAgentDockerfile()
def plugin = new AgentNodePlugin()
def jenkinsfile = createJenkinsfileSpy()
def original = createOriginalSpy()

def agentClosure = plugin.addAgent()
agentClosure.delegate = jenkinsfile
agentClosure.delegate = original
agentClosure { -> }

verify(jenkinsfile).build(anyString(), contains('-f Dockerfile'))
verify(original).build(anyString(), contains('-f Dockerfile'))
}

@Test
void usesGivenDockerfile() {
def expectedDockerfile = 'someDockerfile'
AgentNodePlugin.withAgentDockerfile(expectedDockerfile)
def plugin = new AgentNodePlugin()
def jenkinsfile = createJenkinsfileSpy()
def original = createOriginalSpy()

def agentClosure = plugin.addAgent()
agentClosure.delegate = jenkinsfile
agentClosure.delegate = original
agentClosure { -> }

verify(jenkinsfile).build(anyString(), contains("-f ${expectedDockerfile}"))
verify(original).build(anyString(), contains("-f ${expectedDockerfile}"))
}

@Test
Expand All @@ -231,13 +231,13 @@ class AgentNodePluginTest {
AgentNodePlugin.withAgentDockerfile()
.withAgentDockerImageOptions(expectedOptions)
def plugin = new AgentNodePlugin()
def jenkinsfile = createJenkinsfileSpy()
def original = createOriginalSpy()

def agentClosure = plugin.addAgent()
agentClosure.delegate = jenkinsfile
agentClosure.delegate = original
agentClosure { -> }

verify(jenkinsfile).inside(eq(expectedOptions), anyObject())
verify(original).inside(eq(expectedOptions), anyObject())
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/BuildWithParametersPluginTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class BuildWithParametersPluginTest {

@Test
void doesNotAddAnyParameters() {
def original = spy(new DummyJenkinsfile())
def original = spy(new MockWorkflowScript())
def plugin = new BuildWithParametersPlugin()
def decoration = plugin.addParameterToFirstStageOnly()

Expand All @@ -136,7 +136,7 @@ class BuildWithParametersPluginTest {
class WithParameters {
@Test
void runsTheInnerClosure() {
def original = spy(new DummyJenkinsfile())
def original = spy(new MockWorkflowScript())
def innerClosure = spy { -> }
def plugin = spy(new BuildWithParametersPlugin())
doReturn(true).when(plugin).hasParameters()
Expand All @@ -151,7 +151,7 @@ class BuildWithParametersPluginTest {
@Test
void addsTheParameters() {
def expectedParameters = ['myparams']
def original = spy(new DummyJenkinsfile())
def original = spy(new MockWorkflowScript())
def plugin = spy(new BuildWithParametersPlugin())
doReturn(true).when(plugin).hasParameters()
doReturn(expectedParameters).when(plugin).getBuildParameters()
Expand All @@ -166,7 +166,7 @@ class BuildWithParametersPluginTest {

@Test
void addParametersOnlyOnceAfterMultipleCalls() {
def original = spy(new DummyJenkinsfile())
def original = spy(new MockWorkflowScript())
def plugin = spy(new BuildWithParametersPlugin())
doReturn(true).when(plugin).hasParameters()
doReturn(['myparams']).when(plugin).getBuildParameters()
Expand Down
77 changes: 0 additions & 77 deletions test/DummyJenkinsfile.groovy

This file was deleted.

2 changes: 1 addition & 1 deletion test/GithubPRPlanPluginTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class GithubPRPlanPluginTest {
@Test
void doesNotBlowUp() {
MockJenkinsfile.withParsedScmUrl([protocol: 'git', domain: 'my.github.com'])
Jenkinsfile.original = spy(new DummyJenkinsfile())
Jenkinsfile.original = spy(new MockWorkflowScript())
def plugin = spy(new GithubPRPlanPlugin())
doReturn('HTTP/1.1 201 Created').when(plugin).readFile('comment.headers')
doReturn('{ "id": "someId", "html_url": "some_url" }').when(Jenkinsfile.original).sh(anyObject())
Expand Down
Loading