Skip to content

Commit

Permalink
Merge branch 'main' into remove-brick-math-phan-config
Browse files Browse the repository at this point in the history
  • Loading branch information
brettmc committed Mar 31, 2022
2 parents 392fe4b + ca05f51 commit 8975100
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions tests/Unit/Contrib/IdConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,45 @@
*/
class IdConverterTest extends TestCase
{
public function test_correctly_converted_span_id()
//Based on this section of the Jaeger spec https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/jaeger.md#ids
public function test_correctly_converts_example_from_spec()
{
$hex = 'FF00000000000000';

$this->assertEquals(-72057594037927936, IdConverter::convertOtelToJaegerSpanId($hex));
}

public function test_correctly_converts_random_span_id()
{
// 16 char hex string
$hex = bin2hex(random_bytes(8));

$this->assertEquals($hex, dechex(IdConverter::convertOtelToJaegerSpanId($hex)));
$this->assertEquals($hex, $this->dechexWithLeadingZeroes(IdConverter::convertOtelToJaegerSpanId($hex)));
}

public function test_correctly_converted_trace_id()
public function test_correctly_converts_trace_id()
{
$hex = '0102030405060708090a0b0c0d0e0f10';

$traceId = IdConverter::convertOtelToJaegerTraceIds($hex);

$this->assertEquals(72623859790382856, $traceId['traceIdHigh']);
$this->assertEquals(651345242494996240, $traceId['traceIdLow']);
}

public function test_correctly_converts_random_trace_id()
{
// 32 char hex string
$hex = bin2hex(random_bytes(16));

$traceId = IdConverter::convertOtelToJaegerTraceIds($hex);
$convertedTraceId = dechex((int) $traceId['traceIdHigh']);
$convertedTraceId .= dechex((int) $traceId['traceIdLow']);
$convertedTraceId = $this->dechexWithLeadingZeroes($traceId['traceIdHigh']);
$convertedTraceId .= $this->dechexWithLeadingZeroes($traceId['traceIdLow']);
$this->assertEquals($hex, $convertedTraceId);
}

private function dechexWithLeadingZeroes(int $num)
{
return str_pad(dechex($num), 16, '0', STR_PAD_LEFT);
}
}

0 comments on commit 8975100

Please sign in to comment.