diff options
| author | Fuwn <[email protected]> | 2026-02-26 14:46:02 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-26 14:48:52 -0800 |
| commit | 0099d621e97b6048971fadb5c71918cc9f2b5a09 (patch) | |
| tree | a38ba31585200bacd61f453ef7158de7f0aaf7a3 /internal/ingest/client_test.go | |
| parent | Initial commit (diff) | |
| download | plutia-test-0099d621e97b6048971fadb5c71918cc9f2b5a09.tar.xz plutia-test-0099d621e97b6048971fadb5c71918cc9f2b5a09.zip | |
feat: initial Plutia release — verifiable high-performance PLC mirror (mirror + resolver modes)
Diffstat (limited to 'internal/ingest/client_test.go')
| -rw-r--r-- | internal/ingest/client_test.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/ingest/client_test.go b/internal/ingest/client_test.go new file mode 100644 index 0000000..ff80225 --- /dev/null +++ b/internal/ingest/client_test.go @@ -0,0 +1,38 @@ +package ingest + +import ( + "strings" + "testing" +) + +func TestDecodeExportBody_IgnoresTrailingPartialNDJSONLine(t *testing.T) { + body := strings.Join([]string{ + `{"seq":1,"did":"did:plc:alice","cid":"cid1","operation":{"x":1}}`, + `{"seq":2,"did":"did:plc:bob","cid":"cid2","operation":{"x":2}}`, + `{"seq":3,"did":"did:plc:carol","cid":"cid3","operation":{"x":3}`, + }, "\n") + + records, err := decodeExportBody(strings.NewReader(body), 0) + if err != nil { + t.Fatalf("decode export body: %v", err) + } + if len(records) != 2 { + t.Fatalf("record count mismatch: got %d want 2", len(records)) + } + if records[0].Seq != 1 || records[1].Seq != 2 { + t.Fatalf("unexpected sequences: got [%d %d], want [1 2]", records[0].Seq, records[1].Seq) + } +} + +func TestDecodeExportBody_FailsOnMalformedNonTrailingNDJSONLine(t *testing.T) { + body := strings.Join([]string{ + `{"seq":1,"did":"did:plc:alice","cid":"cid1","operation":{"x":1}}`, + `{"seq":2,"did":"did:plc:bob","cid":"cid2","operation":{"x":2}`, + `{"seq":3,"did":"did:plc:carol","cid":"cid3","operation":{"x":3}}`, + }, "\n") + + _, err := decodeExportBody(strings.NewReader(body), 0) + if err == nil { + t.Fatalf("expected malformed middle line to fail") + } +} |