Skip to content

Commit

Permalink
Merge pull request #120592 from AxeZhan/validation_sets
Browse files Browse the repository at this point in the history
Use generic set in package "/pkg/apis/core/validation"

Kubernetes-commit: 418e9d08a496964f9973ac7ce76f2db687192370
  • Loading branch information
k8s-publishing-bot committed Oct 31, 2023
2 parents 92fa50e + 092c2b3 commit 850727f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/api/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestNewInvalid(t *testing.T) {
`Kind "name" is invalid: field[0].name: Not found: "bar"`,
},
{
field.NotSupported(field.NewPath("field[0].name"), "bar", nil),
field.NotSupported[string](field.NewPath("field[0].name"), "bar", nil),
&metav1.StatusDetails{
Kind: "Kind",
Name: "name",
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/validation/field/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ func Invalid(field *Path, value interface{}, detail string) *Error {
// NotSupported returns a *Error indicating "unsupported value".
// This is used to report unknown values for enumerated fields (e.g. a list of
// valid values).
func NotSupported(field *Path, value interface{}, validValues []string) *Error {
func NotSupported[T ~string](field *Path, value interface{}, validValues []T) *Error {
detail := ""
if len(validValues) > 0 {
quotedValues := make([]string, len(validValues))
for i, v := range validValues {
quotedValues[i] = strconv.Quote(v)
quotedValues[i] = strconv.Quote(fmt.Sprint(v))
}
detail = "supported values: " + strings.Join(quotedValues, ", ")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/validation/field/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestMakeFuncs(t *testing.T) {
ErrorTypeInvalid,
},
{
func() *Error { return NotSupported(NewPath("f"), "v", nil) },
func() *Error { return NotSupported[string](NewPath("f"), "v", nil) },
ErrorTypeNotSupported,
},
{
Expand Down

0 comments on commit 850727f

Please sign in to comment.