From 178a8f87f313fd38969c2a1f07963e24e45238ff Mon Sep 17 00:00:00 2001 From: Antoine Pelisse Date: Thu, 31 May 2018 13:35:26 -0700 Subject: [PATCH] openapi: Remove FakeClient from testing library And make a simplified version of it where needed. --- pkg/kubectl/cmd/util/openapi/BUILD | 1 + .../cmd/util/openapi/openapi_getter_test.go | 29 ++++++++++++------- .../cmd/util/openapi/testing/openapi.go | 27 ----------------- 3 files changed, 20 insertions(+), 37 deletions(-) diff --git a/pkg/kubectl/cmd/util/openapi/BUILD b/pkg/kubectl/cmd/util/openapi/BUILD index bb6b3e24048..eda5d272a2b 100644 --- a/pkg/kubectl/cmd/util/openapi/BUILD +++ b/pkg/kubectl/cmd/util/openapi/BUILD @@ -36,6 +36,7 @@ go_test( deps = [ ":go_default_library", "//pkg/kubectl/cmd/util/openapi/testing:go_default_library", + "//vendor/github.com/googleapis/gnostic/OpenAPIv2:go_default_library", "//vendor/github.com/onsi/ginkgo:go_default_library", "//vendor/github.com/onsi/ginkgo/config:go_default_library", "//vendor/github.com/onsi/ginkgo/types:go_default_library", diff --git a/pkg/kubectl/cmd/util/openapi/openapi_getter_test.go b/pkg/kubectl/cmd/util/openapi/openapi_getter_test.go index 004d27e1b2b..9239fe2bc75 100644 --- a/pkg/kubectl/cmd/util/openapi/openapi_getter_test.go +++ b/pkg/kubectl/cmd/util/openapi/openapi_getter_test.go @@ -19,27 +19,36 @@ package openapi_test import ( "fmt" + openapi_v2 "github.com/googleapis/gnostic/OpenAPIv2" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi" - tst "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/testing" ) +// FakeCounter returns a "null" document and the specified error. It +// also counts how many times the OpenAPISchema method has been called. +type FakeCounter struct { + Calls int + Err error +} + +func (f *FakeCounter) OpenAPISchema() (*openapi_v2.Document, error) { + f.Calls = f.Calls + 1 + return nil, f.Err +} + var _ = Describe("Getting the Resources", func() { - var client *tst.FakeClient - var expectedData openapi.Resources + var client FakeCounter var instance openapi.Getter + var expectedData openapi.Resources BeforeEach(func() { - client = tst.NewFakeClient(&fakeSchema) - d, err := fakeSchema.OpenAPISchema() + client = FakeCounter{} + instance = openapi.NewOpenAPIGetter(&client) + var err error + expectedData, err = openapi.NewOpenAPIData(nil) Expect(err).To(BeNil()) - - expectedData, err = openapi.NewOpenAPIData(d) - Expect(err).To(BeNil()) - - instance = openapi.NewOpenAPIGetter(client) }) Context("when the server returns a successful result", func() { diff --git a/pkg/kubectl/cmd/util/openapi/testing/openapi.go b/pkg/kubectl/cmd/util/openapi/testing/openapi.go index 1ccf47c25a5..4935e7ad0c5 100644 --- a/pkg/kubectl/cmd/util/openapi/testing/openapi.go +++ b/pkg/kubectl/cmd/util/openapi/testing/openapi.go @@ -65,33 +65,6 @@ func (f *Fake) OpenAPISchema() (*openapi_v2.Document, error) { return f.document, f.err } -// FakeClient implements a dummy OpenAPISchemaInterface that uses the -// fake OpenAPI schema given as a parameter, and count the number of -// call to the function. -type FakeClient struct { - Calls int - Err error - - fake *Fake -} - -// NewFakeClient creates a new FakeClient from the given Fake. -func NewFakeClient(f *Fake) *FakeClient { - return &FakeClient{fake: f} -} - -// OpenAPISchema returns a OpenAPI Document as returned by the fake, but -// it also counts the number of calls. -func (f *FakeClient) OpenAPISchema() (*openapi_v2.Document, error) { - f.Calls = f.Calls + 1 - - if f.Err != nil { - return nil, f.Err - } - - return f.fake.OpenAPISchema() -} - // FakeResources is a wrapper to directly load the openapi schema from a // file, and get the schema for given GVK. This is only for test since // it's assuming that the file is there and everything will go fine.