|
5 | 5 |
|
6 | 6 | package io.opentelemetry.sdk.testing.assertj;
|
7 | 7 |
|
| 8 | +import static io.opentelemetry.api.common.AttributeKey.stringKey; |
8 | 9 | import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
9 | 10 | import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
|
10 | 11 | import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
@@ -60,9 +61,9 @@ class MetricAssertionsTest {
|
60 | 61 | private static final InstrumentationScopeInfo INSTRUMENTATION_SCOPE_INFO =
|
61 | 62 | InstrumentationScopeInfo.builder("opentelemetry").setVersion("1.0").build();
|
62 | 63 |
|
63 |
| - private static final AttributeKey<String> DOG = AttributeKey.stringKey("dog"); |
64 |
| - private static final AttributeKey<String> BEAR = AttributeKey.stringKey("bear"); |
65 |
| - private static final AttributeKey<String> CAT = AttributeKey.stringKey("cat"); |
| 64 | + private static final AttributeKey<String> DOG = stringKey("dog"); |
| 65 | + private static final AttributeKey<String> BEAR = stringKey("bear"); |
| 66 | + private static final AttributeKey<String> CAT = stringKey("cat"); |
66 | 67 | private static final AttributeKey<Boolean> WARM = AttributeKey.booleanKey("warm");
|
67 | 68 | private static final AttributeKey<Long> TEMPERATURE = AttributeKey.longKey("temperature");
|
68 | 69 | private static final AttributeKey<Double> LENGTH = AttributeKey.doubleKey("length");
|
@@ -317,7 +318,7 @@ void doubleGauge() {
|
317 | 318 | attributes ->
|
318 | 319 | assertThat(attributes)
|
319 | 320 | .hasSize(2)
|
320 |
| - .containsEntry(AttributeKey.stringKey("dog"), "bark") |
| 321 | + .containsEntry(stringKey("dog"), "bark") |
321 | 322 | .hasEntrySatisfying(DOG, value -> assertThat(value).hasSize(4))
|
322 | 323 | .hasEntrySatisfying(
|
323 | 324 | AttributeKey.booleanKey("dog is cute"),
|
@@ -454,7 +455,19 @@ void doubleGauge() {
|
454 | 455 | equalTo(CONDITIONS, Arrays.asList(false, true)),
|
455 | 456 | equalTo(SCORES, Arrays.asList(0L, 1L)),
|
456 | 457 | equalTo(COINS, Arrays.asList(0.01, 0.05, 0.1)),
|
457 |
| - satisfies(LENGTH, val -> val.isCloseTo(1, offset(0.3)))))); |
| 458 | + satisfies(LENGTH, val -> val.isCloseTo(1, offset(0.3)))) |
| 459 | + .hasAttributesSatisfying( |
| 460 | + attributes -> |
| 461 | + assertThat(attributes) |
| 462 | + .hasSize(8) |
| 463 | + .containsEntry(stringKey("bear"), "mya") |
| 464 | + .containsEntry("warm", true) |
| 465 | + .containsEntry("temperature", 30L) |
| 466 | + .containsEntry("colors", "red", "blue") |
| 467 | + .containsEntry("conditions", false, true) |
| 468 | + .containsEntry("scores", 0L, 1L) |
| 469 | + .containsEntry("coins", 0.01, 0.05, 0.1) |
| 470 | + .containsEntry("length", 1.2)))); |
458 | 471 | }
|
459 | 472 |
|
460 | 473 | @Test
|
@@ -500,7 +513,7 @@ void doubleGaugeFailure() {
|
500 | 513 | resource.hasAttributesSatisfying(
|
501 | 514 | attributes ->
|
502 | 515 | assertThat(attributes)
|
503 |
| - .containsEntry(AttributeKey.stringKey("dog"), "meow")))) |
| 516 | + .containsEntry(stringKey("dog"), "meow")))) |
504 | 517 | .isInstanceOf(AssertionError.class);
|
505 | 518 | assertThatThrownBy(
|
506 | 519 | () ->
|
@@ -774,6 +787,29 @@ void doubleGaugeFailure() {
|
774 | 787 | satisfies(
|
775 | 788 | COINS, val -> val.containsExactly(0.01, 0.05, 0.1))))))
|
776 | 789 | .isInstanceOf(AssertionError.class);
|
| 790 | + assertThatThrownBy( |
| 791 | + () -> |
| 792 | + assertThat(DOUBLE_GAUGE_METRIC) |
| 793 | + .hasDoubleGaugeSatisfying( |
| 794 | + gauge -> |
| 795 | + gauge.hasPointsSatisfying( |
| 796 | + point -> point.hasAttributes(Attributes.empty()), |
| 797 | + point -> |
| 798 | + point.hasAttributesSatisfying( |
| 799 | + attributes -> |
| 800 | + assertThat(attributes) |
| 801 | + .hasSize(8) |
| 802 | + .containsEntry( |
| 803 | + stringKey("bear"), |
| 804 | + "WRONG BEAR NAME") // Failed here |
| 805 | + .containsEntry("warm", true) |
| 806 | + .containsEntry("temperature", 30L) |
| 807 | + .containsEntry("colors", "red", "blue") |
| 808 | + .containsEntry("conditions", false, true) |
| 809 | + .containsEntry("scores", 0L, 1L) |
| 810 | + .containsEntry("coins", 0.01, 0.05, 0.1) |
| 811 | + .containsEntry("length", 1.2))))) |
| 812 | + .isInstanceOf(AssertionError.class); |
777 | 813 | }
|
778 | 814 |
|
779 | 815 | // The above tests verify shared behavior in AbstractPointDataAssert and MetricDataAssert so we
|
|
0 commit comments