-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.store.postgres_test.go
More file actions
706 lines (624 loc) · 20.8 KB
/
Copy pathevent.store.postgres_test.go
File metadata and controls
706 lines (624 loc) · 20.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
package store_test
import (
"context"
"fmt"
"testing"
"time"
store "github.com/gradientzero/comby-store-postgres"
"github.com/gradientzero/comby/v3"
)
func TestEventStore1(t *testing.T) {
var err error
ctx := context.Background()
// setup and init store
eventStore := store.NewEventStorePostgres("localhost", 5432, "postgres", "mysecretpassword", "postgres")
if err = eventStore.Init(ctx,
comby.EventStoreOptionWithAttribute("key1", "value"),
); err != nil {
t.Fatal(err)
}
// check if the attribute is set
if v := eventStore.Options().Attributes.Get("key1"); v != nil {
if v != "value" {
t.Fatalf("wrong value: %q", v)
}
} else {
t.Fatalf("missing key")
}
// reset database
if err := eventStore.Reset(ctx); err != nil {
t.Fatal(err)
}
// check info with empty store
if m, err := eventStore.Info(ctx); err != nil {
t.Fatalf("failed to get info: %v", err)
} else {
if m.LastItemCreatedAt != 0 {
t.Fatalf("wrong last item created at %d", m.LastItemCreatedAt)
}
}
// check totals
if eventStore.Total(ctx) != 0 {
t.Fatalf("wrong total %d", eventStore.Total(ctx))
}
// Create test domain data
type TestDomainData struct {
Name string
Value int
}
// Create values
evt1 := &comby.BaseEvent{
InstanceId: 1,
EventUuid: comby.NewUuid(),
TenantUuid: "TenantUuid_1",
CommandUuid: "CommandUuid_1",
AggregateUuid: "AggregateUuid_1",
Domain: "Domain_1",
CreatedAt: 1000,
Version: 1,
DomainEvt: &TestDomainData{
Name: "TestEvent1",
Value: 100,
},
}
if err := eventStore.Create(ctx,
comby.EventStoreCreateOptionWithEvent(evt1),
); err != nil {
t.Fatal(err)
}
evt2 := &comby.BaseEvent{
InstanceId: 1,
EventUuid: comby.NewUuid(),
TenantUuid: "TenantUuid_2",
CommandUuid: "CommandUuid_2",
AggregateUuid: "AggregateUuid_2",
Domain: "Domain_2",
CreatedAt: 1000,
Version: 1,
DomainEvt: &TestDomainData{
Name: "TestEvent2",
Value: 200,
},
}
if err := eventStore.Create(ctx,
comby.EventStoreCreateOptionWithEvent(evt2),
comby.EventStoreCreateOptionWithAttribute("anyKey1", "anyValue1"),
); err != nil {
t.Fatal(err)
}
// check totals
if eventStore.Total(ctx) != 2 {
t.Fatalf("wrong total %d", eventStore.Total(ctx))
}
// Get a value and verify all fields
if _evt1, err := eventStore.Get(ctx,
comby.EventStoreGetOptionWithEventUuid(evt1.EventUuid),
); err != nil {
t.Fatal(err)
} else {
if _evt1.GetAggregateUuid() != "AggregateUuid_1" {
t.Fatalf("wrong aggregate uuid: %q", _evt1.GetAggregateUuid())
}
if _evt1.GetTenantUuid() != "TenantUuid_1" {
t.Fatalf("wrong tenant uuid: %q", _evt1.GetTenantUuid())
}
if _evt1.GetCommandUuid() != "CommandUuid_1" {
t.Fatalf("wrong command uuid: %q", _evt1.GetCommandUuid())
}
if _evt1.GetDomain() != "Domain_1" {
t.Fatalf("wrong domain: %q", _evt1.GetDomain())
}
if _evt1.GetVersion() != 1 {
t.Fatalf("wrong version: %d", _evt1.GetVersion())
}
if _evt1.GetInstanceId() != 1 {
t.Fatalf("wrong instance id: %d", _evt1.GetInstanceId())
}
// Verify data_bytes is not empty
if len(_evt1.GetDomainEvtBytes()) == 0 {
t.Fatalf("data_bytes is empty")
}
// Verify data_type is set
if len(_evt1.GetDomainEvtName()) == 0 {
t.Fatalf("data_type is empty")
}
}
// List all events
if evts, total, err := eventStore.List(ctx); err == nil {
if len(evts) != 2 {
t.Fatalf("wrong number of events: %d", len(evts))
}
if int64(len(evts)) != total {
t.Fatalf("wrong number of totals: %d", total)
}
}
// Delete an event
if err := eventStore.Delete(ctx,
comby.EventStoreDeleteOptionWithEventUuid(evt1.EventUuid),
); err != nil {
t.Fatal(err)
}
// check totals
if eventStore.Total(ctx) != 1 {
t.Fatalf("wrong total %d", eventStore.Total(ctx))
}
// reset database
if err := eventStore.Reset(ctx); err != nil {
t.Fatal(err)
}
// close connection
if err := eventStore.Close(ctx); err != nil {
t.Fatalf("failed to close connection: %v", err)
}
}
func TestEventStoreWithEncrypted(t *testing.T) {
var err error
ctx := context.Background()
// create crypto service
key := []byte("12345678901234567890123456789012")
cryptoService, _ := comby.NewCryptoService(key)
// setup and init store
eventStore := store.NewEventStorePostgres("localhost", 5432, "postgres", "mysecretpassword", "postgres")
if err = eventStore.Init(ctx,
comby.EventStoreOptionWithCryptoService(cryptoService),
); err != nil {
t.Fatal(err)
}
// create domain data to encrypt/decrypt
type MyDomainEvent struct {
String string
Int int64
Boolean bool
}
domainData := &MyDomainEvent{
String: "string",
Int: 123,
Boolean: true,
}
// Create values
evt1 := &comby.BaseEvent{
EventUuid: comby.NewUuid(),
AggregateUuid: "AggregateUuid_1",
Domain: "Domain_1",
CreatedAt: 1000,
Version: 1,
DomainEvt: domainData,
}
if err := eventStore.Create(ctx,
comby.EventStoreCreateOptionWithEvent(evt1),
); err != nil {
t.Fatal(err)
}
// Get a value
if _evt1, err := eventStore.Get(ctx,
comby.EventStoreGetOptionWithEventUuid(evt1.EventUuid),
); err != nil {
t.Fatal(err)
} else {
_domainData := &MyDomainEvent{}
_domainData, _ = comby.Deserialize(_evt1.GetDomainEvtBytes(), _domainData)
if _domainData.String != "string" {
t.Fatalf("wrong value: %q", _domainData.String)
}
if _domainData.Int != 123 {
t.Fatalf("wrong value: %q", _domainData.Int)
}
if _domainData.Boolean != true {
t.Fatalf("wrong value")
}
}
// List all events
if evts, _, err := eventStore.List(ctx); err == nil {
_evt1 := evts[0]
_domainData := &MyDomainEvent{}
_domainData, _ = comby.Deserialize(_evt1.GetDomainEvtBytes(), _domainData)
if _domainData.String != "string" {
t.Fatalf("wrong value: %q", _domainData.String)
}
if _domainData.Int != 123 {
t.Fatalf("wrong value: %q", _domainData.Int)
}
if _domainData.Boolean != true {
t.Fatalf("wrong value")
}
}
// Update event
domainData.String = "string2"
domainData.Int = 456
domainData.Boolean = false
evt1.DomainEvt = domainData
if err := eventStore.Update(ctx,
comby.EventStoreUpdateOptionWithEvent(evt1),
); err != nil {
t.Fatal(err)
}
// Get a value
if _evt1, err := eventStore.Get(ctx,
comby.EventStoreGetOptionWithEventUuid(evt1.EventUuid),
); err != nil {
t.Fatal(err)
} else {
_domainData := &MyDomainEvent{}
_domainData, _ = comby.Deserialize(_evt1.GetDomainEvtBytes(), _domainData)
if _domainData.String != "string2" {
t.Fatalf("wrong value: %q", _domainData.String)
}
if _domainData.Int != 456 {
t.Fatalf("wrong value: %q", _domainData.Int)
}
if _domainData.Boolean != false {
t.Fatalf("wrong value")
}
}
// reset database
if err := eventStore.Reset(ctx); err != nil {
t.Fatal(err)
}
// close connection
if err := eventStore.Close(ctx); err != nil {
t.Fatalf("failed to close connection: %v", err)
}
}
func TestEventStoreFieldLoading(t *testing.T) {
var err error
ctx := context.Background()
// setup and init store
eventStore := store.NewEventStorePostgres("localhost", 5432, "postgres", "mysecretpassword", "postgres")
if err = eventStore.Init(ctx); err != nil {
t.Fatal(err)
}
// Define a domain event type with various fields
type ComplexDomainEvent struct {
StringField string
IntField int64
BoolField bool
FloatField float64
ArrayField []string
NestedObject struct {
Name string
Value int
}
}
// Create a comprehensive test event with all fields populated
testData := &ComplexDomainEvent{
StringField: "test-string-value",
IntField: 42,
BoolField: true,
FloatField: 3.14159,
ArrayField: []string{"item1", "item2", "item3"},
NestedObject: struct {
Name string
Value int
}{
Name: "nested",
Value: 999,
},
}
evt := &comby.BaseEvent{
InstanceId: 123,
EventUuid: comby.NewUuid(),
TenantUuid: "tenant-uuid-123",
CommandUuid: "command-uuid-456",
AggregateUuid: "aggregate-uuid-789",
Domain: "test-domain",
Version: 5,
CreatedAt: 1234567890,
DomainEvt: testData,
}
// Create the event
if err := eventStore.Create(ctx,
comby.EventStoreCreateOptionWithEvent(evt),
); err != nil {
t.Fatal(err)
}
// Test 1: Get the event and verify ALL fields are loaded
t.Run("Get - Verify all fields loaded", func(t *testing.T) {
loadedEvt, err := eventStore.Get(ctx,
comby.EventStoreGetOptionWithEventUuid(evt.EventUuid),
)
if err != nil {
t.Fatalf("failed to get event: %v", err)
}
if loadedEvt == nil {
t.Fatal("loaded event is nil")
}
// Verify all base fields
if loadedEvt.GetInstanceId() != 123 {
t.Errorf("InstanceId: expected 123, got %d", loadedEvt.GetInstanceId())
}
if loadedEvt.GetEventUuid() != evt.EventUuid {
t.Errorf("EventUuid: expected %s, got %s", evt.EventUuid, loadedEvt.GetEventUuid())
}
if loadedEvt.GetTenantUuid() != "tenant-uuid-123" {
t.Errorf("TenantUuid: expected 'tenant-uuid-123', got %s", loadedEvt.GetTenantUuid())
}
if loadedEvt.GetCommandUuid() != "command-uuid-456" {
t.Errorf("CommandUuid: expected 'command-uuid-456', got %s", loadedEvt.GetCommandUuid())
}
if loadedEvt.GetAggregateUuid() != "aggregate-uuid-789" {
t.Errorf("AggregateUuid: expected 'aggregate-uuid-789', got %s", loadedEvt.GetAggregateUuid())
}
if loadedEvt.GetDomain() != "test-domain" {
t.Errorf("Domain: expected 'test-domain', got %s", loadedEvt.GetDomain())
}
if loadedEvt.GetVersion() != 5 {
t.Errorf("Version: expected 5, got %d", loadedEvt.GetVersion())
}
if loadedEvt.GetCreatedAt() != 1234567890 {
t.Errorf("CreatedAt: expected 1234567890, got %d", loadedEvt.GetCreatedAt())
}
// CRITICAL: Verify data_bytes is not empty
dataBytes := loadedEvt.GetDomainEvtBytes()
if len(dataBytes) == 0 {
t.Fatal("CRITICAL: data_bytes is empty after loading")
}
// Verify data_type is set
dataType := loadedEvt.GetDomainEvtName()
if len(dataType) == 0 {
t.Fatal("CRITICAL: data_type is empty after loading")
}
// Deserialize and verify the domain data
loadedData := &ComplexDomainEvent{}
loadedData, err = comby.Deserialize(dataBytes, loadedData)
if err != nil {
t.Fatalf("failed to deserialize domain data: %v", err)
}
// Verify all domain data fields
if loadedData.StringField != "test-string-value" {
t.Errorf("StringField: expected 'test-string-value', got %s", loadedData.StringField)
}
if loadedData.IntField != 42 {
t.Errorf("IntField: expected 42, got %d", loadedData.IntField)
}
if loadedData.BoolField != true {
t.Errorf("BoolField: expected true, got %v", loadedData.BoolField)
}
if loadedData.FloatField != 3.14159 {
t.Errorf("FloatField: expected 3.14159, got %f", loadedData.FloatField)
}
if len(loadedData.ArrayField) != 3 {
t.Errorf("ArrayField length: expected 3, got %d", len(loadedData.ArrayField))
}
if loadedData.NestedObject.Name != "nested" {
t.Errorf("NestedObject.Name: expected 'nested', got %s", loadedData.NestedObject.Name)
}
if loadedData.NestedObject.Value != 999 {
t.Errorf("NestedObject.Value: expected 999, got %d", loadedData.NestedObject.Value)
}
})
// Test 2: List events and verify ALL fields are loaded
t.Run("List - Verify all fields loaded", func(t *testing.T) {
evts, total, err := eventStore.List(ctx)
if err != nil {
t.Fatalf("failed to list events: %v", err)
}
if total != 1 {
t.Fatalf("expected 1 event, got %d", total)
}
if len(evts) != 1 {
t.Fatalf("expected 1 event in list, got %d", len(evts))
}
loadedEvt := evts[0]
// Verify all base fields
if loadedEvt.GetInstanceId() != 123 {
t.Errorf("InstanceId: expected 123, got %d", loadedEvt.GetInstanceId())
}
if loadedEvt.GetTenantUuid() != "tenant-uuid-123" {
t.Errorf("TenantUuid: expected 'tenant-uuid-123', got %s", loadedEvt.GetTenantUuid())
}
if loadedEvt.GetCommandUuid() != "command-uuid-456" {
t.Errorf("CommandUuid: expected 'command-uuid-456', got %s", loadedEvt.GetCommandUuid())
}
// CRITICAL: Verify data_bytes is not empty in List
dataBytes := loadedEvt.GetDomainEvtBytes()
if len(dataBytes) == 0 {
t.Fatal("CRITICAL: data_bytes is empty after List()")
}
// Verify data_type is set
dataType := loadedEvt.GetDomainEvtName()
if len(dataType) == 0 {
t.Fatal("CRITICAL: data_type is empty after List()")
}
// Deserialize and verify the domain data
loadedData := &ComplexDomainEvent{}
loadedData, err = comby.Deserialize(dataBytes, loadedData)
if err != nil {
t.Fatalf("failed to deserialize domain data from List: %v", err)
}
// Verify critical fields
if loadedData.StringField != "test-string-value" {
t.Errorf("List - StringField: expected 'test-string-value', got %s", loadedData.StringField)
}
if loadedData.IntField != 42 {
t.Errorf("List - IntField: expected 42, got %d", loadedData.IntField)
}
})
// reset database
if err := eventStore.Reset(ctx); err != nil {
t.Fatal(err)
}
// close connection
if err := eventStore.Close(ctx); err != nil {
t.Fatalf("failed to close connection: %v", err)
}
}
// Helper function to create test events with all fields populated (except runtime fields)
func createTestEvent(tenantUuid, domain string, version int64, createdAt int64) comby.Event {
evt := comby.NewBaseEvent()
evt.SetInstanceId(1)
evt.SetTenantUuid(tenantUuid)
evt.SetCommandUuid(fmt.Sprintf("command-%d", version))
evt.SetDomain(domain)
evt.SetAggregateUuid(fmt.Sprintf("aggregate-%d", version))
evt.SetVersion(version)
evt.SetDomainEvtName(fmt.Sprintf("TestEvent_%d", version))
evt.SetDomainEvtBytes([]byte(fmt.Sprintf("test-data-%d", version)))
evt.SetCreatedAt(createdAt)
return evt
}
// Test: PostgreSQL to PostgreSQL - Validate complete event data is copied (including DomainEvtBytes)
// This test specifically addresses the reported issue where data_bytes are missing after copying
// between PostgreSQL event stores.
func TestSyncEventStore_ValidateCompleteEventData(t *testing.T) {
ctx := context.Background()
// Create PostgreSQL event stores
source := store.NewEventStorePostgres("localhost", 5432, "postgres", "mysecretpassword", "postgres")
destination := store.NewEventStorePostgres("localhost", 5432, "postgres", "mysecretpassword", "postgres")
// Initialize stores
if err := source.Init(ctx); err != nil {
t.Fatalf("Failed to init source PostgreSQL store: %v", err)
}
defer source.Close(ctx)
if err := destination.Init(ctx); err != nil {
t.Fatalf("Failed to init destination PostgreSQL store: %v", err)
}
defer destination.Close(ctx)
// Reset both stores to ensure clean state
if err := source.Reset(ctx); err != nil {
t.Fatalf("Failed to reset source store: %v", err)
}
if err := destination.Reset(ctx); err != nil {
t.Fatalf("Failed to reset destination store: %v", err)
}
// Create test events with all fields populated and various data sizes
startTime := time.Now().Unix()
testEvents := []comby.Event{
createTestEvent("tenant-1", "user-domain", 1, startTime),
createTestEvent("tenant-1", "order-domain", 2, startTime+1),
createTestEvent("tenant-2", "product-domain", 3, startTime+2),
createTestEvent("tenant-2", "inventory-domain", 4, startTime+3),
createTestEvent("tenant-3", "payment-domain", 5, startTime+4),
}
// Set DomainEvtBytes with different sizes to ensure all data is copied
testEvents[0].SetDomainEvtBytes([]byte("small-payload"))
testEvents[1].SetDomainEvtBytes([]byte("medium-payload-with-more-content-for-testing"))
// Create large payload with actual text content (PostgreSQL doesn't accept null bytes in text fields)
largePayload := "large-payload-"
for i := 0; i < 500; i++ {
largePayload += "x"
}
testEvents[2].SetDomainEvtBytes([]byte(largePayload))
testEvents[3].SetDomainEvtBytes([]byte(`{"type":"json","data":{"key":"value","nested":{"field":"data"}}}`))
// Create very large payload with actual text content
veryLargePayload := "very-large-payload-"
for i := 0; i < 2000; i++ {
veryLargePayload += "y"
}
testEvents[4].SetDomainEvtBytes([]byte(veryLargePayload))
// Additional field customization
testEvents[0].SetDomainEvtName("UserCreated")
testEvents[1].SetDomainEvtName("OrderPlaced")
testEvents[2].SetDomainEvtName("ProductAdded")
testEvents[3].SetDomainEvtName("InventoryUpdated")
testEvents[4].SetDomainEvtName("PaymentProcessed")
// Store all events in source
for i, evt := range testEvents {
if err := source.Create(ctx, comby.EventStoreCreateOptionWithEvent(evt)); err != nil {
t.Fatalf("Failed to create event %d in source PostgreSQL store: %v", i, err)
}
}
// Verify source has all events
sourceTotal := source.Total(ctx)
if sourceTotal != int64(len(testEvents)) {
t.Fatalf("Source store should have %d events, got %d", len(testEvents), sourceTotal)
}
// Sync from PostgreSQL source to PostgreSQL destination
err := comby.SyncEventStore(ctx, source, destination)
if err != nil {
t.Fatalf("Sync from PostgreSQL to PostgreSQL failed: %v", err)
}
// Verify count matches
destTotal := destination.Total(ctx)
if sourceTotal != destTotal {
t.Fatalf("Event count mismatch after sync: source=%d, destination=%d", sourceTotal, destTotal)
}
// Retrieve all events from both stores for field-by-field comparison
sourceEvents, _, err := source.List(ctx, comby.EventStoreListOptionOrderBy("created_at"), comby.EventStoreListOptionAscending(true))
if err != nil {
t.Fatalf("Failed to list source events: %v", err)
}
destEvents, _, err := destination.List(ctx, comby.EventStoreListOptionOrderBy("created_at"), comby.EventStoreListOptionAscending(true))
if err != nil {
t.Fatalf("Failed to list destination events: %v", err)
}
if len(sourceEvents) != len(destEvents) {
t.Fatalf("Event list length mismatch: source=%d, destination=%d", len(sourceEvents), len(destEvents))
}
// Validate EVERY field for EVERY event
for i := 0; i < len(sourceEvents); i++ {
srcEvt := sourceEvents[i]
dstEvt := destEvents[i]
// Instance ID
if srcEvt.GetInstanceId() != dstEvt.GetInstanceId() {
t.Errorf("Event %d: InstanceId mismatch: source=%d, dest=%d", i, srcEvt.GetInstanceId(), dstEvt.GetInstanceId())
}
// Event UUID
if srcEvt.GetEventUuid() != dstEvt.GetEventUuid() {
t.Errorf("Event %d: EventUuid mismatch: source=%s, dest=%s", i, srcEvt.GetEventUuid(), dstEvt.GetEventUuid())
}
// Tenant UUID
if srcEvt.GetTenantUuid() != dstEvt.GetTenantUuid() {
t.Errorf("Event %d: TenantUuid mismatch: source=%s, dest=%s", i, srcEvt.GetTenantUuid(), dstEvt.GetTenantUuid())
}
// Command UUID
if srcEvt.GetCommandUuid() != dstEvt.GetCommandUuid() {
t.Errorf("Event %d: CommandUuid mismatch: source=%s, dest=%s", i, srcEvt.GetCommandUuid(), dstEvt.GetCommandUuid())
}
// Domain
if srcEvt.GetDomain() != dstEvt.GetDomain() {
t.Errorf("Event %d: Domain mismatch: source=%s, dest=%s", i, srcEvt.GetDomain(), dstEvt.GetDomain())
}
// Aggregate UUID
if srcEvt.GetAggregateUuid() != dstEvt.GetAggregateUuid() {
t.Errorf("Event %d: AggregateUuid mismatch: source=%s, dest=%s", i, srcEvt.GetAggregateUuid(), dstEvt.GetAggregateUuid())
}
// Version
if srcEvt.GetVersion() != dstEvt.GetVersion() {
t.Errorf("Event %d: Version mismatch: source=%d, dest=%d", i, srcEvt.GetVersion(), dstEvt.GetVersion())
}
// Domain Event Name
if srcEvt.GetDomainEvtName() != dstEvt.GetDomainEvtName() {
t.Errorf("Event %d: DomainEvtName mismatch: source=%s, dest=%s", i, srcEvt.GetDomainEvtName(), dstEvt.GetDomainEvtName())
}
// Created At
if srcEvt.GetCreatedAt() != dstEvt.GetCreatedAt() {
t.Errorf("Event %d: CreatedAt mismatch: source=%d, dest=%d", i, srcEvt.GetCreatedAt(), dstEvt.GetCreatedAt())
}
// CRITICAL TEST: DomainEvtBytes (data_bytes) - THIS IS THE REPORTED BUG!
srcBytes := srcEvt.GetDomainEvtBytes()
dstBytes := dstEvt.GetDomainEvtBytes()
// Check if bytes exist
if len(srcBytes) == 0 {
t.Errorf("Event %d: Source DomainEvtBytes is empty! This should not happen.", i)
}
if len(dstBytes) == 0 {
t.Errorf("Event %d: CRITICAL BUG - Destination DomainEvtBytes is empty! data_bytes were not copied from PostgreSQL source.", i)
}
// Check length matches
if len(srcBytes) != len(dstBytes) {
t.Errorf("Event %d: DomainEvtBytes length mismatch: source=%d bytes, dest=%d bytes",
i, len(srcBytes), len(dstBytes))
t.Errorf(" Source data (first 100 chars): %q", string(srcBytes[:min(100, len(srcBytes))]))
if len(dstBytes) > 0 {
t.Errorf(" Dest data (first 100 chars): %q", string(dstBytes[:min(100, len(dstBytes))]))
} else {
t.Errorf(" Dest data: EMPTY (BUG!)")
}
}
// Check content matches byte-for-byte
if len(srcBytes) > 0 && len(dstBytes) > 0 {
if string(srcBytes) != string(dstBytes) {
t.Errorf("Event %d: DomainEvtBytes content mismatch!", i)
t.Errorf(" Source (%d bytes): %q", len(srcBytes), string(srcBytes[:min(200, len(srcBytes))]))
t.Errorf(" Dest (%d bytes): %q", len(dstBytes), string(dstBytes[:min(200, len(dstBytes))]))
}
}
}
}
// Helper function for min
func min(a, b int) int {
if a < b {
return a
}
return b
}