Skip to content

Commit 6a9fb12

Browse files
committed
add test for binary bson
1 parent 1caacc8 commit 6a9fb12

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

infrastructure/raw-writer-2/calls.http

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
@ts6 = 2026-04-02T10:05:00Z
1212
@ts7 = 2026-04-02T10:06:00Z
1313
@ts8 = 2026-04-02T10:07:00Z
14+
@ts9 = 2026-04-02T10:08:00Z
1415

1516

1617
# ─── Health checks ────────────────────────────────────────────────────────────
@@ -66,9 +67,18 @@ User-Agent: calls-http/test
6667

6768
###
6869

69-
### Small BSON (invalid) — malformed JSON with application/bson content-type (→ Mongo, binary field; bytes stored as-is)
70-
# The service stores whatever bytes it receives; BSON/JSON validation is the consumer's job.
71-
POST {{host}}/raw-writer-test/small-bson-invalid/{{ts5}}
70+
### Small BSON (binary) — actual binary BSON bytes with application/bson content-type (→ Mongo, parsed as bson.M)
71+
# testdata/small.bson is generated by ./testdata/generate.sh
72+
POST {{host}}/raw-writer-test/small-bson-binary/{{ts5}}
73+
Content-Type: application/bson
74+
User-Agent: calls-http/test
75+
76+
< ./testdata/small.bson
77+
78+
###
79+
80+
### Small BSON (invalid) — malformed bytes, neither JSON nor BSON (→ Mongo, stored as raw binary)
81+
POST {{host}}/raw-writer-test/small-bson-invalid/{{ts9}}
7282
Content-Type: application/bson
7383
User-Agent: calls-http/test
7484

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
small.bin
2+
small.bson
23
large.json
34
large.bin

infrastructure/raw-writer-2/testdata/generate.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@ cd "$(dirname "$0")"
1313
printf '\xDE\xAD\xBE\xEF' > small.bin
1414
echo "created small.bin (4 bytes)"
1515

16+
# small.bson — binary BSON encoding of {"hello":"world","value":42} (exercises the binary BSON path)
17+
python3 -c "
18+
import struct, sys
19+
20+
def bson_string(key, val):
21+
k = key.encode() + b'\x00'
22+
v = val.encode() + b'\x00'
23+
return b'\x02' + k + struct.pack('<i', len(v)) + v
24+
25+
def bson_int32(key, val):
26+
k = key.encode() + b'\x00'
27+
return b'\x10' + k + struct.pack('<i', val)
28+
29+
body = bson_string('hello', 'world') + bson_int32('value', 42)
30+
doc = struct.pack('<i', 4 + 1 + len(body)) + body + b'\x00'
31+
sys.stdout.buffer.write(doc)
32+
" > small.bson
33+
echo "created small.bson ($(wc -c < small.bson) bytes)"
34+
1635
# large.json — ~6 MB JSON array (exercises the large compressible path → S3 + zstd)
1736
python3 -c "
1837
import json, sys

0 commit comments

Comments
 (0)