@@ -1427,3 +1427,91 @@ func Test_augmentWorkerOptions(t *testing.T) {
14271427 })
14281428 }
14291429}
1430+
1431+ func TestValidateFnFormat_Activity (t * testing.T ) {
1432+ for _ , tc := range []struct {
1433+ name string
1434+ fn any
1435+ wantErr string
1436+ }{
1437+ {
1438+ name : "not a function" ,
1439+ fn : 1 ,
1440+ wantErr : "expected a func as input" ,
1441+ },
1442+ {
1443+ name : "function without return" ,
1444+ fn : func () {},
1445+ wantErr : "expected function to return result" ,
1446+ },
1447+ {
1448+ name : "function with too many return values" ,
1449+ fn : func () (int , int , error ) { return 0 , 0 , nil },
1450+ wantErr : "expected function to return result" ,
1451+ },
1452+ {
1453+ name : "function without error" ,
1454+ fn : func () int { return 0 },
1455+ wantErr : "expected function second return value" ,
1456+ },
1457+ {
1458+ name : "function with error but in the wrong place" ,
1459+ fn : func () (error , int ) { return nil , 0 },
1460+ wantErr : "expected function second return value" ,
1461+ },
1462+ } {
1463+ t .Run (tc .name , func (t * testing.T ) {
1464+ err := validateFnFormat (reflect .TypeOf (tc .fn ), false )
1465+ assert .ErrorContains (t , err , tc .wantErr )
1466+ })
1467+ }
1468+ }
1469+
1470+ func TestTestValidateFnFormat_Workflow (t * testing.T ) {
1471+ for _ , tc := range []struct {
1472+ name string
1473+ fn any
1474+ wantErr string
1475+ }{
1476+ {
1477+ name : "not a function" ,
1478+ fn : 1 ,
1479+ wantErr : "expected a func as input" ,
1480+ },
1481+ {
1482+ name : "function without return" ,
1483+ fn : func (_ Context ) {},
1484+ wantErr : "expected function to return result" ,
1485+ },
1486+ {
1487+ name : "function with too many return values" ,
1488+ fn : func (_ Context ) (int , int , error ) { return 0 , 0 , nil },
1489+ wantErr : "expected function to return result" ,
1490+ },
1491+ {
1492+ name : "function without error" ,
1493+ fn : func (_ Context ) int { return 0 },
1494+ wantErr : "expected function second return value" ,
1495+ },
1496+ {
1497+ name : "function with error but in the wrong place" ,
1498+ fn : func (_ Context ) (error , int ) { return nil , 0 },
1499+ wantErr : "expected function second return value" ,
1500+ },
1501+ {
1502+ name : "workflow without args" ,
1503+ fn : func () error { return nil },
1504+ wantErr : "expected at least one argument of type workflow.Context" ,
1505+ },
1506+ {
1507+ name : "workflow with wrong args" ,
1508+ fn : func (int ) error { return nil },
1509+ wantErr : "expected first argument to be workflow.Context" ,
1510+ },
1511+ } {
1512+ t .Run (tc .name , func (t * testing.T ) {
1513+ err := validateFnFormat (reflect .TypeOf (tc .fn ), true )
1514+ assert .ErrorContains (t , err , tc .wantErr )
1515+ })
1516+ }
1517+ }
0 commit comments