From b7598021ee0607404a10d90ea680b4f9ae46619c Mon Sep 17 00:00:00 2001 From: hzxuzhonghu Date: Wed, 15 Nov 2017 17:24:04 +0800 Subject: [PATCH] remove unused code in pkg/apimachinery --- pkg/BUILD | 1 - pkg/apimachinery/tests/BUILD | 30 ----- .../tests/api_meta_scheme_test.go | 121 ------------------ 3 files changed, 152 deletions(-) delete mode 100644 pkg/apimachinery/tests/BUILD delete mode 100644 pkg/apimachinery/tests/api_meta_scheme_test.go diff --git a/pkg/BUILD b/pkg/BUILD index fc74d006478..86e113bbfdd 100644 --- a/pkg/BUILD +++ b/pkg/BUILD @@ -27,7 +27,6 @@ filegroup( "//pkg/api/v1/pod:all-srcs", "//pkg/api/v1/resource:all-srcs", "//pkg/api/v1/service:all-srcs", - "//pkg/apimachinery/tests:all-srcs", "//pkg/apis/abac:all-srcs", "//pkg/apis/admission:all-srcs", "//pkg/apis/admissionregistration:all-srcs", diff --git a/pkg/apimachinery/tests/BUILD b/pkg/apimachinery/tests/BUILD deleted file mode 100644 index adbe4ae6907..00000000000 --- a/pkg/apimachinery/tests/BUILD +++ /dev/null @@ -1,30 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load( - "@io_bazel_rules_go//go:def.bzl", - "go_test", -) - -go_test( - name = "go_default_test", - srcs = ["api_meta_scheme_test.go"], - importpath = "k8s.io/kubernetes/pkg/apimachinery/tests", - deps = [ - "//pkg/api/testapi:go_default_library", - "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", - "//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library", - ], -) - -filegroup( - name = "package-srcs", - srcs = glob(["**"]), - tags = ["automanaged"], - visibility = ["//visibility:private"], -) - -filegroup( - name = "all-srcs", - srcs = [":package-srcs"], - tags = ["automanaged"], -) diff --git a/pkg/apimachinery/tests/api_meta_scheme_test.go b/pkg/apimachinery/tests/api_meta_scheme_test.go deleted file mode 100644 index 42b2842cd3e..00000000000 --- a/pkg/apimachinery/tests/api_meta_scheme_test.go +++ /dev/null @@ -1,121 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package tests - -import ( - "fmt" - "reflect" - "strings" - "testing" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/kubernetes/pkg/api/testapi" -) - -// These types do not follow the list convention as documented in -// docs/devel/api-convention.md -var listTypeExceptions = sets.NewString("APIGroupList", "APIResourceList") - -func validateListType(target reflect.Type) error { - // exceptions - if listTypeExceptions.Has(target.Name()) { - return nil - } - hasListSuffix := strings.HasSuffix(target.Name(), "List") - hasMetadata := false - hasItems := false - for i := 0; i < target.NumField(); i++ { - field := target.Field(i) - tag := field.Tag.Get("json") - switch { - case strings.HasPrefix(tag, "metadata"): - hasMetadata = true - case tag == "items": - hasItems = true - if field.Type.Kind() != reflect.Slice { - return fmt.Errorf("Expected items to be slice, got %s", field.Type.Kind()) - } - } - } - if hasListSuffix && !hasMetadata { - return fmt.Errorf("Expected type %s to contain \"metadata\"", target.Name()) - } - if hasListSuffix && !hasItems { - return fmt.Errorf("Expected type %s to contain \"items\"", target.Name()) - } - // if a type contains field Items with JSON tag "items", its name should end with List. - if !hasListSuffix && hasItems { - return fmt.Errorf("Type %s has Items, its name is expected to end with \"List\"", target.Name()) - } - return nil -} - -// TestListTypes verifies that no external type violates the api convention of -// list types. -func TestListTypes(t *testing.T) { - for groupKey, group := range testapi.Groups { - for kind, target := range group.ExternalTypes() { - t.Logf("working on %v in %v", kind, groupKey) - err := validateListType(target) - if err != nil { - t.Error(err) - } - } - } -} - -type WithoutMetaDataList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta - Items []interface{} `json:"items"` -} - -type WithoutItemsList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` -} - -type WrongItemsJSONTagList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []interface{} `json:"items,omitempty"` -} - -// If a type has Items, its name should end with "List" -type ListWithWrongName struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []interface{} `json:"items"` -} - -// TestValidateListType verifies the validateListType function reports error on -// types that violate the api convention. -func TestValidateListType(t *testing.T) { - var testTypes = []interface{}{ - WithoutMetaDataList{}, - WithoutItemsList{}, - WrongItemsJSONTagList{}, - ListWithWrongName{}, - } - for _, testType := range testTypes { - err := validateListType(reflect.TypeOf(testType)) - if err == nil { - t.Errorf("Expected error") - } - } -}