MCPcopy Create free account
hub / github.com/blues/note / TestBulkEncodeDecode

Function TestBulkEncodeDecode

lib/bulk_test.go:543–592  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

541}
542
543func TestBulkEncodeDecode(t *testing.T) {
544 ctx := context.Background()
545 for _, test := range bulkTests {
546 expectedJSON, err := note.JSONMarshal(test.data)
547 require.NoError(t, err)
548
549 if verboseBulkTest {
550 fmt.Printf("Template: %s\n", test.template)
551 fmt.Printf("Data Before: %v JSON: %s\n", test.data, expectedJSON)
552 }
553
554 templateBody := BulkBody{}
555 templateBody.NoteFormat = BulkNoteFormatFlexNano
556 templateBody.NoteTemplate = test.template
557 templateBodyJSON, err := note.JSONMarshal(templateBody)
558 require.NoError(t, err)
559
560 context, err := BulkEncodeTemplate(templateBodyJSON)
561 assert.NoError(t, err)
562
563 output, err := context.BulkEncodeNextEntry(ctx, test.data, []byte{}, 0, 0, "", "", false)
564 if test.wantErr {
565 assert.Error(t, err)
566 continue
567 }
568 assert.NoError(t, err)
569
570 if verboseBulkTest {
571 fmt.Printf("Binary: %v\n", output)
572 }
573
574 context, err = BulkDecodeTemplate(ctx, templateBodyJSON, output)
575 assert.NoError(t, err)
576
577 body, payload, _, _, _, _, success := context.BulkDecodeNextEntry(ctx)
578 assert.Equal(t, true, success, "BulkDecodeNextEntry failed")
579 assert.Equal(t, "", string(payload))
580
581 // The contract appears to be that these should be equal from the JSON standpoint
582 // They are not equal from the Go standpoint because numbers are represented as json.Number rather than their native types
583 actualJSON, err := note.JSONMarshal(body)
584 assert.NoError(t, err)
585
586 if verboseBulkTest {
587 fmt.Printf("Data After: %v JSON: %s\n\n", body, actualJSON)
588 }
589
590 assert.JSONEq(t, string(expectedJSON), string(actualJSON), "JSON strings should match after encoding and decoding using template %s", test.template)
591 }
592}
593
594// TestOLCEncodingRoundTrip tests that OLC values round-trip correctly through encoding/decoding
595func TestOLCEncodingRoundTrip(t *testing.T) {

Callers

nothing calls this directly

Calls 5

BulkEncodeTemplateFunction · 0.85
BulkDecodeTemplateFunction · 0.85
BulkEncodeNextEntryMethod · 0.80
BulkDecodeNextEntryMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected