forked from jenkinsci/JenkinsPipelineUnit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(declarative) withCredentails usernamePassword mocking conflict
- Loading branch information
Showing
5 changed files
with
101 additions
and
4 deletions.
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
43 changes: 43 additions & 0 deletions
43
src/test/groovy/com/lesfurets/jenkins/unit/declarative/TestDeclaraticeWithCredentials.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,43 @@ | ||
package com.lesfurets.jenkins.unit.declarative | ||
|
||
import com.lesfurets.jenkins.unit.declarative.DeclarativePipelineTest | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
import static org.junit.Assert.assertTrue | ||
|
||
class TestDeclaraticeWithCredentials extends DeclarativePipelineTest { | ||
|
||
@Override | ||
@Before | ||
void setUp() throws Exception { | ||
scriptRoots += 'src/test/jenkins/jenkinsfiles' | ||
scriptExtension = '' | ||
super.setUp() | ||
} | ||
|
||
@Test | ||
void should_run_script_with_credentials() { | ||
// when: | ||
runScript("withCredentials_Jenkinsfile") | ||
|
||
// then: | ||
assertJobStatusSuccess() | ||
assertCallStack().contains("echo(User/Pass = user/pass)") | ||
assertCallStack().contains("echo(Nested User/Pass = user/pass)") | ||
assertCallStack().contains("echo(Restored User/Pass = user/pass)") | ||
assertCallStack().contains("echo(Cleared User/Pass = null/null)") | ||
|
||
assertCallStack().contains("echo(Docker = docker_pass)") | ||
assertCallStack().contains("echo(Nested Docker = docker_pass)") | ||
assertCallStack().contains("echo(Restored Docker = docker_pass)") | ||
assertCallStack().contains("echo(Cleared Docker = null)") | ||
|
||
assertCallStack().contains("echo(SSH = ssh_pass)") | ||
assertCallStack().contains("echo(Nested SSH = ssh_pass)") | ||
assertCallStack().contains("echo(Restored SSH = ssh_pass)") | ||
assertCallStack().contains("echo(Cleared SSH = null)") | ||
|
||
|
||
} | ||
} |
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
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
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,40 @@ | ||
|
||
pipeline { | ||
agent any | ||
stages { | ||
stage("run") { | ||
withCredentials([ | ||
usernamePassword( credentialsId: 'my_cred_id', usernameVariable: 'user', passwordVariable: 'pass' ), | ||
string( credentialsId: 'docker_cred', variable: 'docker_pass' ), | ||
string( credentialsId: 'ssh_cred', variable: 'ssh_pass' ) | ||
]) { | ||
// Ensure values are set on entry | ||
echo "User/Pass = $user/$pass" | ||
echo "Docker = $docker_pass" | ||
echo "SSH = $ssh_pass" | ||
|
||
withCredentials([ | ||
usernamePassword( credentialsId: 'my_cred_id', usernameVariable: 'user', passwordVariable: 'pass' ), | ||
string( credentialsId: 'docker_cred', variable: 'docker_pass' ), | ||
string( credentialsId: 'ssh_cred', variable: 'ssh_pass' ) | ||
]) { | ||
// Ensure nested values are in place | ||
echo "Nested User/Pass = $user/$pass" | ||
echo "Nested Docker = $docker_pass" | ||
echo "Nested SSH = $ssh_pass" | ||
} | ||
|
||
// Ensure original values are restored | ||
echo "Restored User/Pass = $user/$pass" | ||
echo "Restored Docker = $docker_pass" | ||
echo "Restored SSH = $ssh_pass" | ||
} | ||
|
||
// Ensure original state where the values are not set | ||
echo "Cleared User/Pass = $user/$pass" | ||
echo "Cleared Docker = $docker_pass" | ||
echo "Cleared SSH = $ssh_pass" | ||
} | ||
} | ||
} | ||
|