Skip to content

Commit

Permalink
Add missing integration test for Logs
Browse files Browse the repository at this point in the history
  • Loading branch information
xgouchet committed Oct 18, 2024
1 parent c3e7cb7 commit 7e0cdce
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,34 @@ class LoggerTest {
assertThat(event0.getString(fakeAttributeKey)).isEqualTo(fakeAttributeValue2)
}

@RepeatedTest(16)
fun `M send log without attribute W Logs#addAttribute() + Logs#removeAttribute() + Logger#log()`(
@StringForgery fakeAttributeKey: String,
@StringForgery fakeAttributeValue: String,
@StringForgery fakeMessage: String,
@IntForgery(Log.VERBOSE, 10) fakeLevel: Int
) {
// Given
val testedLogger = Logger.Builder(stubSdkCore).build()

// When
Logs.addAttribute(fakeAttributeKey, fakeAttributeValue, stubSdkCore)
Logs.removeAttribute(fakeAttributeKey, stubSdkCore)
testedLogger.log(fakeLevel, fakeMessage)

// Then
val eventsWritten = stubSdkCore.eventsWritten(Feature.LOGS_FEATURE_NAME)
assertThat(eventsWritten).hasSize(1)
val event0 = JsonParser.parseString(eventsWritten[0].eventData) as JsonObject
assertThat(event0.getString("ddtags")).contains("env:" + stubSdkCore.getDatadogContext().env)
assertThat(event0.getString("ddtags")).contains("version:" + stubSdkCore.getDatadogContext().version)
assertThat(event0.getString("ddtags")).contains("variant:" + stubSdkCore.getDatadogContext().variant)
assertThat(event0.getString("service")).isEqualTo(stubSdkCore.getDatadogContext().service)
assertThat(event0.getString("message")).isEqualTo(fakeMessage)
assertThat(event0.getString("status")).isEqualTo(LEVEL_NAMES[fakeLevel])
assertThat(event0.getString(fakeAttributeKey)).isNull()
}

@RepeatedTest(16)
fun `M send log with overridden custom attribute W Logs#addAttribute() + Logger#addAttribute() + Logger#log()`(
@StringForgery fakeAttributeKey: String,
Expand Down Expand Up @@ -920,7 +948,7 @@ class LoggerTest {
}

@RepeatedTest(16)
fun `M send log with updated custom attribute W Logger#addAttribute() + Logger#removeAttribute() + Logger#log()`(
fun `M send log without attribute W Logger#addAttribute() + Logger#removeAttribute() + Logger#log()`(
@StringForgery fakeAttributeKey: String,
@StringForgery fakeAttributeValue: String,
@StringForgery fakeMessage: String,
Expand Down

0 comments on commit 7e0cdce

Please sign in to comment.