github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/templates/PiperPipelineStageReleaseTest.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.*
     8  
     9  import static org.hamcrest.Matchers.anyOf
    10  import static org.hamcrest.Matchers.containsString
    11  import static org.hamcrest.Matchers.hasItem
    12  import static org.hamcrest.Matchers.hasItems
    13  import static org.hamcrest.Matchers.hasItems
    14  import static org.hamcrest.Matchers.is
    15  import static org.hamcrest.Matchers.not
    16  import static org.hamcrest.Matchers.not
    17  import static org.junit.Assert.assertThat
    18  
    19  class PiperPipelineStageReleaseTest extends BasePiperTest {
    20      private JenkinsStepRule jsr = new JenkinsStepRule(this)
    21      private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
    22  
    23      @Rule
    24      public RuleChain rules = Rules
    25          .getCommonRules(this)
    26          .around(new JenkinsReadYamlRule(this))
    27          .around(jlr)
    28          .around(jsr)
    29  
    30      private List stepsCalled = []
    31      private Map stepParameters = [:]
    32  
    33      @Before
    34      void init()  {
    35          nullScript.env.STAGE_NAME = 'Release'
    36          helper.registerAllowedMethod('piperStageWrapper', [Map.class, Closure.class], {m, body ->
    37              assertThat(m.stageName, is('Release'))
    38              return body()
    39          })
    40  
    41          helper.registerAllowedMethod('healthExecuteCheck', [Map.class], {m ->
    42              stepsCalled.add('healthExecuteCheck')
    43              stepParameters.healthExecuteCheck = m
    44          })
    45  
    46          helper.registerAllowedMethod('multicloudDeploy', [Map.class], {m ->
    47              stepsCalled.add('multicloudDeploy')
    48              stepParameters.multicloudDeploy = m
    49          })
    50  
    51          helper.registerAllowedMethod('cloudFoundryDeploy', [Map.class], {m ->
    52              stepsCalled.add('cloudFoundryDeploy')
    53              stepParameters.cloudFoundryDeploy = m
    54          })
    55  
    56          helper.registerAllowedMethod('neoDeploy', [Map.class], {m ->
    57              stepsCalled.add('neoDeploy')
    58              stepParameters.neoDeploy = m
    59          })
    60  
    61          helper.registerAllowedMethod('kubernetesDeploy', [Map.class], {m ->
    62              stepsCalled.add('kubernetesDeploy')
    63              stepParameters.kubernetesDeploy = m
    64          })
    65  
    66          helper.registerAllowedMethod('npmExecuteEndToEndTests', [Map.class], {m ->
    67              stepsCalled.add('npmExecuteEndToEndTests')
    68              stepParameters.npmExecuteEndToEndTests = m
    69          })
    70  
    71          helper.registerAllowedMethod('githubPublishRelease', [Map.class], {m ->
    72              stepsCalled.add('githubPublishRelease')
    73              stepParameters.githubPublishRelease = m
    74          })
    75  
    76          helper.registerAllowedMethod('transportRequestUploadCTS', [Map.class], {m ->
    77              stepsCalled.add('transportRequestUploadCTS')
    78              stepParameters.transportRequestUploadCTS = m
    79          })
    80      }
    81  
    82      @Test
    83      void testReleaseStageDefault() {
    84  
    85          jsr.step.piperPipelineStageRelease(
    86              script: nullScript,
    87              juStabUtils: utils
    88          )
    89          assertThat(stepsCalled, not(anyOf(hasItem('cloudFoundryDeploy'), hasItem('neoDeploy'), hasItem('kubernetesDeploy'), hasItem('healthExecuteCheck'), hasItem('githubPublishRelease'), hasItem('transportRequestUploadCTS'))))
    90      }
    91  
    92      @Test
    93      void testReleaseStageMultiCloud() {
    94  
    95          jsr.step.piperPipelineStageRelease(
    96              script: nullScript,
    97              juStabUtils: utils,
    98              multicloudDeploy: true,
    99              healthExecuteCheck: true
   100          )
   101  
   102          assertThat(stepsCalled, hasItems('multicloudDeploy', 'healthExecuteCheck'))
   103      }
   104  
   105      @Test
   106      void testReleaseStageCF() {
   107  
   108          jsr.step.piperPipelineStageRelease(
   109              script: nullScript,
   110              juStabUtils: utils,
   111              cloudFoundryDeploy: true,
   112              healthExecuteCheck: true
   113          )
   114  
   115          assertThat(stepsCalled, hasItems('cloudFoundryDeploy', 'healthExecuteCheck'))
   116      }
   117  
   118      @Test
   119      void testReleaseStageNeo() {
   120  
   121          jsr.step.piperPipelineStageRelease(
   122              script: nullScript,
   123              juStabUtils: utils,
   124              neoDeploy: true
   125          )
   126  
   127          assertThat(stepsCalled, hasItem('neoDeploy'))
   128      }
   129  
   130      @Test
   131      void testReleaseStageKubernetes() {
   132  
   133          jsr.step.piperPipelineStageRelease(
   134              script: nullScript,
   135              juStabUtils: utils,
   136              kubernetesDeploy: true
   137          )
   138  
   139          assertThat(stepsCalled, hasItem('kubernetesDeploy'))
   140      }
   141  
   142      @Test
   143      void testAcceptanceNpmExecuteEndToEndTests() {
   144  
   145          jsr.step.piperPipelineStageRelease(
   146              script: nullScript,
   147              juStabUtils: utils,
   148              npmExecuteEndToEndTests: true
   149          )
   150  
   151          assertThat(stepsCalled, hasItem('npmExecuteEndToEndTests'))
   152          assertThat(stepParameters.npmExecuteEndToEndTests.runScript, is('ci-smoke'))
   153      }
   154  
   155      @Test
   156      void testReleaseStageGitHub() {
   157  
   158          jsr.step.piperPipelineStageRelease(
   159              script: nullScript,
   160              juStabUtils: utils,
   161              githubPublishRelease: true
   162          )
   163  
   164          assertThat(stepsCalled, hasItem('githubPublishRelease'))
   165      }
   166  
   167      @Test
   168      void testReleaseStageTransportRequestUploadCTS() {
   169  
   170          jsr.step.piperPipelineStageRelease(
   171              script: nullScript,
   172              juStabUtils: utils,
   173              transportRequestUploadCTS: true
   174          )
   175  
   176          assertThat(stepsCalled, hasItem('transportRequestUploadCTS'))
   177      }
   178  
   179      @Test
   180      void testReleaseStageTransportRequestUploadCTSWhenSetToFalse() {
   181  
   182          jsr.step.piperPipelineStageRelease(
   183              script: nullScript,
   184              juStabUtils: utils,
   185              transportRequestUploadCTS: false
   186          )
   187  
   188          assertThat(stepsCalled, not(hasItem('transportRequestUploadCTS')))
   189      }
   190  }