mirror of https://github.com/k3s-io/k3s
openapi: Remove FakeClient from testing library
And make a simplified version of it where needed.pull/8/head
parent
a1c8d3f5f3
commit
178a8f87f3
|
@ -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",
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue