From e4f87f1cd7de9a84e715bf352463e2a06042ba90 Mon Sep 17 00:00:00 2001 From: yongruilin Date: Thu, 15 Jan 2026 06:42:06 +0000 Subject: [PATCH] Add tests for numeric format validation --- .../apiserver/validation/validation_test.go | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/validation/validation_test.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/validation/validation_test.go index 85c3f51d915..df2c6dd8d5a 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/validation/validation_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/validation/validation_test.go @@ -18,6 +18,7 @@ package validation import ( "context" + "math" "math/rand" "os" "strconv" @@ -638,6 +639,37 @@ func TestValidateCustomResource(t *testing.T) { }}, }, }, + {name: "numeric formats valid", + schema: apiextensions.JSONSchemaProps{ + Type: "object", + Properties: map[string]apiextensions.JSONSchemaProps{ + "intThirtyTwo": {Type: "integer", Format: "int32"}, + "intSixtyFour": {Type: "integer", Format: "int64"}, + "floatThreeTwo": {Type: "number", Format: "float"}, + "floatSixFour": {Type: "number", Format: "double"}, + }, + }, + objects: []interface{}{ + map[string]interface{}{ + "intThirtyTwo": int64(math.MinInt32), + "intSixtyFour": int64(math.MinInt64), + "floatThreeTwo": float64(-math.MaxFloat32), + "floatSixFour": float64(-math.MaxFloat64), + }, + map[string]interface{}{ + "intThirtyTwo": int64(0), + "intSixtyFour": int64(0), + "floatThreeTwo": float64(0), + "floatSixFour": float64(0), + }, + map[string]interface{}{ + "intThirtyTwo": int64(math.MaxInt32), + "intSixtyFour": int64(math.MaxInt64), + "floatThreeTwo": float64(math.MaxFloat32), + "floatSixFour": float64(math.MaxFloat64), + }, + }, + }, } for _, tt := range tests { compatVersion := tt.compatVersion