Skip to content

Commit

Permalink
Add "env" and "team" functions to SyntheticTestBuilder (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
darmen authored Sep 29, 2023
1 parent 3dee127 commit 2cdab48
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 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
- Add handy `env()` and `team()` functions for adding corresponding Datadog `key:value` tags

### Bug fixes

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ Start using the library in a gradle project by following the steps below:
```kotlin
fun `add a multi-step API synthetic test`() {
syntheticMultiStepApiTest("Test Login to the app") {
tags("env:qa")
baseUrl(URL("https://synthetic-test.personio.de"))
env("qa")
team("team-one")
publicLocations(Location.FRANKFURT_AWS)
testFrequency(5.minutes)
retry(1, 600.milliseconds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ abstract class SyntheticTestBuilder(
}

/**
* Sets the tags for the synthetic test
* Adds the tags for the synthetic test
* @param tags List of tags
*/
fun tags(vararg tags: String) {
Expand Down Expand Up @@ -279,6 +279,22 @@ abstract class SyntheticTestBuilder(
addLocalVariable(name, "{{ uuid }}")
}

/**
* Adds "env:<envName>" tag
* @param envName Environment name. Examples: prod, stage, dev.
*/
fun env(envName: String) {
tags("env:$envName")
}

/**
* Adds "team:<teamName>" tag
* @param teamName Team name
*/
fun team(teamName: String) {
tags("team:$teamName")
}

private fun getScaledDate(value: Duration): Pair<Long, String>? =
value.getScaledValue(
sequenceOf(DurationUnit.MILLISECONDS, DurationUnit.SECONDS, DurationUnit.MINUTES, DurationUnit.HOURS, DurationUnit.DAYS),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,26 @@ class SyntheticMultiStepApiTestBuilderTest {
result.config.steps.count()
)
}

@Test
fun `env adds env tag`() {
sut.env("env1")
sut.env("env2")

val result = sut.build()

assertTrue(result.tags.contains("env:env1"))
assertTrue(result.tags.contains("env:env2"))
}

@Test
fun `team adds team tag`() {
sut.team("team-one")
sut.team("team-two")

val result = sut.build()

assertTrue(result.tags.contains("team:team-one"))
assertTrue(result.tags.contains("team:team-two"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class E2EMultiStepApiTest {
syntheticMultiStepApiTest("[Multi-Step] Synthetic-Test-As-Code") {
alertMessage("Test failed", "@slack-test_slack_channel")
recoveryMessage("Test recovered")
tags("env:qa")
env("qa")
publicLocations(Location.IRELAND_AWS, Location.N_CALIFORNIA_AWS, Location.MUMBAI_AWS)
testFrequency(1.minutes)
advancedScheduling(
Expand Down

0 comments on commit 2cdab48

Please sign in to comment.