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