Skip to content

Commit

Permalink
Some assertions refactoring (#6618)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek authored Sep 14, 2022
1 parent 14b4b3b commit c0b0722
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,8 @@ void parseError() {
assertThat(attrs)
.containsEntry("exception.type", "InvalidSyntax");
String message =
String.valueOf(
attrs
.asMap()
.get(
AttributeKey.stringKey(
"exception.message")));
attrs.get(
AttributeKey.stringKey("exception.message"));
assertThat(message).startsWith("Invalid Syntax");
}))));
}
Expand Down Expand Up @@ -256,12 +252,8 @@ void validationError() {
.containsEntry(
"exception.type", "ValidationError");
String message =
String.valueOf(
attrs
.asMap()
.get(
AttributeKey.stringKey(
"exception.message")));
attrs.get(
AttributeKey.stringKey("exception.message"));
assertThat(message)
.startsWith(
"Validation error of type FieldUndefined");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -921,10 +921,10 @@ SpanDataAssert assertClientSpan(
if (uri.getPort() == PortUtils.UNUSABLE_PORT || uri.getHost().equals("192.0.2.1")) {
// TODO: net.peer.name and net.peer.port should always be populated from the URI or
// the Host header, verify these assertions below
if (attrs.asMap().containsKey(SemanticAttributes.NET_PEER_NAME)) {
if (attrs.get(SemanticAttributes.NET_PEER_NAME) != null) {
assertThat(attrs).containsEntry(SemanticAttributes.NET_PEER_NAME, uri.getHost());
}
if (attrs.asMap().containsKey(SemanticAttributes.NET_PEER_PORT)) {
if (attrs.get(SemanticAttributes.NET_PEER_PORT) != null) {
if (uri.getPort() > 0) {
assertThat(attrs)
.containsEntry(SemanticAttributes.NET_PEER_PORT, (long) uri.getPort());
Expand All @@ -945,13 +945,12 @@ SpanDataAssert assertClientSpan(

// In these cases the peer connection is not established, so the HTTP client should
// not report any socket-level attributes
// TODO https://github.com/open-telemetry/opentelemetry-java/pull/4723
assertThat(attrs.asMap())
.doesNotContainKey(AttributeKey.stringKey("net.sock.family"))
assertThat(attrs)
.doesNotContainKey("net.sock.family")
// TODO netty sometimes reports net.sock.peer.addr in connection error test
// .doesNotContainKey(AttributeKey.stringKey("net.sock.peer.addr"))
.doesNotContainKey(AttributeKey.stringKey("net.sock.peer.name"))
.doesNotContainKey(AttributeKey.stringKey("net.sock.peer.port"));
// .doesNotContainKey("net.sock.peer.addr")
.doesNotContainKey("net.sock.peer.name")
.doesNotContainKey("net.sock.peer.port");

} else {
if (httpClientAttributes.contains(SemanticAttributes.NET_PEER_NAME)) {
Expand All @@ -962,11 +961,11 @@ SpanDataAssert assertClientSpan(
}

// TODO: Move to test knob rather than always treating as optional
if (attrs.asMap().containsKey(AttributeKey.stringKey("net.sock.peer.addr"))) {
if (attrs.get(AttributeKey.stringKey("net.sock.peer.addr")) != null) {
assertThat(attrs)
.containsEntry(AttributeKey.stringKey("net.sock.peer.addr"), "127.0.0.1");
}
if (attrs.asMap().containsKey(AttributeKey.stringKey("net.sock.peer.port"))) {
if (attrs.get(AttributeKey.stringKey("net.sock.peer.port")) != null) {
assertThat(attrs)
.containsEntry(
AttributeKey.longKey("net.sock.peer.port"),
Expand Down

0 comments on commit c0b0722

Please sign in to comment.