Accept ConfigKit integers in module options

This commit is contained in:
2026-09-13 16:41:14 +00:00
parent cf17dd7bd0
commit d770e19c17
7 changed files with 72 additions and 4 deletions

View File

@@ -155,7 +155,7 @@ func nonNegativeIntOption(name string, value any) (int, error) {
}
func intOption(name string, value any) (int, error) {
got, ok := value.(int)
got, ok := pipeline.IntOption(value)
if !ok {
return 0, chunkerErrorf("%s must be an integer", name)
}

View File

@@ -121,9 +121,19 @@ func TestPlanRejectsInvalidOptions(t *testing.T) {
}
}
func TestDecodeOptionsRejectsNonNativeIntegers(t *testing.T) {
func TestDecodeOptionsAcceptsConfigKitIntegers(t *testing.T) {
options, err := DecodeOptions(map[string]any{"max_units": int64(2), "overlap_units": int64(1)})
if err != nil {
t.Fatalf("DecodeOptions() error = %v", err)
}
if options.MaxUnits != 2 || options.OverlapUnits != 1 {
t.Fatalf("DecodeOptions() = %#v", options)
}
}
func TestDecodeOptionsRejectsUnsupportedIntegerRepresentations(t *testing.T) {
for _, value := range []any{
int8(2), int16(2), int32(2), int64(2),
int8(2), int16(2), int32(2),
uint(2), uint8(2), uint16(2), uint32(2), uint64(2),
float32(2), float64(2), json.Number("2"),
} {