Skip to content

Commit 91fa053

Browse files
authored
add support for uuid (#24)
1 parent 064d9d0 commit 91fa053

3 files changed

Lines changed: 21 additions & 12 deletions

File tree

core/runner_test.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
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

435436
type 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
457459
func 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

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ require (
6868
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
6969
github.com/shirou/gopsutil/v4 v4.25.10 // indirect
7070
github.com/siherrmann/queuerSql v0.0.0-20251130135331-9ed23b19fae5
71-
github.com/siherrmann/validator v0.12.0
71+
github.com/siherrmann/validator v0.15.0
7272
github.com/sirupsen/logrus v1.9.3 // indirect
7373
github.com/spf13/cobra v1.10.1
7474
github.com/tklauser/go-sysconf v0.3.16 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7
127127
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
128128
github.com/shirou/gopsutil/v4 v4.25.10 h1:at8lk/5T1OgtuCp+AwrDofFRjnvosn0nkN2OLQ6g8tA=
129129
github.com/shirou/gopsutil/v4 v4.25.10/go.mod h1:+kSwyC8DRUD9XXEHCAFjK+0nuArFJM0lva+StQAcskM=
130-
github.com/siherrmann/validator v0.12.0 h1:bW80s6cXVuqIYPWCB8nboXryJWVog1C+XOQW72XovbE=
131-
github.com/siherrmann/validator v0.12.0/go.mod h1:LqNNViIg5YKzO4SX4zMdafyffL6xCWuRqSyt1szpolo=
130+
github.com/siherrmann/validator v0.15.0 h1:5mnBDsExYA+7w+w5r5aPo3nL3Nlv8EI0PUYrXEXj+Lw=
131+
github.com/siherrmann/validator v0.15.0/go.mod h1:EO/YNTu2qDR7JPR7sPPjurlm+35G/HAijykBJxVFezE=
132132
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
133133
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
134134
github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s=

0 commit comments

Comments
 (0)