diff --git a/tests/h2_otel.t b/tests/h2_otel.t index a302b7d..3f3123f 100644 --- a/tests/h2_otel.t +++ b/tests/h2_otel.t @@ -443,18 +443,14 @@ sub get_ssl_socket { sub get_attr { my($attr, $type, $obj) = @_; - for (keys %{$obj}) { - if ($_ =~ /^attribute\d+/) { - if ($$obj{$_}{key} eq '"' . $attr . '"') { - if ($type eq 'string_value') { - $$obj{$_}{value}{$type} =~ s/(^\")|(\"$)//g; - } - return $$obj{$_}{value}{$type} - } - } - } + my ($res) = grep { + $_ =~ /^attribute\d+/ && $$obj{$_}{key} eq '"' . $attr . '"' + } keys %{$obj}; - return undef; + $$obj{$res}{value}{$type} =~ s/(^\")|(\"$)//g + if $res && $type eq 'string_value'; + + return $$obj{$res}{value}{$type}; } sub decode_protobuf { diff --git a/tests/h2_otel_collector.t b/tests/h2_otel_collector.t index 1f2d301..8e6d8dc 100644 --- a/tests/h2_otel_collector.t +++ b/tests/h2_otel_collector.t @@ -449,11 +449,9 @@ sub get_ssl_socket { sub get_attr { my($attr, $type, $obj) = @_; - for (@{$$obj{"attributes"}}) { - return $$_{"value"}{$type} if ($$_{"key"} eq $attr); - } + my ($res) = grep { $$_{"key"} eq $attr } @{$$obj{"attributes"}}; - return undef; + return $res->{"value"}{$type}; } ############################################################################### diff --git a/tests/otel.t b/tests/otel.t index ba3bde0..0acc3f8 100644 --- a/tests/otel.t +++ b/tests/otel.t @@ -390,18 +390,14 @@ sub get_ssl_socket { sub get_attr { my($attr, $type, $obj) = @_; - for (keys %{$obj}) { - if ($_ =~ /^attribute\d+/) { - if ($$obj{$_}{key} eq '"' . $attr . '"') { - if ($type eq 'string_value') { - $$obj{$_}{value}{$type} =~ s/(^\")|(\"$)//g; - } - return $$obj{$_}{value}{$type} - } - } - } + my ($res) = grep { + $_ =~ /^attribute\d+/ && $$obj{$_}{key} eq '"' . $attr . '"' + } keys %{$obj}; - return undef; + $$obj{$res}{value}{$type} =~ s/(^\")|(\"$)//g + if $res && $type eq 'string_value'; + + return $$obj{$res}{value}{$type}; } sub decode_protobuf { diff --git a/tests/otel_collector.t b/tests/otel_collector.t index 223e5ec..c5ac2a8 100644 --- a/tests/otel_collector.t +++ b/tests/otel_collector.t @@ -394,11 +394,9 @@ sub get_ssl_socket { sub get_attr { my($attr, $type, $obj) = @_; - for (@{$$obj{"attributes"}}) { - return $$_{"value"}{$type} if ($$_{"key"} eq $attr); - } + my ($res) = grep { $$_{"key"} eq $attr } @{$$obj{"attributes"}}; - return undef; + return $res->{"value"}{$type}; } ###############################################################################