mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-02-03 20:40:26 -05:00
Add ratcheting tests for numeric format validation
This commit is contained in:
parent
4a457d97f4
commit
45b64fb145
1 changed files with 47 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package validation_test
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -131,3 +132,49 @@ func TestObjectObjectFieldsRatcheting(t *testing.T) {
|
|||
"small": 501,
|
||||
}}, validation.WithRatcheting(nil)).IsValid())
|
||||
}
|
||||
|
||||
var numericFormatSchema *spec.Schema = &spec.Schema{
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Type: spec.StringOrArray{"object"},
|
||||
Properties: map[string]spec.Schema{
|
||||
"intThirtyTwo": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Type: spec.StringOrArray{"integer"},
|
||||
Format: "int32",
|
||||
},
|
||||
},
|
||||
"unrelated": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Type: spec.StringOrArray{"string"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestNumericFormatRatcheting(t *testing.T) {
|
||||
validator := validation.NewRatchetingSchemaValidator(numericFormatSchema, nil, "", strfmt.Default)
|
||||
|
||||
// Ratcheting should allow existing invalid value if unchanged
|
||||
assert.True(t, validator.ValidateUpdate(map[string]interface{}{
|
||||
"intThirtyTwo": int64(math.MaxInt32 + 1),
|
||||
}, map[string]interface{}{
|
||||
"intThirtyTwo": int64(math.MaxInt32 + 1),
|
||||
}, validation.WithRatcheting(nil)).IsValid())
|
||||
|
||||
// Ratcheting should allow existing invalid value if other fields change
|
||||
assert.True(t, validator.ValidateUpdate(map[string]interface{}{
|
||||
"intThirtyTwo": int64(math.MaxInt32 + 1),
|
||||
"unrelated": "changed",
|
||||
}, map[string]interface{}{
|
||||
"intThirtyTwo": int64(math.MaxInt32 + 1),
|
||||
"unrelated": "original",
|
||||
}, validation.WithRatcheting(nil)).IsValid())
|
||||
|
||||
// Should fail if value changes to another invalid value
|
||||
assert.False(t, validator.ValidateUpdate(map[string]interface{}{
|
||||
"intThirtyTwo": int64(math.MaxInt32 + 2),
|
||||
}, map[string]interface{}{
|
||||
"intThirtyTwo": int64(math.MaxInt32 + 1),
|
||||
}, validation.WithRatcheting(nil)).IsValid())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue