-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: mock existing local function.
The mock was not applicable in case the function already exists and the specified closure is null.
- Loading branch information
Nestor Acuna-Blanco
committed
Jan 7, 2022
1 parent
640a2a9
commit bb1a3e4
Showing
3 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/test/groovy/com/lesfurets/jenkins/unit/declarative/TestMockLocalFunction.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.lesfurets.jenkins.unit.declarative | ||
|
||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class TestMockLocalFunction extends DeclarativePipelineTest { | ||
|
||
@Before | ||
@Override | ||
void setUp() throws Exception { | ||
scriptRoots += 'src/test/jenkins/jenkinsfiles' | ||
helper.registerAllowedMethod("githubNotify", [Map]) | ||
super.setUp() | ||
} | ||
|
||
@Test(expected=MissingMethodException.class) | ||
void should_execute_with_errors() { | ||
runScript("Mock_existing_function_Jenkinsfile") | ||
} | ||
|
||
@Test | ||
void should_execute_without_errors() { | ||
helper.registerAllowedMethod("runFunc") | ||
runScript("Mock_existing_function_Jenkinsfile") | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/test/jenkins/jenkinsfiles/Mock_existing_function_Jenkinsfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
pipeline { | ||
agent { node { label 'test1' } } | ||
stages { | ||
stage('sdfsdf') { | ||
steps { | ||
githubNotify status: 'PENDING', context: 'Pipeline' | ||
runFunc() | ||
} | ||
} | ||
} | ||
} | ||
|
||
def runFunc(){ | ||
echo "inside runFunc" | ||
doSomeStuff() | ||
} |