Skip to content

Commit

Permalink
adds raw body extraction method for API tests (#238)
Browse files Browse the repository at this point in the history
* adds raw body extraction method for API tests

* adds PR link to changelog

* adds body extraction
  • Loading branch information
rishiranjjan authored Sep 6, 2024
1 parent 6789681 commit 2972f00
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 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 `bodyRaw()` extraction function for API Tests to extract entire response body ([#238](https://github.com/personio/datadog-synthetic-test-support/pull/238))

### Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ class ParsingOptionsBuilder {
.secure(secure)
}

/**
* Extracts the entire response body
* @param secure set to true to disallow the extracted value to be read from DataDog UI
* By default secure is set to false allowing the extracted value to be available for reading in Datadog UI
*/
fun bodyRaw(secure: Boolean = false) {
parsingOptions =
SyntheticsParsingOptions()
.parser(
SyntheticsVariableParser()
.type(SyntheticsGlobalVariableParserType.RAW),
)
.type(SyntheticsGlobalVariableParseTestOptionsType.HTTP_BODY)
.secure(secure)
}

/**
* Extracts the value from a response header
* @param name Header name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ class ParsingOptionsBuilderTest {
)
}

@ParameterizedTest
@ValueSource(booleans = [true, false])
fun `bodyRaw returns parsing options with RAW parser type and HTTP_BODY type`(secure: Boolean) {
parsingOptionsBuilder.variable(TEST_STEP_NAME)
parsingOptionsBuilder.bodyRaw(secure)

assertEquals(
SyntheticsParsingOptions()
.name(TEST_STEP_NAME)
.parser(
SyntheticsVariableParser()
.type(SyntheticsGlobalVariableParserType.RAW),
)
.type(SyntheticsGlobalVariableParseTestOptionsType.HTTP_BODY)
.secure(secure),
parsingOptionsBuilder.build(),
)
}

@ParameterizedTest
@ValueSource(booleans = [true, false])
fun `header returns parsing options with RAW parser type and HTTP_HEADER type`(secure: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class E2EMultiStepApiTest {
extract("COOKIE_VARIABLE") {
headerRegex("set-cookie", "(?<=cookie_name\\=)[^;]+(?=;)")
}
extract("RAW_RESPONSE_BODY") {
bodyRaw()
}
}
}
}
Expand Down

0 comments on commit 2972f00

Please sign in to comment.