Skip to content

Commit

Permalink
generic set
Browse files Browse the repository at this point in the history
Kubernetes-commit: 070e7a38cb672b019ffbaf261da3b09f7feaeb01
  • Loading branch information
AxeZhan authored and k8s-publishing-bot committed Oct 26, 2023
1 parent 92fa50e commit 092c2b3
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 092c2b3

Please sign in to comment.