Some assertions refactoring (#6618)

This commit is contained in:
Mateusz Rzeszutek 2022-09-14 17:24:27 +02:00 committed by GitHub
parent 14b4b3ba07
commit c0b0722699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 22 deletions

View File

@ -209,12 +209,8 @@ public abstract class AbstractGraphqlTest {
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");
}))));
}
@ -256,12 +252,8 @@ public abstract class AbstractGraphqlTest {
.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");

View File

@ -921,10 +921,10 @@ public abstract class AbstractHttpClientTest<REQUEST> {
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());
@ -945,13 +945,12 @@ public abstract class AbstractHttpClientTest<REQUEST> {
// 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)) {
@ -962,11 +961,11 @@ public abstract class AbstractHttpClientTest<REQUEST> {
}
// 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"),