Skip to content

Commit

Permalink
add context info about wrong span or trace (#6703)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger authored Sep 18, 2024
1 parent d773f3b commit c9c857c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
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

0 comments on commit c9c857c

Please sign in to comment.