Skip to content

Commit 344149c

Browse files
committed
simplify
1 parent 8576172 commit 344149c

File tree

1 file changed

+23
-70
lines changed

1 file changed

+23
-70
lines changed

dbos/serialization_test.go

Lines changed: 23 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -589,78 +589,31 @@ func serializerAnyValueWorkflow(ctx DBOSContext, input any) (any, error) {
589589
})
590590
}
591591

592-
// Typed workflow functions for testing concrete signatures
593-
func serializerIntWorkflow(ctx DBOSContext, input int) (int, error) {
594-
return RunAsStep(ctx, func(context context.Context) (int, error) {
595-
return input, nil
596-
})
597-
}
598-
599-
func serializerIntPtrWorkflow(ctx DBOSContext, input *int) (*int, error) {
600-
return RunAsStep(ctx, func(context context.Context) (*int, error) {
601-
return input, nil
602-
})
603-
}
604-
605-
func serializerIntSliceWorkflow(ctx DBOSContext, input []int) ([]int, error) {
606-
return RunAsStep(ctx, func(context context.Context) ([]int, error) {
607-
return input, nil
608-
})
609-
}
610-
611-
func serializerStringIntMapWorkflow(ctx DBOSContext, input map[string]int) (map[string]int, error) {
612-
return RunAsStep(ctx, func(context context.Context) (map[string]int, error) {
613-
return input, nil
614-
})
615-
}
616-
617-
func serializerWithInterfacesWorkflow(ctx DBOSContext, input WithInterfaces) (WithInterfaces, error) {
618-
return RunAsStep(ctx, func(context context.Context) (WithInterfaces, error) {
619-
return input, nil
620-
})
621-
}
622-
623-
func serializerMyIntWorkflow(ctx DBOSContext, input MyInt) (MyInt, error) {
624-
return RunAsStep(ctx, func(context context.Context) (MyInt, error) {
625-
return input, nil
626-
})
627-
}
628-
629-
func serializerMyStringWorkflow(ctx DBOSContext, input MyString) (MyString, error) {
630-
return RunAsStep(ctx, func(context context.Context) (MyString, error) {
631-
return input, nil
632-
})
633-
}
634-
635-
func serializerMyStringSliceWorkflow(ctx DBOSContext, input []MyString) ([]MyString, error) {
636-
return RunAsStep(ctx, func(context context.Context) ([]MyString, error) {
637-
return input, nil
638-
})
639-
}
640-
641-
func serializerStringMyIntMapWorkflow(ctx DBOSContext, input map[string]MyInt) (map[string]MyInt, error) {
642-
return RunAsStep(ctx, func(context context.Context) (map[string]MyInt, error) {
643-
return input, nil
644-
})
645-
}
646-
647-
func serializerTwiceIntWorkflow(ctx DBOSContext, input TwiceInt) (TwiceInt, error) {
648-
return RunAsStep(ctx, func(context context.Context) (TwiceInt, error) {
649-
return input, nil
650-
})
651-
}
652-
653-
func serializerStringWorkflow(ctx DBOSContext, input string) (string, error) {
654-
return RunAsStep(ctx, func(context context.Context) (string, error) {
655-
return input, nil
656-
})
592+
// makeTestWorkflow creates a generic workflow that simply returns the input.
593+
func makeTestWorkflow[T any]() Workflow[T, T] {
594+
return func(ctx DBOSContext, input T) (T, error) {
595+
return RunAsStep(ctx, func(context context.Context) (T, error) {
596+
return input, nil
597+
})
598+
}
657599
}
658600

659-
func serializerBoolWorkflow(ctx DBOSContext, input bool) (bool, error) {
660-
return RunAsStep(ctx, func(context context.Context) (bool, error) {
661-
return input, nil
662-
})
663-
}
601+
// Typed workflow functions for testing concrete signatures
602+
// These are now generated using makeTestWorkflow to reduce boilerplate
603+
var (
604+
serializerIntWorkflow = makeTestWorkflow[int]()
605+
serializerIntPtrWorkflow = makeTestWorkflow[*int]()
606+
serializerIntSliceWorkflow = makeTestWorkflow[[]int]()
607+
serializerStringIntMapWorkflow = makeTestWorkflow[map[string]int]()
608+
serializerWithInterfacesWorkflow = makeTestWorkflow[WithInterfaces]()
609+
serializerMyIntWorkflow = makeTestWorkflow[MyInt]()
610+
serializerMyStringWorkflow = makeTestWorkflow[MyString]()
611+
serializerMyStringSliceWorkflow = makeTestWorkflow[[]MyString]()
612+
serializerStringMyIntMapWorkflow = makeTestWorkflow[map[string]MyInt]()
613+
serializerTwiceIntWorkflow = makeTestWorkflow[TwiceInt]()
614+
serializerStringWorkflow = makeTestWorkflow[string]()
615+
serializerBoolWorkflow = makeTestWorkflow[bool]()
616+
)
664617

665618
// Typed Send/Recv workflows for various types
666619
func serializerIntSenderWorkflow(ctx DBOSContext, input int) (int, error) {

0 commit comments

Comments
 (0)