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

     1  package templates
     2  
     3  import org.junit.Before
     4  import org.junit.Rule
     5  import org.junit.Test
     6  import org.junit.rules.RuleChain
     7  import util.BasePiperTest
     8  import util.JenkinsReadYamlRule
     9  import util.JenkinsStepRule
    10  import util.PipelineWhenException
    11  import util.Rules
    12  
    13  import static org.hamcrest.Matchers.*
    14  import static org.junit.Assert.assertThat
    15  
    16  class AbapEnvironmentPipelineStageCloneRepositoriesTest extends BasePiperTest {
    17      private JenkinsStepRule jsr = new JenkinsStepRule(this)
    18  
    19      @Rule
    20      public RuleChain rules = Rules
    21          .getCommonRules(this)
    22          .around(new JenkinsReadYamlRule(this))
    23          .around(jsr)
    24  
    25      private stepsCalled = []
    26      @Before
    27      void init()  {
    28          binding.variables.env.STAGE_NAME = 'Clone Repositories'
    29  
    30          helper.registerAllowedMethod('piperStageWrapper', [Map.class, Closure.class], {m, body ->
    31              assertThat(m.stageName, is('Clone Repositories'))
    32              return body()
    33          })
    34          helper.registerAllowedMethod('strategy', [Map], {m ->
    35              stepsCalled.add('strategy')
    36          })
    37          helper.registerAllowedMethod('cloudFoundryCreateServiceKey', [Map.class], {m -> stepsCalled.add('cloudFoundryCreateServiceKey')})
    38          helper.registerAllowedMethod('abapEnvironmentPullGitRepo', [Map.class], {m -> stepsCalled.add('abapEnvironmentPullGitRepo')})
    39          helper.registerAllowedMethod('abapEnvironmentCheckoutBranch', [Map.class], {m -> stepsCalled.add('abapEnvironmentCheckoutBranch')})
    40          helper.registerAllowedMethod('abapEnvironmentCloneGitRepo', [Map.class], {m -> stepsCalled.add('abapEnvironmentCloneGitRepo')})
    41          // assertThat(stepsCalled, hasItem('cloudFoundryCreateServiceKey'))
    42      }
    43  
    44      @Test
    45      void testAbapEnvironmentPipelineStageCloneRepositoriesPull() {
    46  
    47          nullScript.commonPipelineEnvironment.configuration.runStage = []
    48          jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript, strategy: 'Pull',  host: 'abc.com')
    49  
    50          assertThat(stepsCalled, hasItems('abapEnvironmentPullGitRepo'))
    51          assertThat(stepsCalled, not(hasItem('cloudFoundryCreateServiceKey')))
    52          assertThat(stepsCalled, not(hasItems('abapEnvironmentCloneGitRepo')))
    53          assertThat(stepsCalled, not(hasItems('abapEnvironmentCheckoutBranch')))
    54      }
    55  
    56      @Test
    57      void testAbapEnvironmentPipelineStageCloneRepositoriesClone() {
    58  
    59          nullScript.commonPipelineEnvironment.configuration.runStage = []
    60          jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript, strategy: 'Clone')
    61  
    62          assertThat(stepsCalled, hasItems('abapEnvironmentCloneGitRepo', 'cloudFoundryCreateServiceKey'))
    63          assertThat(stepsCalled, not(hasItems('abapEnvironmentPullGitRepo', 'abapEnvironmentCheckoutBranch')))
    64      }
    65  
    66      @Test
    67      void testAbapEnvironmentPipelineStageCloneRepositoriesCheckoutPull() {
    68  
    69          nullScript.commonPipelineEnvironment.configuration.runStage = []
    70          jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript, strategy: 'CheckoutPull')
    71  
    72          assertThat(stepsCalled, hasItems('abapEnvironmentPullGitRepo', 'abapEnvironmentCheckoutBranch', 'cloudFoundryCreateServiceKey'))
    73          assertThat(stepsCalled, not(hasItems('abapEnvironmentCloneGitRepo')))
    74      }
    75  
    76      @Test
    77      void testAbapEnvironmentPipelineStageCloneRepositoriesPullCheckoutPull() {
    78  
    79          nullScript.commonPipelineEnvironment.configuration.runStage = []
    80          jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript, strategy: 'AddonBuild', host: 'abc.com')
    81  
    82          assertThat(stepsCalled, not(hasItems('abapEnvironmentPullGitRepo', 'abapEnvironmentCheckoutBranch', 'cloudFoundryCreateServiceKey')))
    83          assertThat(stepsCalled, hasItems('abapEnvironmentCloneGitRepo'))
    84      }
    85  
    86      @Test
    87      void testAbapEnvironmentPipelineStageCloneRepositoriesNoStrategy() {
    88  
    89          nullScript.commonPipelineEnvironment.configuration.runStage = []
    90          jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript, host: 'abc.com')
    91  
    92          assertThat(stepsCalled, hasItems('abapEnvironmentPullGitRepo'))
    93          assertThat(stepsCalled, not(hasItems('abapEnvironmentCloneGitRepo', 'abapEnvironmentCheckoutBranch', 'cloudFoundryCreateServiceKey')))
    94      }
    95  }