Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions core/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"
"time"

"github.com/google/uuid"
"github.com/siherrmann/queuer/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -434,6 +435,7 @@ type TestConfig struct {

type TestData struct {
ID int
RID uuid.UUID
Message string
Active bool
}
Expand All @@ -450,15 +452,15 @@ func taskWithStructParams(config TestConfig, data *TestData) (string, error) {
if data == nil {
return "", fmt.Errorf("data cannot be nil")
}
return fmt.Sprintf("%s-%d: %s (ID: %d, Active: %t)", config.Name, config.Value, data.Message, data.ID, data.Active), nil
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
}

// Task function that accepts a nested struct with both struct and pointer fields
func taskWithNestedStruct(nested NestedStruct) (string, error) {
if nested.DataPtr == nil {
return "", fmt.Errorf("nested.DataPtr cannot be nil")
}
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
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
}

// TestNewRunnerWithStructParameters tests the runner with struct and pointer-to-struct parameters
Expand All @@ -478,11 +480,12 @@ func TestNewRunnerWithStructParameters(t *testing.T) {
},
param2: &TestData{
ID: 1,
RID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440001"),
Message: "test message",
Active: true,
},
wantErr: false,
wantResult: "config-42: test message (ID: 1, Active: true)",
wantResult: "config-42: test message (ID: 1, RID: 550e8400-e29b-41d4-a716-446655440001, Active: true)",
},
{
name: "Map to Struct and Map to Pointer Conversion",
Expand All @@ -492,11 +495,12 @@ func TestNewRunnerWithStructParameters(t *testing.T) {
},
param2: map[string]interface{}{
"ID": 2,
"RID": "550e8400-e29b-41d4-a716-446655440001",
"Message": "converted from map",
"Active": false,
},
wantErr: false,
wantResult: "fromMap-99: converted from map (ID: 2, Active: false)",
wantResult: "fromMap-99: converted from map (ID: 2, RID: 550e8400-e29b-41d4-a716-446655440001, Active: false)",
},
{
name: "Struct Value and Map to Pointer",
Expand All @@ -506,11 +510,12 @@ func TestNewRunnerWithStructParameters(t *testing.T) {
},
param2: map[string]interface{}{
"ID": 3,
"RID": "550e8400-e29b-41d4-a716-446655440001",
"Message": "mixed params",
"Active": true,
},
wantErr: false,
wantResult: "direct-10: mixed params (ID: 3, Active: true)",
wantResult: "direct-10: mixed params (ID: 3, RID: 550e8400-e29b-41d4-a716-446655440001, Active: true)",
},
{
name: "Map to Struct with Type Conversion",
Expand All @@ -520,11 +525,12 @@ func TestNewRunnerWithStructParameters(t *testing.T) {
},
param2: map[string]interface{}{
"ID": 4.0, // float64 should convert to int
"RID": "550e8400-e29b-41d4-a716-446655440001",
"Message": "type conversion test",
"Active": true,
},
wantErr: false,
wantResult: "typeConv-25: type conversion test (ID: 4, Active: true)",
wantResult: "typeConv-25: type conversion test (ID: 4, RID: 550e8400-e29b-41d4-a716-446655440001, Active: true)",
},
}

Expand Down Expand Up @@ -593,13 +599,14 @@ func TestNewRunnerWithNestedStruct(t *testing.T) {
},
DataPtr: &TestData{
ID: 10,
RID: uuid.MustParse("550e8400-e29b-41d4-a716-446655440001"),
Message: "nested data",
Active: true,
},
Metadata: "meta-direct",
},
wantErr: false,
wantResult: "meta-direct: nested-config-100 | nested data (ID: 10, Active: true)",
wantResult: "meta-direct: nested-config-100 | nested data (ID: 10, RID: 550e8400-e29b-41d4-a716-446655440001, Active: true)",
},
{
name: "Map to Nested Struct Conversion",
Expand All @@ -610,13 +617,14 @@ func TestNewRunnerWithNestedStruct(t *testing.T) {
},
"DataPtr": map[string]interface{}{
"ID": 20,
"RID": "550e8400-e29b-41d4-a716-446655440001",
"Message": "map data",
"Active": false,
},
"Metadata": "meta-from-map",
},
wantErr: false,
wantResult: "meta-from-map: map-config-200 | map data (ID: 20, Active: false)",
wantResult: "meta-from-map: map-config-200 | map data (ID: 20, RID: 550e8400-e29b-41d4-a716-446655440001, Active: false)",
},
{
name: "Map with Type Conversions in Nested Struct",
Expand All @@ -627,13 +635,14 @@ func TestNewRunnerWithNestedStruct(t *testing.T) {
},
"DataPtr": map[string]interface{}{
"ID": 30.0, // float64 to int
"RID": "550e8400-e29b-41d4-a716-446655440001",
"Message": "type conversion",
"Active": true,
},
"Metadata": "meta-type-conv",
},
wantErr: false,
wantResult: "meta-type-conv: type-conv-300 | type conversion (ID: 30, Active: true)",
wantResult: "meta-type-conv: type-conv-300 | type conversion (ID: 30, RID: 550e8400-e29b-41d4-a716-446655440001, Active: true)",
},
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ require (
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/shirou/gopsutil/v4 v4.25.10 // indirect
github.com/siherrmann/queuerSql v0.0.0-20251130135331-9ed23b19fae5
github.com/siherrmann/validator v0.12.0
github.com/siherrmann/validator v0.15.0
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cobra v1.10.1
github.com/tklauser/go-sysconf v0.3.16 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shirou/gopsutil/v4 v4.25.10 h1:at8lk/5T1OgtuCp+AwrDofFRjnvosn0nkN2OLQ6g8tA=
github.com/shirou/gopsutil/v4 v4.25.10/go.mod h1:+kSwyC8DRUD9XXEHCAFjK+0nuArFJM0lva+StQAcskM=
github.com/siherrmann/validator v0.12.0 h1:bW80s6cXVuqIYPWCB8nboXryJWVog1C+XOQW72XovbE=
github.com/siherrmann/validator v0.12.0/go.mod h1:LqNNViIg5YKzO4SX4zMdafyffL6xCWuRqSyt1szpolo=
github.com/siherrmann/validator v0.15.0 h1:5mnBDsExYA+7w+w5r5aPo3nL3Nlv8EI0PUYrXEXj+Lw=
github.com/siherrmann/validator v0.15.0/go.mod h1:EO/YNTu2qDR7JPR7sPPjurlm+35G/HAijykBJxVFezE=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s=
Expand Down