-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into add-mr-links-to-changelog
- Loading branch information
Showing
9 changed files
with
193 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/kotlin/com/personio/synthetics/builder/SyntheticBrowserTestBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.personio.synthetics.builder | ||
|
||
import com.datadog.api.client.v1.model.SyntheticsBrowserTest | ||
import com.datadog.api.client.v1.model.SyntheticsBrowserTestConfig | ||
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.SyntheticsTestPauseStatus | ||
import com.datadog.api.client.v1.model.SyntheticsTestRequest | ||
import com.personio.synthetics.client.SyntheticsApiClient | ||
import com.personio.synthetics.config.Defaults | ||
import java.net.URL | ||
|
||
/** | ||
* A builder for creating SyntheticsBrowserTest instances | ||
*/ | ||
class SyntheticBrowserTestBuilder( | ||
override val name: String, | ||
defaults: Defaults, | ||
apiClient: SyntheticsApiClient | ||
) : SyntheticTestBuilder(name, defaults, apiClient) { | ||
private val config = SyntheticsBrowserTestConfig() | ||
|
||
/** | ||
* Builds a synthetic browser test | ||
* @return SyntheticsBrowserTest object that contains a browser test | ||
*/ | ||
fun build(): SyntheticsBrowserTest = | ||
SyntheticsBrowserTest( | ||
config, | ||
parameters.locations, | ||
parameters.message, | ||
name, | ||
options, | ||
SyntheticsBrowserTestType.BROWSER | ||
) | ||
.tags(parameters.tags) | ||
.status(SyntheticsTestPauseStatus.PAUSED) | ||
|
||
/** | ||
* Sets the base url for the synthetic browser test | ||
* @param url The base url for the test | ||
*/ | ||
fun baseUrl(url: URL) { | ||
config.request( | ||
SyntheticsTestRequest() | ||
.method("GET") | ||
.url(url.toString()) | ||
) | ||
} | ||
|
||
override fun addLocalVariable(name: String, pattern: String) { | ||
config.addVariablesItem( | ||
SyntheticsBrowserVariable() | ||
.name(name.uppercase()) | ||
.type(SyntheticsBrowserVariableType.TEXT) | ||
.pattern(pattern) | ||
.example("") | ||
) | ||
} | ||
|
||
override fun useGlobalVariable(name: String) { | ||
val variableName = name.uppercase() | ||
val variableId = getGlobalVariableId(variableName) | ||
checkNotNull(variableId) { "The global variable $name to be used in the test doesn't exist in DataDog." } | ||
config.addVariablesItem( | ||
SyntheticsBrowserVariable() | ||
.name(variableName) | ||
.id(variableId) | ||
.type(SyntheticsBrowserVariableType.GLOBAL) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/test/kotlin/com/personio/synthetics/e2e/E2EBrowserTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.personio.synthetics.e2e | ||
|
||
import com.personio.synthetics.dsl.syntheticBrowserTest | ||
import com.personio.synthetics.model.config.Location | ||
import com.personio.synthetics.model.config.MonitorPriority | ||
import com.personio.synthetics.model.config.RenotifyInterval | ||
import com.personio.synthetics.model.config.Timeframe | ||
import org.junit.jupiter.api.Test | ||
import java.net.URL | ||
import java.time.DayOfWeek | ||
import java.time.LocalTime | ||
import java.time.ZoneId | ||
import kotlin.time.Duration.Companion.days | ||
import kotlin.time.Duration.Companion.milliseconds | ||
import kotlin.time.Duration.Companion.minutes | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
class E2EBrowserTest { | ||
@Test | ||
fun `create synthetic browser test`() { | ||
syntheticBrowserTest("[Browser] Synthetic-Test-As-Code") { | ||
alertMessage("Test Failed", "@slack-test_slack_channel") | ||
recoveryMessage("Test recovered") | ||
env("qa") | ||
tags("synthetics-api") | ||
baseUrl(URL("https://synthetic-test.personio.de")) | ||
publicLocations(Location.IRELAND_AWS, Location.N_CALIFORNIA_AWS, Location.MUMBAI_AWS) | ||
testFrequency(6.minutes) | ||
advancedScheduling( | ||
Timeframe( | ||
from = LocalTime.of(0, 1), | ||
to = LocalTime.of(23, 59), | ||
DayOfWeek.MONDAY, | ||
DayOfWeek.TUESDAY, | ||
DayOfWeek.FRIDAY | ||
), | ||
timezone = ZoneId.of("Europe/Dublin") | ||
) | ||
retry(2, 600.milliseconds) | ||
minFailureDuration(120.minutes) | ||
minLocationFailed(2) | ||
monitorName("Monitor for [Browser] Synthetic-Test-As-Code") | ||
renotifyInterval(RenotifyInterval.HOURS_2) | ||
monitorPriority(MonitorPriority.P3_MEDIUM) | ||
useGlobalVariable("TEST_PASSWORD") | ||
textVariable("TEXT_VARIABLE", "test") | ||
numericPatternVariable( | ||
name = "NUMERIC_PATTERN", | ||
characterLength = 4, | ||
prefix = "test" | ||
) | ||
alphabeticPatternVariable("ALPHABETIC_PATTERN", 5) | ||
alphanumericPatternVariable("ALPHANUMERIC_PATTERN", 6) | ||
datePatternVariable( | ||
name = "DATE_PATTERN", | ||
duration = (-1).days, | ||
format = "MM-DD-YYYY" | ||
) | ||
timestampPatternVariable( | ||
name = "TIMESTAMP_PATTERN", | ||
duration = 10.seconds | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters