Skip to content

Commit

Permalink
Add compliance tests for environment variables (#648)
Browse files Browse the repository at this point in the history
* Add compliance tests for environment variables

* Add tests to verify compliance

* Add Makefile task for testing compliance
  • Loading branch information
yuktea authored Apr 2, 2022
1 parent 0bc3731 commit f2ad2fc
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ test-integration:
$(DC_RUN_PHP) env XDEBUG_MODE=off vendor/bin/phpunit --testsuite integration --colors=always
test-coverage:
$(DC_RUN_PHP) env XDEBUG_MODE=coverage vendor/bin/phpunit --testsuite unit --coverage-html=tests/coverage/html
test-compliance:
$(DC_RUN_PHP) env XDEBUG_MODE=coverage vendor/bin/phpunit --group compliance
test-trace-compliance:
$(DC_RUN_PHP) env XDEBUG_MODE=coverage vendor/bin/phpunit --group trace-compliance
phan:
$(DC_RUN_PHP) env XDEBUG_MODE=off env PHAN_DISABLE_XDEBUG_WARN=1 vendor/bin/phan
psalm:
Expand Down
134 changes: 134 additions & 0 deletions tests/Integration/SDK/SpanLimitsBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Tests\Integration\SDK;

use AssertWell\PHPUnitGlobalState\EnvironmentVariables;
use OpenTelemetry\SDK\Trace\SpanLimitsBuilder;
use PHPUnit\Framework\TestCase;

class SpanLimitsBuilderTest extends TestCase
{
use EnvironmentVariables;

public function tearDown(): void
{
$this->restoreEnvironmentVariables();
}

/**
* @group trace-compliance
*/
public function test_span_length_limits_builder_uses_environment_variable(): void
{
$this->setEnvironmentVariable('OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT', 9);
$builder = new SpanLimitsBuilder();
$spanLimits = $builder->build();
$this->assertEquals(9, $spanLimits->getAttributeLimits()->getAttributeValueLengthLimit());
}

/**
* @group trace-compliance
*/
public function test_span_length_limits_builder_uses_configured_value(): void
{
$this->setEnvironmentVariable('OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT', 9);
$builder = new SpanLimitsBuilder();
$builder->setAttributeValueLengthLimit(201);
$spanLimits = $builder->build();
$this->assertEquals(201, $spanLimits->getAttributeLimits()->getAttributeValueLengthLimit());
}

/**
* @group trace-compliance
*/
public function test_span_event_limits_builder_uses_environment_variable(): void
{
$this->setEnvironmentVariable('OTEL_SPAN_EVENT_COUNT_LIMIT', 200);
$builder = new SpanLimitsBuilder();
$spanLimits = $builder->build();
$this->assertEquals(200, $spanLimits->getEventCountLimit());
}

/**
* @group trace-compliance
*/
public function test_span_event_limits_builder_uses_configured_value(): void
{
$this->setEnvironmentVariable('OTEL_SPAN_EVENT_COUNT_LIMIT', 200);
$builder = new SpanLimitsBuilder();
$builder->setEventCountLimit(185);
$spanLimits = $builder->build();
$this->assertEquals(185, $spanLimits->getEventCountLimit());
}

/**
* @group trace-compliance
*/
public function test_span_limits_link_builder_uses_environment_variable(): void
{
$this->setEnvironmentVariable('OTEL_SPAN_LINK_COUNT_LIMIT', 1101);
$builder = new SpanLimitsBuilder();
$spanLimits = $builder->build();
$this->assertEquals(1101, $spanLimits->getLinkCountLimit());
}

/**
* @group trace-compliance
*/
public function test_span_limits_link_builder_uses_configured_value(): void
{
$this->setEnvironmentVariable('OTEL_SPAN_LINK_COUNT_LIMIT', 1102);
$builder = new SpanLimitsBuilder();
$builder->setLinkCountLimit(193);
$spanLimits = $builder->build();
$this->assertEquals(193, $spanLimits->getLinkCountLimit());
}

/**
* @group trace-compliance
*/
public function test_span_attribute_per_event_count_limits_builder_uses_environment_variable(): void
{
$this->setEnvironmentVariable('OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT', 400);
$builder = new SpanLimitsBuilder();
$spanLimits = $builder->build();
$this->assertEquals(400, $spanLimits->getAttributePerEventCountLimit());
}

/**
* @group trace-compliance
*/
public function test_span_event_attribute_per_event_count_limits_builder_uses_configured_value(): void
{
$this->setEnvironmentVariable('OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT', 400);
$builder = new SpanLimitsBuilder();
$builder->setAttributePerEventCountLimit(155);
$spanLimits = $builder->build();
$this->assertEquals(155, $spanLimits->getAttributePerEventCountLimit());
}

/**
* @group trace-compliance
*/
public function test_span_attribute_per_link_count_limits_builder_uses_environment_variable(): void
{
$this->setEnvironmentVariable('OTEL_LINK_ATTRIBUTE_COUNT_LIMIT', 500);
$builder = new SpanLimitsBuilder();
$spanLimits = $builder->build();
$this->assertEquals(500, $spanLimits->getAttributePerLinkCountLimit());
}

/**
* @group trace-compliance
*/
public function test_span_link_attribute_per_event_count_limits_builder_uses_configured_value(): void
{
$this->setEnvironmentVariable('OTEL_LINK_ATTRIBUTE_COUNT_LIMIT', 500);
$builder = new SpanLimitsBuilder();
$builder->setAttributePerLinkCountLimit(450);
$spanLimits = $builder->build();
$this->assertEquals(450, $spanLimits->getAttributePerLinkCountLimit());
}
}

0 comments on commit f2ad2fc

Please sign in to comment.