@@ -425,3 +425,138 @@ outerLoop:
425425 }
426426 }
427427}
428+
429+ // Test structs for struct parameter tests
430+ type TestConfig struct {
431+ Name string
432+ Value int
433+ }
434+
435+ type TestData struct {
436+ ID int
437+ Message string
438+ Active bool
439+ }
440+
441+ // Task function that accepts a struct and pointer to struct
442+ func taskWithStructParams (config TestConfig , data * TestData ) (string , error ) {
443+ if data == nil {
444+ return "" , fmt .Errorf ("data cannot be nil" )
445+ }
446+ return fmt .Sprintf ("%s-%d: %s (ID: %d, Active: %t)" , config .Name , config .Value , data .Message , data .ID , data .Active ), nil
447+ }
448+
449+ // TestNewRunnerWithStructParameters tests the runner with struct and pointer-to-struct parameters
450+ func TestNewRunnerWithStructParameters (t * testing.T ) {
451+ tests := []struct {
452+ name string
453+ param1 interface {}
454+ param2 interface {}
455+ wantErr bool
456+ wantResult string
457+ }{
458+ {
459+ name : "Valid Struct and Pointer" ,
460+ param1 : TestConfig {
461+ Name : "config" ,
462+ Value : 42 ,
463+ },
464+ param2 : & TestData {
465+ ID : 1 ,
466+ Message : "test message" ,
467+ Active : true ,
468+ },
469+ wantErr : false ,
470+ wantResult : "config-42: test message (ID: 1, Active: true)" ,
471+ },
472+ {
473+ name : "Map to Struct and Map to Pointer Conversion" ,
474+ param1 : map [string ]interface {}{
475+ "Name" : "fromMap" ,
476+ "Value" : 99 ,
477+ },
478+ param2 : map [string ]interface {}{
479+ "ID" : 2 ,
480+ "Message" : "converted from map" ,
481+ "Active" : false ,
482+ },
483+ wantErr : false ,
484+ wantResult : "fromMap-99: converted from map (ID: 2, Active: false)" ,
485+ },
486+ {
487+ name : "Struct Value and Map to Pointer" ,
488+ param1 : TestConfig {
489+ Name : "direct" ,
490+ Value : 10 ,
491+ },
492+ param2 : map [string ]interface {}{
493+ "ID" : 3 ,
494+ "Message" : "mixed params" ,
495+ "Active" : true ,
496+ },
497+ wantErr : false ,
498+ wantResult : "direct-10: mixed params (ID: 3, Active: true)" ,
499+ },
500+ {
501+ name : "Map to Struct with Type Conversion" ,
502+ param1 : map [string ]interface {}{
503+ "Name" : "typeConv" ,
504+ "Value" : 25.0 , // float64 should convert to int
505+ },
506+ param2 : map [string ]interface {}{
507+ "ID" : 4.0 , // float64 should convert to int
508+ "Message" : "type conversion test" ,
509+ "Active" : true ,
510+ },
511+ wantErr : false ,
512+ wantResult : "typeConv-25: type conversion test (ID: 4, Active: true)" ,
513+ },
514+ }
515+
516+ for _ , test := range tests {
517+ t .Run (test .name , func (t * testing.T ) {
518+ mockTask , err := model .NewTask (taskWithStructParams )
519+ require .NoError (t , err , "Failed to create mock task" )
520+
521+ job := & model.Job {
522+ TaskName : mockTask .Name ,
523+ Parameters : []interface {}{
524+ test .param1 ,
525+ test .param2 ,
526+ },
527+ Options : & model.Options {
528+ OnError : & model.OnError {
529+ Timeout : 5.0 ,
530+ },
531+ },
532+ }
533+
534+ runner , err := NewRunnerFromJob (mockTask , job )
535+ if test .wantErr {
536+ assert .Error (t , err , "NewRunnerFromJob should return an error" )
537+ return
538+ }
539+
540+ require .NoError (t , err , "NewRunnerFromJob should not return an error" )
541+ assert .NotNil (t , runner )
542+
543+ go runner .Run (context .Background ())
544+
545+ outerLoop:
546+ for {
547+ select {
548+ case err := <- runner .ErrorChannel :
549+ assert .NoError (t , err , "Runner should not return an error" )
550+ break outerLoop
551+ case results := <- runner .ResultsChannel :
552+ assert .NotNil (t , results )
553+ assert .Len (t , results , 1 )
554+ assert .Equal (t , test .wantResult , results [0 ])
555+ break outerLoop
556+ case <- time .After (2 * time .Second ):
557+ t .Fatal ("Test timed out" )
558+ }
559+ }
560+ })
561+ }
562+ }
0 commit comments