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

     1  import com.sap.piper.analytics.InfluxData
     2  
     3  import org.junit.Rule
     4  import org.junit.Test
     5  import util.BasePiperTest
     6  
     7  import static org.hamcrest.Matchers.hasKey
     8  import static org.hamcrest.Matchers.is
     9  import static org.hamcrest.Matchers.not
    10  
    11  import static org.junit.Assert.assertThat
    12  import org.junit.rules.RuleChain
    13  
    14  import util.Rules
    15  import util.JenkinsReadYamlRule
    16  import util.JenkinsStepRule
    17  
    18  
    19  class DurationMeasureTest extends BasePiperTest {
    20      private JenkinsStepRule stepRule = new JenkinsStepRule(this)
    21  
    22      @Rule
    23      public RuleChain rules = Rules
    24          .getCommonRules(this)
    25          .around(new JenkinsReadYamlRule(this))
    26          .around(stepRule)
    27  
    28      @Test
    29      void testDurationMeasurement() throws Exception {
    30          def bodyExecuted = false
    31          stepRule.step.durationMeasure(script: nullScript, measurementName: 'test') {
    32              bodyExecuted = true
    33          }
    34          // doesnt work
    35          //assertThat(InfluxData.getInstance().getFields(), hasEntry('pipeline_data', hasEntry('test', is(anything()))))
    36          assertThat(InfluxData.getInstance().getFields(), hasKey('pipeline_data'))
    37          assertThat(InfluxData.getInstance().getFields().pipeline_data, hasKey('test'))
    38          assertThat(InfluxData.getInstance().getFields().pipeline_data.test, is(not(null)))
    39          assertThat(bodyExecuted, is(true))
    40          assertJobStatusSuccess()
    41      }
    42  }