From ba3339a1fbc196dddd829cf8a4526cf82e3c7d13 Mon Sep 17 00:00:00 2001 From: hangaoshuai Date: Thu, 22 Feb 2018 09:44:01 +0800 Subject: [PATCH] fix todo: add validate method for &schedulerapi.Policy --- examples/BUILD | 1 + examples/examples_test.go | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/BUILD b/examples/BUILD index 8fa87a454e9..9235dca18ad 100644 --- a/examples/BUILD +++ b/examples/BUILD @@ -41,6 +41,7 @@ go_test( "//pkg/registry/batch/job:go_default_library", "//pkg/scheduler/api:go_default_library", "//pkg/scheduler/api/latest:go_default_library", + "//pkg/scheduler/api/validation:go_default_library", "//vendor/github.com/golang/glog:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", diff --git a/examples/examples_test.go b/examples/examples_test.go index 33ec647fff0..1cf3eab0022 100644 --- a/examples/examples_test.go +++ b/examples/examples_test.go @@ -44,6 +44,7 @@ import ( "k8s.io/kubernetes/pkg/registry/batch/job" schedulerapi "k8s.io/kubernetes/pkg/scheduler/api" schedulerapilatest "k8s.io/kubernetes/pkg/scheduler/api/latest" + schedulerapivalidation "k8s.io/kubernetes/pkg/scheduler/api/validation" ) func validateObject(obj runtime.Object) (errors field.ErrorList) { @@ -144,6 +145,15 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) { return errors } +func validateschedulerpolicy(obj runtime.Object) error { + switch t := obj.(type) { + case *schedulerapi.Policy: + return schedulerapivalidation.ValidatePolicy(*t) + default: + return fmt.Errorf("obj type is not schedulerapi.Policy") + } +} + func walkJSONFiles(inDir string, fn func(name, path string, data []byte)) error { return filepath.Walk(inDir, func(path string, info os.FileInfo, err error) error { if err != nil { @@ -357,7 +367,10 @@ func TestExampleObjectSchemas(t *testing.T) { t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data)) return } - //TODO: Add validate method for &schedulerapi.Policy + if err := validateschedulerpolicy(expectedType); err != nil { + t.Errorf("%s did not validate correctly: %v\n%s", path, err, string(data)) + return + } } else { codec, err := testapi.GetCodecForObject(expectedType) if err != nil {