mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-01 18:58:18 +00:00
Move NodeResourcesFit plugin args validation to apis/config/validation
Signed-off-by: Dave Chen <dave.chen@arm.com>
This commit is contained in:
@@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
@@ -571,74 +570,3 @@ func TestStorageRequests(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestValidateFitArgs(t *testing.T) {
|
||||
argsTest := []struct {
|
||||
name string
|
||||
args config.NodeResourcesFitArgs
|
||||
expect string
|
||||
}{
|
||||
{
|
||||
name: "IgnoredResources: too long value",
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResources: []string{fmt.Sprintf("longvalue%s", strings.Repeat("a", 64))},
|
||||
},
|
||||
expect: "name part must be no more than 63 characters",
|
||||
},
|
||||
{
|
||||
name: "IgnoredResources: name is empty",
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResources: []string{"example.com/"},
|
||||
},
|
||||
expect: "name part must be non-empty",
|
||||
},
|
||||
{
|
||||
name: "IgnoredResources: name has too many slash",
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResources: []string{"example.com/aaa/bbb"},
|
||||
},
|
||||
expect: "a qualified name must consist of alphanumeric characters",
|
||||
},
|
||||
{
|
||||
name: "IgnoredResources: valid args",
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResources: []string{"example.com"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "IgnoredResourceGroups: valid args ",
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResourceGroups: []string{"example.com"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "IgnoredResourceGroups: illegal args",
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResourceGroups: []string{"example.com/"},
|
||||
},
|
||||
expect: "name part must be non-empty",
|
||||
},
|
||||
{
|
||||
name: "IgnoredResourceGroups: name is too long",
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResourceGroups: []string{strings.Repeat("a", 64)},
|
||||
},
|
||||
expect: "name part must be no more than 63 characters",
|
||||
},
|
||||
{
|
||||
name: "IgnoredResourceGroups: name cannot be contain slash",
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResourceGroups: []string{"example.com/aa"},
|
||||
},
|
||||
expect: "resource group name can't contain '/'",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range argsTest {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if err := validateFitArgs(test.args); err != nil && !strings.Contains(err.Error(), test.expect) {
|
||||
t.Errorf("case[%v]: error details do not include %v", test.name, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user