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

     1  import org.junit.After
     2  import org.junit.Before
     3  import org.junit.Rule
     4  import org.junit.Test
     5  import org.junit.rules.RuleChain
     6  import util.*
     7  
     8  import com.sap.piper.Utils
     9  
    10  import static org.hamcrest.Matchers.containsString
    11  import static org.junit.Assert.*
    12  
    13  class PipelineStashFilesBeforeBuildTest extends BasePiperTest {
    14      JenkinsStepRule stepRule = new JenkinsStepRule(this)
    15      JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
    16      JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this)
    17      //JenkinsReadJsonRule readJsonRule = new JenkinsReadJsonRule(this)
    18  
    19      @Before
    20      public void setup() {
    21          Utils.metaClass.echo = { def m -> }
    22      }
    23  
    24      @After
    25      public void tearDown() {
    26          Utils.metaClass = null
    27      }
    28  
    29      @Rule
    30      public RuleChain rules = Rules
    31          .getCommonRules(this)
    32          .around(new JenkinsReadYamlRule(this))
    33          //.around(readJsonRule)
    34          .around(loggingRule)
    35          .around(shellRule)
    36          .around(stepRule)
    37  
    38      @Test
    39      void testStashBeforeBuild() {
    40  
    41          stepRule.step.pipelineStashFilesBeforeBuild(script: nullScript, juStabUtils: utils, runOpaTests: true)
    42  
    43          // asserts
    44          assertThat(loggingRule.log, containsString('Stash content: buildDescriptor'))
    45          assertThat(loggingRule.log, containsString('Stash content: deployDescriptor'))
    46          assertThat(loggingRule.log, containsString('Stash content: git'))
    47          assertThat(loggingRule.log, containsString('Stash content: opensourceConfiguration'))
    48          assertThat(loggingRule.log, containsString('Stash content: pipelineConfigAndTests'))
    49          assertThat(loggingRule.log, containsString('Stash content: securityDescriptor'))
    50          assertThat(loggingRule.log, containsString('Stash content: tests'))
    51      }
    52  
    53      @Test
    54      void testStashBeforeBuildCustomConfig() {
    55  
    56          stepRule.step.pipelineStashFilesBeforeBuild(script: nullScript, juStabUtils: utils, runOpaTests: true, stashIncludes: ['myStash': '**.myTest'])
    57  
    58          // asserts
    59          assertThat(loggingRule.log, containsString('Stash content: buildDescriptor'))
    60          assertThat(loggingRule.log, containsString('Stash content: deployDescriptor'))
    61          assertThat(loggingRule.log, containsString('Stash content: git'))
    62          assertThat(loggingRule.log, containsString('Stash content: opensourceConfiguration'))
    63          assertThat(loggingRule.log, containsString('Stash content: pipelineConfigAndTests'))
    64          assertThat(loggingRule.log, containsString('Stash content: securityDescriptor'))
    65          assertThat(loggingRule.log, containsString('Stash content: tests'))
    66          assertThat(loggingRule.log, containsString('Stash content: myStash'))
    67      }
    68  }