Attribute assertions should always contain the attr key (#5027)
* improve attribute assertions to alwyas contain the attr key * spotless * change assertion * Update sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/AttributeAssertionTest.java Co-authored-by: jack-berg <34418638+jack-berg@users.noreply.github.com> * fix build Co-authored-by: jack-berg <34418638+jack-berg@users.noreply.github.com>
This commit is contained in:
parent
ea500962d6
commit
79a601d7d7
|
|
@ -37,6 +37,13 @@ public abstract class AttributeAssertion {
|
|||
// suppressing here.
|
||||
@SuppressWarnings("NullAway")
|
||||
static AbstractAssert<?, ?> attributeValueAssertion(AttributeKey<?> key, @Nullable Object value) {
|
||||
AbstractAssert<? extends AbstractAssert<?, ?>, ?> abstractAssert = makeAssertion(key, value);
|
||||
String description = "%s attribute '%s'";
|
||||
return abstractAssert.as(description, key.getType(), key.getKey());
|
||||
}
|
||||
|
||||
private static AbstractAssert<? extends AbstractAssert<?, ?>, ?> makeAssertion(
|
||||
AttributeKey<?> key, Object value) {
|
||||
switch (key.getType()) {
|
||||
case STRING:
|
||||
return assertThat((String) value);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.testing.assertj;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||
|
||||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import org.assertj.core.api.AbstractAssert;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class AttributeAssertionTest {
|
||||
|
||||
@Test
|
||||
void nullAttr_errorMessageContainsAttrName() {
|
||||
AttributeKey<String> key = AttributeKey.stringKey("flib");
|
||||
|
||||
assertThatThrownBy(
|
||||
() ->
|
||||
AttributeAssertion.create(key, AbstractAssert::isNotNull)
|
||||
.getAssertion()
|
||||
.accept(AttributeAssertion.attributeValueAssertion(key, null)))
|
||||
.isInstanceOf(AssertionError.class)
|
||||
.hasMessage("[STRING attribute 'flib'] \nExpecting actual not to be null");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue