Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger committed Jun 10, 2024
1 parent 606c931 commit 5782ca6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions sdk/testing/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ dependencies {

testImplementation("junit:junit")
testImplementation("org.junit.vintage:junit-vintage-engine")
testImplementation(project(":sdk-extensions:autoconfigure"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static AutoConfiguredOpenTelemetryTesting create(Map<String, String> prop
return new AutoConfiguredOpenTelemetryTesting(getOpenTelemetrySdk(properties));
}

public AutoConfiguredOpenTelemetryTesting(OpenTelemetryTestSdk sdk) {
private AutoConfiguredOpenTelemetryTesting(OpenTelemetryTestSdk sdk) {
super(sdk);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.sdk.testing.sdk;

import io.opentelemetry.api.common.AttributeKey;
import java.util.Collections;
import org.junit.jupiter.api.Test;

class AutoConfiguredOpenTelemetryTestingTest {

@Test
void sdkEnabled() {
AutoConfiguredOpenTelemetryTesting testing =
AutoConfiguredOpenTelemetryTesting.create(Collections.emptyMap());
testing.getOpenTelemetry().getTracer("test").spanBuilder("test").startSpan().end();
testing.assertTraces(trace -> trace.hasSize(1));
}

@Test
void resourceAttributes() {
AutoConfiguredOpenTelemetryTesting testing =
AutoConfiguredOpenTelemetryTesting.create(
Collections.singletonMap("otel.resource.attributes", "foo=bar"));
testing.getOpenTelemetry().getTracer("test").spanBuilder("test").startSpan().end();
testing.assertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasResourceSatisfying(
resource -> resource.hasAttribute(AttributeKey.stringKey("foo"), "bar"))));
}
}

0 comments on commit 5782ca6

Please sign in to comment.