github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/CnbBuildTest.groovy (about)

     1  import org.junit.Rule
     2  import org.junit.Test
     3  import org.junit.rules.RuleChain
     4  
     5  import util.BasePiperTest
     6  import util.JenkinsReadYamlRule
     7  import util.JenkinsStepRule
     8  import util.Rules
     9  
    10  import static org.junit.Assert.assertThat
    11  import static org.junit.Assert.assertTrue
    12  import static org.hamcrest.Matchers.is
    13  import static org.hamcrest.Matchers.hasEntry
    14  import static org.hamcrest.Matchers.allOf
    15  
    16  public class CnbBuildTest extends BasePiperTest {
    17  
    18      private JenkinsStepRule stepRule = new JenkinsStepRule(this)
    19      private JenkinsReadYamlRule readYamlRule = new JenkinsReadYamlRule(this)
    20  
    21      @Rule
    22      public RuleChain ruleChain = Rules
    23          .getCommonRules(this)
    24          .around(stepRule)
    25          .around(readYamlRule)
    26  
    27      @Test
    28      void testCallGoWrapper() {
    29  
    30          def calledWithParameters,
    31              calledWithStepName,
    32              calledWithMetadata,
    33              calledWithCredentials,
    34              calledWithFailOnError
    35  
    36          helper.registerAllowedMethod(
    37              'piperExecuteBin',
    38              [Map, String, String, List, Boolean, Boolean, Boolean],
    39              {
    40                  params, stepName, metaData, creds, failOnMissingReports, failOnMissingLinks, failOnError  ->
    41                  calledWithParameters = params
    42                  calledWithStepName = stepName
    43                  calledWithMetadata = metaData
    44                  calledWithCredentials = creds
    45                  calledWithFailOnError = failOnError
    46              }
    47          )
    48  
    49          stepRule.step.cnbBuild(
    50              script: nullScript,
    51              buildpacks: ['test1', 'test2'],
    52              containerImageName: 'foo',
    53              containerImageTag: 'bar',
    54              containerRegistryUrl: 'test',
    55              dockerConfigJsonCredentialsId: 'DOCKER_CREDENTIALS',
    56              buildEnvVars: ['foo=bar', 'bar=baz']
    57          )
    58  
    59          assertThat(calledWithParameters.size(), is(7))
    60          assertThat(calledWithParameters.script, is(nullScript))
    61          assertThat(calledWithParameters.buildpacks, is(['test1', 'test2']))
    62          assertThat(calledWithParameters.containerImageName, is('foo'))
    63          assertThat(calledWithParameters.containerImageTag, is('bar'))
    64          assertThat(calledWithParameters.containerRegistryUrl, is('test'))
    65          assertThat(calledWithParameters.dockerConfigJsonCredentialsId, is('DOCKER_CREDENTIALS'))
    66          assertThat(calledWithParameters.buildEnvVars, is(['foo=bar', 'bar=baz']))
    67  
    68          assertThat(calledWithStepName, is('cnbBuild'))
    69          assertThat(calledWithMetadata, is('metadata/cnbBuild.yaml'))
    70  
    71          assertThat(calledWithCredentials.size(), is(1))
    72          assertThat(calledWithCredentials[0].size(), is(3))
    73          assertThat(calledWithCredentials[0], allOf(hasEntry('type','file'), hasEntry('id','dockerConfigJsonCredentialsId'), hasEntry('env',['PIPER_dockerConfigJSON'])))
    74  
    75          assertTrue(calledWithFailOnError)
    76  
    77      }
    78  }