I'm trying to test a function in my Jenkins Script Pipeline.
void doSomeDockerThings(){
withCredentials([[$class: 'UsernamePasswordMultiBinding', creditialsId: 'my_creds', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
sh "docker login -u $USERNAME -p '$PASSWORD' $DTR"
}
}
From a Groovy Unit Test that extends BasePipelineTest, I have the following test method.
@Test
void testDoSomeDockerThings(){
helper.registerAllowedMethod( "withCredentials", [LinkedHasMap.class, Closure.class], null );
helper.registerAllowedMethod( "sh", [String.class], {c -> return c; })
binding.setVariable( "USERNAME", "user" );
binding.setVariable( "PASSWORD", "password" );
binding.setVariable( "DTR", "Docker_Trusted_Registry" );
}
What I want to do is now write an assert that this command executed with what I expected. Since that is in a Closer of withCredentials how can I verify this?
sh "docker login -u $USERNAME -p '$PASSWORD' $DTR"
I've also tried using the withCredentialsInterceptor and I can't seem to get the syntax right for what it expects. If anyone has an example of that I would appreciate it.
helper.registerAllowedMethod( "withCredentials", [LinkedHasMap.class, Closure.class], withCredentialsInterceptor );
I'm really struggling to find documentation or examples are how to do this.