mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
openapi: Remove FakeClient from testing library
And make a simplified version of it where needed.
This commit is contained in:
parent
a1c8d3f5f3
commit
178a8f87f3
@ -36,6 +36,7 @@ go_test(
|
|||||||
deps = [
|
deps = [
|
||||||
":go_default_library",
|
":go_default_library",
|
||||||
"//pkg/kubectl/cmd/util/openapi/testing: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:go_default_library",
|
||||||
"//vendor/github.com/onsi/ginkgo/config:go_default_library",
|
"//vendor/github.com/onsi/ginkgo/config:go_default_library",
|
||||||
"//vendor/github.com/onsi/ginkgo/types:go_default_library",
|
"//vendor/github.com/onsi/ginkgo/types:go_default_library",
|
||||||
|
@ -19,27 +19,36 @@ package openapi_test
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
openapi_v2 "github.com/googleapis/gnostic/OpenAPIv2"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
|
"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 _ = Describe("Getting the Resources", func() {
|
||||||
var client *tst.FakeClient
|
var client FakeCounter
|
||||||
var expectedData openapi.Resources
|
|
||||||
var instance openapi.Getter
|
var instance openapi.Getter
|
||||||
|
var expectedData openapi.Resources
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
client = tst.NewFakeClient(&fakeSchema)
|
client = FakeCounter{}
|
||||||
d, err := fakeSchema.OpenAPISchema()
|
instance = openapi.NewOpenAPIGetter(&client)
|
||||||
|
var err error
|
||||||
|
expectedData, err = openapi.NewOpenAPIData(nil)
|
||||||
Expect(err).To(BeNil())
|
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() {
|
Context("when the server returns a successful result", func() {
|
||||||
|
@ -65,33 +65,6 @@ func (f *Fake) OpenAPISchema() (*openapi_v2.Document, error) {
|
|||||||
return f.document, f.err
|
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
|
// 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
|
// 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.
|
// it's assuming that the file is there and everything will go fine.
|
||||||
|
Loading…
Reference in New Issue
Block a user