mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
openapi: Add EmptyResource/CreateOpenAPISchemaFunc test utils
Add a new EmptyResource class that implements openapi.Resources, but just doesn't have any resources. That is useful for tests that expect the OpenAPISchema to be working, but don't expect any actual result. Also implement CreateOpenAPISchemaFunc to simply plug in the TestFactory code when you want to use an actual APISchema.
This commit is contained in:
parent
1ced91f201
commit
9778b1a9ba
@ -21,6 +21,7 @@ go_library(
|
||||
"//pkg/kubectl:go_default_library",
|
||||
"//pkg/kubectl/cmd/util:go_default_library",
|
||||
"//pkg/kubectl/cmd/util/openapi:go_default_library",
|
||||
"//pkg/kubectl/cmd/util/openapi/testing:go_default_library",
|
||||
"//pkg/kubectl/plugins:go_default_library",
|
||||
"//pkg/kubectl/resource:go_default_library",
|
||||
"//pkg/kubectl/validation:go_default_library",
|
||||
|
@ -44,6 +44,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubectl"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
|
||||
openapitesting "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/testing"
|
||||
"k8s.io/kubernetes/pkg/kubectl/plugins"
|
||||
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||
"k8s.io/kubernetes/pkg/kubectl/validation"
|
||||
@ -822,7 +823,7 @@ func (f *fakeAPIFactory) OpenAPISchema() (openapi.Resources, error) {
|
||||
if f.tf.OpenAPISchemaFunc != nil {
|
||||
return f.tf.OpenAPISchemaFunc()
|
||||
}
|
||||
return nil, nil
|
||||
return openapitesting.EmptyResources{}, nil
|
||||
}
|
||||
|
||||
func NewAPIFactory() (cmdutil.Factory, *TestFactory, runtime.Codec, runtime.NegotiatedSerializer) {
|
||||
|
@ -121,3 +121,20 @@ func (f *FakeResources) LookupResource(gvk schema.GroupVersionKind) proto.Schema
|
||||
}
|
||||
return resources.LookupResource(gvk)
|
||||
}
|
||||
|
||||
// EmptyResources implement a Resources that just doesn't have any resources.
|
||||
type EmptyResources struct{}
|
||||
|
||||
var _ openapi.Resources = EmptyResources{}
|
||||
|
||||
// LookupResource will always return nil. It doesn't have any resources.
|
||||
func (f EmptyResources) LookupResource(gvk schema.GroupVersionKind) proto.Schema {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateOpenAPISchemaFunc returns a function useful for the TestFactory.
|
||||
func CreateOpenAPISchemaFunc(path string) func() (openapi.Resources, error) {
|
||||
return func() (openapi.Resources, error) {
|
||||
return NewFakeResources(path), nil
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user