77 "testing"
88 "time"
99
10+ "github.com/google/uuid"
1011 "github.com/siherrmann/queuer/model"
1112 "github.com/stretchr/testify/assert"
1213 "github.com/stretchr/testify/require"
@@ -434,6 +435,7 @@ type TestConfig struct {
434435
435436type TestData struct {
436437 ID int
438+ RID uuid.UUID
437439 Message string
438440 Active bool
439441}
@@ -450,15 +452,15 @@ func taskWithStructParams(config TestConfig, data *TestData) (string, error) {
450452 if data == nil {
451453 return "" , fmt .Errorf ("data cannot be nil" )
452454 }
453- return fmt .Sprintf ("%s-%d: %s (ID: %d, Active: %t)" , config .Name , config .Value , data .Message , data .ID , data .Active ), nil
455+ return fmt .Sprintf ("%s-%d: %s (ID: %d, RID: %s, Active: %t)" , config .Name , config .Value , data .Message , data .ID , data . RID . String () , data .Active ), nil
454456}
455457
456458// Task function that accepts a nested struct with both struct and pointer fields
457459func taskWithNestedStruct (nested NestedStruct ) (string , error ) {
458460 if nested .DataPtr == nil {
459461 return "" , fmt .Errorf ("nested.DataPtr cannot be nil" )
460462 }
461- return fmt .Sprintf ("%s: %s-%d | %s (ID: %d, Active: %t)" , nested .Metadata , nested .Config .Name , nested .Config .Value , nested .DataPtr .Message , nested .DataPtr .ID , nested .DataPtr .Active ), nil
463+ return fmt .Sprintf ("%s: %s-%d | %s (ID: %d, RID: %s, Active: %t)" , nested .Metadata , nested .Config .Name , nested .Config .Value , nested .DataPtr .Message , nested .DataPtr .ID , nested . DataPtr . RID . String () , nested .DataPtr .Active ), nil
462464}
463465
464466// TestNewRunnerWithStructParameters tests the runner with struct and pointer-to-struct parameters
@@ -478,11 +480,12 @@ func TestNewRunnerWithStructParameters(t *testing.T) {
478480 },
479481 param2 : & TestData {
480482 ID : 1 ,
483+ RID : uuid .MustParse ("550e8400-e29b-41d4-a716-446655440001" ),
481484 Message : "test message" ,
482485 Active : true ,
483486 },
484487 wantErr : false ,
485- wantResult : "config-42: test message (ID: 1, Active: true)" ,
488+ wantResult : "config-42: test message (ID: 1, RID: 550e8400-e29b-41d4-a716-446655440001, Active: true)" ,
486489 },
487490 {
488491 name : "Map to Struct and Map to Pointer Conversion" ,
@@ -492,11 +495,12 @@ func TestNewRunnerWithStructParameters(t *testing.T) {
492495 },
493496 param2 : map [string ]interface {}{
494497 "ID" : 2 ,
498+ "RID" : "550e8400-e29b-41d4-a716-446655440001" ,
495499 "Message" : "converted from map" ,
496500 "Active" : false ,
497501 },
498502 wantErr : false ,
499- wantResult : "fromMap-99: converted from map (ID: 2, Active: false)" ,
503+ wantResult : "fromMap-99: converted from map (ID: 2, RID: 550e8400-e29b-41d4-a716-446655440001, Active: false)" ,
500504 },
501505 {
502506 name : "Struct Value and Map to Pointer" ,
@@ -506,11 +510,12 @@ func TestNewRunnerWithStructParameters(t *testing.T) {
506510 },
507511 param2 : map [string ]interface {}{
508512 "ID" : 3 ,
513+ "RID" : "550e8400-e29b-41d4-a716-446655440001" ,
509514 "Message" : "mixed params" ,
510515 "Active" : true ,
511516 },
512517 wantErr : false ,
513- wantResult : "direct-10: mixed params (ID: 3, Active: true)" ,
518+ wantResult : "direct-10: mixed params (ID: 3, RID: 550e8400-e29b-41d4-a716-446655440001, Active: true)" ,
514519 },
515520 {
516521 name : "Map to Struct with Type Conversion" ,
@@ -520,11 +525,12 @@ func TestNewRunnerWithStructParameters(t *testing.T) {
520525 },
521526 param2 : map [string ]interface {}{
522527 "ID" : 4.0 , // float64 should convert to int
528+ "RID" : "550e8400-e29b-41d4-a716-446655440001" ,
523529 "Message" : "type conversion test" ,
524530 "Active" : true ,
525531 },
526532 wantErr : false ,
527- wantResult : "typeConv-25: type conversion test (ID: 4, Active: true)" ,
533+ wantResult : "typeConv-25: type conversion test (ID: 4, RID: 550e8400-e29b-41d4-a716-446655440001, Active: true)" ,
528534 },
529535 }
530536
@@ -593,13 +599,14 @@ func TestNewRunnerWithNestedStruct(t *testing.T) {
593599 },
594600 DataPtr : & TestData {
595601 ID : 10 ,
602+ RID : uuid .MustParse ("550e8400-e29b-41d4-a716-446655440001" ),
596603 Message : "nested data" ,
597604 Active : true ,
598605 },
599606 Metadata : "meta-direct" ,
600607 },
601608 wantErr : false ,
602- wantResult : "meta-direct: nested-config-100 | nested data (ID: 10, Active: true)" ,
609+ wantResult : "meta-direct: nested-config-100 | nested data (ID: 10, RID: 550e8400-e29b-41d4-a716-446655440001, Active: true)" ,
603610 },
604611 {
605612 name : "Map to Nested Struct Conversion" ,
@@ -610,13 +617,14 @@ func TestNewRunnerWithNestedStruct(t *testing.T) {
610617 },
611618 "DataPtr" : map [string ]interface {}{
612619 "ID" : 20 ,
620+ "RID" : "550e8400-e29b-41d4-a716-446655440001" ,
613621 "Message" : "map data" ,
614622 "Active" : false ,
615623 },
616624 "Metadata" : "meta-from-map" ,
617625 },
618626 wantErr : false ,
619- wantResult : "meta-from-map: map-config-200 | map data (ID: 20, Active: false)" ,
627+ wantResult : "meta-from-map: map-config-200 | map data (ID: 20, RID: 550e8400-e29b-41d4-a716-446655440001, Active: false)" ,
620628 },
621629 {
622630 name : "Map with Type Conversions in Nested Struct" ,
@@ -627,13 +635,14 @@ func TestNewRunnerWithNestedStruct(t *testing.T) {
627635 },
628636 "DataPtr" : map [string ]interface {}{
629637 "ID" : 30.0 , // float64 to int
638+ "RID" : "550e8400-e29b-41d4-a716-446655440001" ,
630639 "Message" : "type conversion" ,
631640 "Active" : true ,
632641 },
633642 "Metadata" : "meta-type-conv" ,
634643 },
635644 wantErr : false ,
636- wantResult : "meta-type-conv: type-conv-300 | type conversion (ID: 30, Active: true)" ,
645+ wantResult : "meta-type-conv: type-conv-300 | type conversion (ID: 30, RID: 550e8400-e29b-41d4-a716-446655440001, Active: true)" ,
637646 },
638647 }
639648
0 commit comments