Skip to content

Commit

Permalink
backfills test to show non-string tags are invalid like other thigns (#…
Browse files Browse the repository at this point in the history
…3693)

Signed-off-by: Adrian Cole <adrian@tetrate.io>
  • Loading branch information
codefromthecrypt authored Jan 16, 2024
1 parent e3dec43 commit 00bde7f
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions zipkin/src/test/java/zipkin2/codec/SpanBytesDecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import zipkin2.Span;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static zipkin2.TestObjects.BACKEND;
import static zipkin2.TestObjects.TRACE;
Expand Down Expand Up @@ -299,7 +300,7 @@ class SpanBytesDecoderTest {
"traceId": "48485A3953BB6124",
"name": "get-traces",
"id": "6b221d5bc9e6496c"
}\
}
""";

SpanBytesDecoder.JSON_V2.decodeOne(json.getBytes(UTF_8));
Expand All @@ -313,14 +314,14 @@ class SpanBytesDecoderTest {
"traceId": "48485a3953bb61246b221d5bc9e6496c",
"name": "get-traces",
"id": "6b221d5bc9e6496c"
}\
}
""").getBytes(UTF_8);
byte[] withLower64bitsTraceId = ("""
{
"traceId": "6b221d5bc9e6496c",
"name": "get-traces",
"id": "6b221d5bc9e6496c"
}\
}
""").getBytes(UTF_8);

assertThat(SpanBytesDecoder.JSON_V2.decodeOne(with128BitTraceId))
Expand All @@ -343,7 +344,7 @@ class SpanBytesDecoderTest {
"tags": null,
"debug": null,
"shared": null
}\
}
""";

SpanBytesDecoder.JSON_V2.decodeOne(json.getBytes(UTF_8));
Expand All @@ -361,7 +362,7 @@ class SpanBytesDecoderTest {
"ipv6": null,
"port": null
}
}\
}
""";

assertThat(SpanBytesDecoder.JSON_V2.decodeOne(json.getBytes(UTF_8)).localEndpoint())
Expand All @@ -379,7 +380,7 @@ class SpanBytesDecoderTest {
"ipv6": null,
"port": null
}
}\
}
""")
.getBytes(UTF_8)).localEndpoint()).isNull();
assertThat(SpanBytesDecoder.JSON_V2.decodeOne(("""
Expand All @@ -388,7 +389,7 @@ class SpanBytesDecoderTest {
"id": "6b221d5bc9e6496c",
"localEndpoint": {
}
}\
}
""")
.getBytes(UTF_8)).localEndpoint()).isNull();
assertThat(SpanBytesDecoder.JSON_V2.decodeOne(("""
Expand All @@ -401,7 +402,7 @@ class SpanBytesDecoderTest {
"ipv6": null,
"port": null
}
}\
}
""")
.getBytes(UTF_8)).remoteEndpoint()).isNull();
assertThat(SpanBytesDecoder.JSON_V2.decodeOne(("""
Expand All @@ -410,7 +411,7 @@ class SpanBytesDecoderTest {
"id": "6b221d5bc9e6496c",
"remoteEndpoint": {
}
}\
}
""")
.getBytes(UTF_8)).remoteEndpoint()).isNull();
}
Expand All @@ -426,7 +427,7 @@ class SpanBytesDecoderTest {
"annotations": [
{ "timestamp": 1472470996199000}
]
}\
}
""";

SpanBytesDecoder.JSON_V2.decodeOne(json.getBytes(UTF_8));
Expand All @@ -442,7 +443,7 @@ class SpanBytesDecoderTest {
"traceId": null,
"name": "get-traces",
"id": "6b221d5bc9e6496c"
}\
}
""";

SpanBytesDecoder.JSON_V2.decodeOne(json.getBytes(UTF_8));
Expand All @@ -458,7 +459,7 @@ class SpanBytesDecoderTest {
"traceId": "6b221d5bc9e6496c",
"name": "get-traces",
"id": null
}\
}
""";

SpanBytesDecoder.JSON_V2.decodeOne(json.getBytes(UTF_8));
Expand All @@ -477,7 +478,7 @@ class SpanBytesDecoderTest {
"tags": {
"foo": NULL
}
}\
}
""";

SpanBytesDecoder.JSON_V2.decodeOne(json.getBytes(UTF_8));
Expand All @@ -496,7 +497,7 @@ class SpanBytesDecoderTest {
"annotations": [
{ "timestamp": 1472470996199000, "value": NULL}
]
}\
}
""";

SpanBytesDecoder.JSON_V2.decodeOne(json.getBytes(UTF_8));
Expand All @@ -515,14 +516,30 @@ class SpanBytesDecoderTest {
"annotations": [
{ "timestamp": NULL, "value": "foo"}
]
}\
}
""";

SpanBytesDecoder.JSON_V2.decodeOne(json.getBytes(UTF_8));
});
assertThat(exception.getMessage()).contains("$.annotations[0].timestamp");
}

@Test void niceErrorOnNonStringTagValue() {
String json = """
{
"traceId": "6b221d5bc9e6496c",
"name": "get-traces",
"id": "6b221d5bc9e6496c",
"tags": {
"error": true
}
}
""";

assertThatThrownBy(() -> SpanBytesDecoder.JSON_V2.decodeOne(json.getBytes(UTF_8)))
.hasMessageContaining("Expected a string but was BOOLEAN");
}

@Test void readSpan_localEndpoint_noServiceName() {
String json = """
{
Expand All @@ -532,7 +549,7 @@ class SpanBytesDecoderTest {
"localEndpoint": {
"ipv4": "127.0.0.1"
}
}\
}
""";

assertThat(SpanBytesDecoder.JSON_V2.decodeOne(json.getBytes(UTF_8)).localServiceName())
Expand All @@ -548,7 +565,7 @@ class SpanBytesDecoderTest {
"remoteEndpoint": {
"ipv4": "127.0.0.1"
}
}\
}
""";

assertThat(SpanBytesDecoder.JSON_V2.decodeOne(json.getBytes(UTF_8)).remoteServiceName())
Expand Down

0 comments on commit 00bde7f

Please sign in to comment.