Skip to content

Commit

Permalink
Make the test status not set by default
Browse files Browse the repository at this point in the history
  • Loading branch information
darmen committed Oct 23, 2023
1 parent 1ca041d commit cd5721e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Breaking changes

### New features & improvements
- Make the test `status` not set by default ([#14](https://github.com/personio/datadog-synthetic-test-support/pull/144))

### Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.datadog.api.client.v1.model.SyntheticsBrowserTestType
import com.datadog.api.client.v1.model.SyntheticsBrowserVariable
import com.datadog.api.client.v1.model.SyntheticsBrowserVariableType
import com.datadog.api.client.v1.model.SyntheticsDeviceID
import com.datadog.api.client.v1.model.SyntheticsTestPauseStatus
import com.datadog.api.client.v1.model.SyntheticsTestRequest
import com.personio.synthetics.client.SyntheticsApiClient
import com.personio.synthetics.config.Defaults
Expand All @@ -31,8 +30,8 @@ class SyntheticBrowserTestBuilder(
* Builds a synthetic browser test
* @return SyntheticsBrowserTest object that contains a browser test
*/
fun build(): SyntheticsBrowserTest =
SyntheticsBrowserTest(
fun build(): SyntheticsBrowserTest {
val test = SyntheticsBrowserTest(
config,
parameters.locations,
parameters.message,
Expand All @@ -41,7 +40,13 @@ class SyntheticBrowserTestBuilder(
SyntheticsBrowserTestType.BROWSER
)
.tags(parameters.tags)
.status(SyntheticsTestPauseStatus.PAUSED)

status?.let {
test.status(it)
}

return test
}

/**
* Sets the base url for the synthetic browser test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class SyntheticMultiStepApiTestBuilder(
* Builds a synthetic API test
* @return SyntheticsAPITest object that contains an API test
*/
fun build(): SyntheticsAPITest =
SyntheticsAPITest(
fun build(): SyntheticsAPITest {
val test = SyntheticsAPITest(
config,
parameters.locations,
parameters.message,
Expand All @@ -35,9 +35,15 @@ class SyntheticMultiStepApiTestBuilder(
SyntheticsAPITestType.API
)
.tags(parameters.tags)
.status(status)
.subtype(SyntheticsTestDetailsSubType.MULTI)

status?.let {
test.status(it)
}

return test
}

/**
* Specifies API steps for a test using a DSL
* @param stepsBuilder A builder to use for building synthetic API steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class SyntheticTestBuilder(
) {
protected var parameters: SyntheticTestParameters
protected var options: SyntheticsTestOptions
protected var status: SyntheticsTestPauseStatus = SyntheticsTestPauseStatus.PAUSED
protected var status: SyntheticsTestPauseStatus? = null

init {
parameters = SyntheticTestParameters(
Expand Down Expand Up @@ -320,6 +320,10 @@ abstract class SyntheticTestBuilder(
tags("team:$teamName")
}

/**
* Sets a synthetic test status
* @param status Synthetic test status
*/
fun status(status: SyntheticsTestPauseStatus) {
this.status = status
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.personio.synthetics.builder

import com.datadog.api.client.v1.model.SyntheticsDeviceID
import com.datadog.api.client.v1.model.SyntheticsTestPauseStatus
import com.personio.synthetics.client.SyntheticsApiClient
import com.personio.synthetics.config.getConfigFromFile
import com.personio.synthetics.model.config.Location
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
Expand Down Expand Up @@ -105,4 +107,18 @@ class SyntheticBrowserTestBuilderTest {
result.options.deviceIds
)
}

@Test
fun `status sets status of a test`() {
testBuilder.status(SyntheticsTestPauseStatus.LIVE)
val result = testBuilder.build()

assertEquals(SyntheticsTestPauseStatus.LIVE, result.status)
}

@Test
fun `build specifies no status by default`() {
val result = testBuilder.build()
assertNull(result.status)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.personio.synthetics.model.config.Location
import com.personio.synthetics.model.config.Timeframe
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -313,17 +314,17 @@ class SyntheticMultiStepApiTestBuilderTest {
assertTrue(result.tags.contains("team:team-two"))
}

@Test
fun `status is set to PAUSED by default`() {
val result = testBuilder.build()
assertEquals(SyntheticsTestPauseStatus.PAUSED, result.status)
}

@Test
fun `status sets status of a test`() {
testBuilder.status(SyntheticsTestPauseStatus.LIVE)
val result = testBuilder.build()

assertEquals(SyntheticsTestPauseStatus.LIVE, result.status)
}

@Test
fun `build specifies no status by default`() {
val result = testBuilder.build()
assertNull(result.status)
}
}

0 comments on commit cd5721e

Please sign in to comment.