Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add context info about wrong span or trace #6703

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ public TraceAssert hasSpansSatisfyingExactly(
List<Consumer<SpanDataAssert>> assertionsList =
StreamSupport.stream(assertions.spliterator(), false).collect(Collectors.toList());
hasSize(assertionsList.size());

// Avoid zipSatisfy - https://github.com/assertj/assertj-core/issues/2300
for (int i = 0; i < assertionsList.size(); i++) {
assertionsList.get(i).accept(new SpanDataAssert(actual.get(i)));
assertionsList.get(i).accept(new SpanDataAssert(actual.get(i)).describedAs("Span " + i));
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public TracesAssert hasTracesSatisfyingExactly(
hasSize(assertionsList.size());
// Avoid zipSatisfy - https://github.com/assertj/assertj-core/issues/2300
for (int i = 0; i < assertionsList.size(); i++) {
assertionsList.get(i).accept(new TraceAssert(actual.get(i)));
assertionsList.get(i).accept(new TraceAssert(actual.get(i)).describedAs("Trace " + i));
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,15 @@ void hasSpansSatisfyingExactly() {
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasSpanId(SPAN_ID1), span -> span.hasSpanId(SPAN_ID2)));
// wrong number of spans
assertThatThrownBy(
() ->
TracesAssert.assertThat(traces)
.hasTracesSatisfyingExactly(
trace -> trace.hasSpansSatisfyingExactly(span -> span.hasSpanId(SPAN_ID1))))
.isInstanceOf(AssertionError.class)
.hasMessageStartingWith("[Trace 0] \n" + "Expected size: 1 but was: 2");

// test asserting spans in wrong oder
assertThatThrownBy(
() ->
Expand All @@ -689,7 +698,9 @@ void hasSpansSatisfyingExactly() {
trace.hasSpansSatisfyingExactly(
span -> span.hasSpanId(SPAN_ID2),
span -> span.hasSpanId(SPAN_ID1))))
.isInstanceOf(AssertionError.class);
.isInstanceOf(AssertionError.class)
.hasMessage(
"[Span 0] Expected span [span1] to have span ID <0000000000000004> but was <0000000000000003>");

// test asserting spans in any order
TracesAssert.assertThat(traces)
Expand Down
Loading