From 01c4fe20283d0a36c0b1a6141896b015b148c99e Mon Sep 17 00:00:00 2001 From: wojtekt Date: Fri, 28 Jun 2019 13:30:43 +0200 Subject: [PATCH] Cleanup util file Kubernetes-commit: 762518fd47bb058d11b26c60d9cf9f9a9c5b3c05 --- pkg/storage/etcd3/store_test.go | 6 +++--- pkg/storage/testing/utils.go | 17 ++++++++++++++--- pkg/storage/tests/cacher_test.go | 3 ++- pkg/storage/tests/utils.go | 30 ------------------------------ 4 files changed, 19 insertions(+), 37 deletions(-) delete mode 100644 pkg/storage/tests/utils.go diff --git a/pkg/storage/etcd3/store_test.go b/pkg/storage/etcd3/store_test.go index 7167a5e4c..6dfcb4bc3 100644 --- a/pkg/storage/etcd3/store_test.go +++ b/pkg/storage/etcd3/store_test.go @@ -47,7 +47,7 @@ import ( "k8s.io/apiserver/pkg/features" "k8s.io/apiserver/pkg/storage" "k8s.io/apiserver/pkg/storage/etcd" - storagetests "k8s.io/apiserver/pkg/storage/tests" + storagetesting "k8s.io/apiserver/pkg/storage/testing" "k8s.io/apiserver/pkg/storage/value" utilfeature "k8s.io/apiserver/pkg/util/feature" featuregatetesting "k8s.io/component-base/featuregate/testing" @@ -693,13 +693,13 @@ func TestTransformationFailure(t *testing.T) { key: "/one-level/test", obj: &example.Pod{ ObjectMeta: metav1.ObjectMeta{Name: "bar"}, - Spec: storagetests.DeepEqualSafePodSpec(), + Spec: storagetesting.DeepEqualSafePodSpec(), }, }, { key: "/two-level/1/test", obj: &example.Pod{ ObjectMeta: metav1.ObjectMeta{Name: "baz"}, - Spec: storagetests.DeepEqualSafePodSpec(), + Spec: storagetesting.DeepEqualSafePodSpec(), }, }} for i, ps := range preset[:1] { diff --git a/pkg/storage/testing/utils.go b/pkg/storage/testing/utils.go index e226da6f6..d0fbeef3e 100644 --- a/pkg/storage/testing/utils.go +++ b/pkg/storage/testing/utils.go @@ -22,15 +22,16 @@ import ( "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apiserver/pkg/apis/example" "k8s.io/apiserver/pkg/storage" ) -// CreateObj will create a single object using the storage interface +// CreateObj will create a single object using the storage interface. func CreateObj(helper storage.Interface, name string, obj, out runtime.Object, ttl uint64) error { return helper.Create(context.TODO(), name, obj, out, ttl) } -//CreateObjList will create a list from the array of objects +// CreateObjList will create a list from the array of objects. func CreateObjList(prefix string, helper storage.Interface, items []runtime.Object) error { for i := range items { obj := items[i] @@ -47,7 +48,7 @@ func CreateObjList(prefix string, helper storage.Interface, items []runtime.Obje return nil } -// CreateList will properly create a list using the storage interface +// CreateList will properly create a list using the storage interface. func CreateList(prefix string, helper storage.Interface, list runtime.Object) error { items, err := meta.ExtractList(list) if err != nil { @@ -59,3 +60,13 @@ func CreateList(prefix string, helper storage.Interface, list runtime.Object) er } return meta.SetList(list, items) } + +// DeepEqualSafePodSpec returns an example.PodSpec safe for deep-equal operations. +func DeepEqualSafePodSpec() example.PodSpec { + grace := int64(30) + return example.PodSpec{ + RestartPolicy: "Always", + TerminationGracePeriodSeconds: &grace, + SchedulerName: "default-scheduler", + } +} diff --git a/pkg/storage/tests/cacher_test.go b/pkg/storage/tests/cacher_test.go index f50def631..e3163dc77 100644 --- a/pkg/storage/tests/cacher_test.go +++ b/pkg/storage/tests/cacher_test.go @@ -47,6 +47,7 @@ import ( "k8s.io/apiserver/pkg/storage/etcd/etcdtest" etcdtesting "k8s.io/apiserver/pkg/storage/etcd/testing" "k8s.io/apiserver/pkg/storage/etcd3" + storagetesting "k8s.io/apiserver/pkg/storage/testing" "k8s.io/apiserver/pkg/storage/value" utilfeature "k8s.io/apiserver/pkg/util/feature" featuregatetesting "k8s.io/component-base/featuregate/testing" @@ -120,7 +121,7 @@ func newTestCacher(s storage.Interface, cap int) (*cacherstorage.Cacher, storage func makeTestPod(name string) *example.Pod { return &example.Pod{ ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: name}, - Spec: DeepEqualSafePodSpec(), + Spec: storagetesting.DeepEqualSafePodSpec(), } } diff --git a/pkg/storage/tests/utils.go b/pkg/storage/tests/utils.go deleted file mode 100644 index 75691e00a..000000000 --- a/pkg/storage/tests/utils.go +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright 2017 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 ( - "k8s.io/apiserver/pkg/apis/example" -) - -func DeepEqualSafePodSpec() example.PodSpec { - grace := int64(30) - return example.PodSpec{ - RestartPolicy: "Always", - TerminationGracePeriodSeconds: &grace, - SchedulerName: "default-scheduler", - } -}