Skip to content

Commit

Permalink
Explicitly check for key for attribute assertions using hasEntrySatis… (
Browse files Browse the repository at this point in the history
#3703)

* Explicitly check for key for attribute assertions using hasEntrySatisfying

* Check test user agent set first
  • Loading branch information
Anuraag Agrawal authored Jul 28, 2021
1 parent 4617a04 commit e4fcbb8
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -997,13 +997,21 @@ SpanDataAssert assertClientSpan(
if (httpClientAttributes.contains(SemanticAttributes.HTTP_USER_AGENT)) {
String userAgent = userAgent();
if (userAgent != null) {
// TODO(anuraaga): Remove after updating to SDK 1.5.0 which adds this into
// hasEntrySatisfying.
// https://github.com/open-telemetry/opentelemetry-java/pull/3433
assertThat(attrs.asMap()).containsKey(SemanticAttributes.HTTP_USER_AGENT);
assertThat(attrs)
.hasEntrySatisfying(
SemanticAttributes.HTTP_USER_AGENT,
actual -> assertThat(actual).startsWith(userAgent));
}
}
if (httpClientAttributes.contains(SemanticAttributes.HTTP_HOST)) {
// TODO(anuraaga): Remove after updating to SDK 1.5.0 which adds this into
// hasEntrySatisfying.
// https://github.com/open-telemetry/opentelemetry-java/pull/3433
assertThat(attrs.asMap()).containsKey(SemanticAttributes.HTTP_HOST);
// TODO(anuraaga): It's not well defined when instrumentation records with and
// without port. We should make this more uniform
assertThat(attrs)
Expand All @@ -1012,12 +1020,22 @@ SpanDataAssert assertClientSpan(
host -> assertThat(host).startsWith(uri.getHost()));
}
if (httpClientAttributes.contains(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH)) {
// TODO(anuraaga): Remove after updating to SDK 1.5.0 which adds this into
// hasEntrySatisfying.
// https://github.com/open-telemetry/opentelemetry-java/pull/3433
assertThat(attrs.asMap())
.containsKey(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH);
assertThat(attrs)
.hasEntrySatisfying(
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH,
length -> assertThat(length).isNotNegative());
}
if (httpClientAttributes.contains(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH)) {
// TODO(anuraaga): Remove after updating to SDK 1.5.0 which adds this into
// hasEntrySatisfying.
// https://github.com/open-telemetry/opentelemetry-java/pull/3433
assertThat(attrs.asMap())
.containsKey(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH);
assertThat(attrs)
.hasEntrySatisfying(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
Expand Down

0 comments on commit e4fcbb8

Please sign in to comment.