Skip to content

Commit d385121

Browse files
committed
tests: internal: opentelemetry: add cases for long nested vals
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 8a8e805 commit d385121

File tree

2 files changed

+92
-4
lines changed

2 files changed

+92
-4
lines changed

tests/internal/data/opentelemetry/test_cases.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,5 +1251,76 @@
12511251
"log_metadata": {"otlp":{}},
12521252
"log_body": {"empty_map_key": null, "normal_key": "normal_value", "missing_value_key": ""}
12531253
}
1254+
},
1255+
"arrayvalue_wrapped_map": {
1256+
"input": {
1257+
"resourceLogs": [{
1258+
"scopeLogs": [{
1259+
"logRecords": [{
1260+
"timeUnixNano": "1640995200000000000",
1261+
"body": {
1262+
"kvlistValue": {
1263+
"values": [{
1264+
"key": "a",
1265+
"value": {
1266+
"kvlistValue": {
1267+
"values": [{
1268+
"key": "d",
1269+
"value": {
1270+
"arrayValue": {
1271+
"values": [{
1272+
"kvlistValue": {
1273+
"values": [{
1274+
"key": "e",
1275+
"value": {"stringValue": "g"}
1276+
}]
1277+
}
1278+
}]
1279+
}
1280+
}
1281+
}]
1282+
}
1283+
}
1284+
}]
1285+
}
1286+
}
1287+
}]
1288+
}]
1289+
}]
1290+
},
1291+
"expected": {
1292+
"group_metadata": {"schema":"otlp","resource_id":0,"scope_id":0},
1293+
"group_body": {"resource":{}},
1294+
"log_metadata": {"otlp":{}},
1295+
"log_body": {"a":{"d":[{"e":"g"}]}}
1296+
}
1297+
},
1298+
"unwrapped_plain_map": {
1299+
"input": {
1300+
"resourceLogs": [{
1301+
"scopeLogs": [{
1302+
"logRecords": [{
1303+
"timeUnixNano": "1640995200000000000",
1304+
"body": {
1305+
"kvlistValue": {
1306+
"values": [{
1307+
"key": "plain",
1308+
"value": {
1309+
"key1": {"stringValue": "v1"},
1310+
"key2": {"intValue": 2}
1311+
}
1312+
}]
1313+
}
1314+
}
1315+
}]
1316+
}]
1317+
}]
1318+
},
1319+
"expected": {
1320+
"group_metadata": {"schema":"otlp","resource_id":0,"scope_id":0},
1321+
"group_body": {"resource":{}},
1322+
"log_metadata": {"otlp":{}},
1323+
"log_body": {"plain": {"key1": "v1", "key2": 2}}
1324+
}
12541325
}
12551326
}

tests/internal/pack.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -977,13 +977,30 @@ void test_json_pack_empty_array()
977977
int root_type;
978978
size_t out_size;
979979
char *out_buf;
980-
char json[] =
981-
"{\"resourceLogs\":[{\"resource\":{},\"scopeLogs\":[{\"scope\":{},"
982-
"\"logRecords\":[{\"body\":{\"test\":{\"values\":[]}}}]}]}]}";
980+
char *json = "{\"resourceLogs\":[{\"resource\":{},\"scopeLogs\":[{\"scope\":{},\"logRecords\":[{\"observedTimeUnixNano\":\"1754059282910920618\",\"body\":{\"kvlistValue\":{\"values\":[{\"key\":\"a\",\"value\":{\"kvlistValue\":{\"values\":[{\"key\":\"b\",\"value\":{\"kvlistValue\":{\"values\":[{\"key\":\"c\",\"value\":{\"kvlistValue\":{\"values\":[{\"key\":\"d\",\"value\":{\"arrayValue\":{\"values\":[{\"kvlistValue\":{\"values\":[{\"key\":\"e\",\"value\":{\"kvlistValue\":{\"values\":[{\"key\":\"f\",\"value\":{\"stringValue\":\"g\"}}]}}}]}}]}}}]}}}]}}}]}}}]}}}]}]}]}";
983981

984-
ret = flb_pack_json(json, strlen(json), &out_buf, &out_size, &root_type, NULL);
982+
ret = flb_pack_json( (char*) json, strlen((char *) json), &out_buf, &out_size, &root_type, NULL);
985983
TEST_CHECK(ret == 0);
986984

985+
if (ret != 0) {
986+
printf("flb_pack_json failed: %d\n", ret);
987+
exit(EXIT_FAILURE);
988+
}
989+
990+
/* unpack just to validate the msgpack buffer */
991+
msgpack_unpacked result;
992+
msgpack_object obj;
993+
size_t off = 0;
994+
msgpack_unpacked_init(&result);
995+
off = 0;
996+
TEST_CHECK(msgpack_unpack_next(&result, out_buf, out_size, &off) == MSGPACK_UNPACK_SUCCESS);
997+
998+
printf("\nmsgpack---:\n");
999+
msgpack_object_print(stdout, result.data);
1000+
printf("\n");
1001+
1002+
msgpack_unpacked_destroy(&result);
1003+
9871004
flb_free(out_buf);
9881005
}
9891006

0 commit comments

Comments
 (0)