github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/templates/PiperPipelineStagePromoteTest.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.hasItem
    11  import static org.hamcrest.Matchers.is
    12  import static org.hamcrest.Matchers.not
    13  import static org.junit.Assert.assertThat
    14  
    15  class PiperPipelineStagePromoteTest extends BasePiperTest {
    16      private JenkinsStepRule jsr = new JenkinsStepRule(this)
    17      private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
    18  
    19      @Rule
    20      public RuleChain rules = Rules
    21          .getCommonRules(this)
    22          .around(new JenkinsReadYamlRule(this))
    23          .around(jlr)
    24          .around(jsr)
    25  
    26      private List stepsCalled = []
    27      private Map stepParameters = [:]
    28  
    29      @Before
    30      void init()  {
    31          nullScript.env.STAGE_NAME = 'Promote'
    32          helper.registerAllowedMethod('piperStageWrapper', [Map.class, Closure.class], {m, body ->
    33              assertThat(m.stageName, is('Promote'))
    34  
    35              return body()
    36          })
    37  
    38          helper.registerAllowedMethod('containerPushToRegistry', [Map.class], {m ->
    39              stepsCalled.add('containerPushToRegistry')
    40              stepParameters.containerPushToRegistry = m
    41          })
    42  
    43          helper.registerAllowedMethod('nexusUpload', [Map.class], {m ->
    44              stepsCalled.add('nexusUpload')
    45              stepParameters.nexusUpload = m
    46          })
    47      }
    48  
    49      @Test
    50      void testStagePromoteDefault() {
    51  
    52          jsr.step.piperPipelineStagePromote(
    53              script: nullScript,
    54              juStabUtils: utils,
    55          )
    56          assertThat(stepsCalled, not(anyOf(hasItem('containerPushToRegistry'), hasItem('nexusUpload'))))
    57  
    58      }
    59  
    60      @Test
    61      void testStagePromotePushToRegistry() {
    62  
    63          jsr.step.piperPipelineStagePromote(
    64              script: nullScript,
    65              juStabUtils: utils,
    66              containerPushToRegistry: true
    67          )
    68  
    69          assertThat(stepsCalled, hasItem('containerPushToRegistry'))
    70      }
    71  
    72      @Test
    73      void testStagePromoteNexusUpload() {
    74  
    75          jsr.step.piperPipelineStagePromote(
    76              script: nullScript,
    77              juStabUtils: utils,
    78              nexusUpload: true
    79          )
    80  
    81          assertThat(stepsCalled, hasItem('nexusUpload'))
    82      }
    83  }