mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 04:54:54 +00:00
chore(validation-gen): Update output_tests for k8s:customUnique
This commit is contained in:
@@ -49,6 +49,17 @@ type Struct struct {
|
||||
// +k8s:unique=map
|
||||
// +k8s:listMapKey=key
|
||||
AtomicListUniqueMap []Item `json:"atomicListUniqueMap"`
|
||||
|
||||
// customUnique with listType=set
|
||||
// +k8s:listType=set
|
||||
// +k8s:customUnique
|
||||
CustomUniqueListWithTypeSet []string `json:"customUniqueListWithTypeSet"`
|
||||
|
||||
// customUnique with listType=map
|
||||
// +k8s:listType=map
|
||||
// +k8s:listMapKey=key
|
||||
// +k8s:customUnique
|
||||
CustomUniqueListWithTypeMap []Item `json:"customUniqueListWithTypeMap"`
|
||||
}
|
||||
|
||||
type Item struct {
|
||||
|
||||
@@ -43,6 +43,8 @@ func TestUnique(t *testing.T) {
|
||||
{Key: "key1", Data: "one"},
|
||||
{Key: "key2", Data: "two"},
|
||||
},
|
||||
CustomUniqueListWithTypeSet: []string{"a", "b", "a"},
|
||||
CustomUniqueListWithTypeMap: []Item{{Key: "a"}, {Key: "b"}, {Key: "a"}},
|
||||
}).ExpectValid()
|
||||
|
||||
// Test empty lists
|
||||
@@ -51,6 +53,8 @@ func TestUnique(t *testing.T) {
|
||||
SliceMapFieldWithMultipleKeys: []ItemWithMultipleKeys{},
|
||||
AtomicListUniqueSet: []Item{},
|
||||
AtomicListUniqueMap: []Item{},
|
||||
CustomUniqueListWithTypeSet: []string{},
|
||||
CustomUniqueListWithTypeMap: []Item{},
|
||||
}).ExpectValid()
|
||||
|
||||
// Test single element lists
|
||||
@@ -59,6 +63,8 @@ func TestUnique(t *testing.T) {
|
||||
SliceMapFieldWithMultipleKeys: []ItemWithMultipleKeys{{Key1: "a", Key2: "b", Data: "one"}},
|
||||
AtomicListUniqueSet: []Item{{Key: "single", Data: "one"}},
|
||||
AtomicListUniqueMap: []Item{{Key: "single", Data: "one"}},
|
||||
CustomUniqueListWithTypeSet: []string{"single"},
|
||||
CustomUniqueListWithTypeMap: []Item{{Key: "single"}},
|
||||
}).ExpectValid()
|
||||
|
||||
// Test duplicate values (should fail validation)
|
||||
@@ -79,6 +85,8 @@ func TestUnique(t *testing.T) {
|
||||
{Key: "key2", Data: "two"},
|
||||
{Key: "key1", Data: "three"},
|
||||
},
|
||||
CustomUniqueListWithTypeSet: []string{"a", "b", "a"},
|
||||
CustomUniqueListWithTypeMap: []Item{{Key: "a"}, {Key: "b"}, {Key: "a"}},
|
||||
}).ExpectMatches(field.ErrorMatcher{}.ByType().ByField(), field.ErrorList{
|
||||
field.Duplicate(field.NewPath("primitiveListUniqueSet").Index(3), nil),
|
||||
field.Duplicate(field.NewPath("primitiveListUniqueSet").Index(4), nil),
|
||||
@@ -96,6 +104,8 @@ func TestUnique(t *testing.T) {
|
||||
{Key: "a", Data: "two"},
|
||||
{Key: "", Data: "three"},
|
||||
},
|
||||
CustomUniqueListWithTypeSet: []string{"", "a", ""},
|
||||
CustomUniqueListWithTypeMap: []Item{{Key: ""}, {Key: "a"}, {Key: ""}},
|
||||
}).ExpectMatches(field.ErrorMatcher{}.ByType().ByField(), field.ErrorList{
|
||||
field.Duplicate(field.NewPath("primitiveListUniqueSet").Index(2), nil),
|
||||
field.Duplicate(field.NewPath("atomicListUniqueMap").Index(2), nil),
|
||||
@@ -119,6 +129,8 @@ func TestRatcheting(t *testing.T) {
|
||||
{Key: "key1", Data: "one"},
|
||||
{Key: "key2", Data: "two"},
|
||||
},
|
||||
CustomUniqueListWithTypeSet: []string{"a", "b", "a"},
|
||||
CustomUniqueListWithTypeMap: []Item{{Key: "a"}, {Key: "b"}, {Key: "a"}},
|
||||
}
|
||||
|
||||
// Same data, different order.
|
||||
@@ -136,6 +148,8 @@ func TestRatcheting(t *testing.T) {
|
||||
{Key: "key2", Data: "two"},
|
||||
{Key: "key1", Data: "one"},
|
||||
},
|
||||
CustomUniqueListWithTypeSet: []string{"a", "a", "b"},
|
||||
CustomUniqueListWithTypeMap: []Item{{Key: "a"}, {Key: "a"}, {Key: "b"}},
|
||||
}
|
||||
|
||||
// Test that reordering doesn't trigger validation errors
|
||||
|
||||
@@ -106,5 +106,7 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field
|
||||
return
|
||||
}(fldPath.Child("atomicListUniqueMap"), obj.AtomicListUniqueMap, safe.Field(oldObj, func(oldObj *Struct) []Item { return oldObj.AtomicListUniqueMap }))...)
|
||||
|
||||
// field Struct.CustomUniqueListWithTypeSet has no validation
|
||||
// field Struct.CustomUniqueListWithTypeMap has no validation
|
||||
return errs
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user