Add integration test to test singularnames for all resources

This commit is contained in:
Arda Güçlü 2022-11-21 09:59:37 +03:00
parent 1f54f610e4
commit 43a889fc65
3 changed files with 28 additions and 4 deletions

View File

@ -168,9 +168,6 @@ func (r *REST) ResourceLocation(ctx context.Context, id string) (*url.URL, http.
return node.ResourceLocation(r, r.connection, r.proxyTransport, ctx, id) return node.ResourceLocation(r, r.connection, r.proxyTransport, ctx, id)
} }
// Implement ShortNamesProvider
var _ rest.ShortNamesProvider = &REST{}
// ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource. // ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource.
func (r *REST) ShortNames() []string { func (r *REST) ShortNames() []string {
return []string{"no"} return []string{"no"}

View File

@ -290,7 +290,7 @@ func (r *LegacyBindingREST) Create(ctx context.Context, obj runtime.Object, crea
} }
func (r *LegacyBindingREST) GetSingularName() string { func (r *LegacyBindingREST) GetSingularName() string {
return "bindings" return "binding"
} }
// StatusREST implements the REST endpoint for changing the status of a pod. // StatusREST implements the REST endpoint for changing the status of a pod.

View File

@ -690,6 +690,33 @@ func TestGroupPriorty(t *testing.T) {
}) })
} }
func TestSingularNames(t *testing.T) {
server := kubeapiservertesting.StartTestServerOrDie(t, nil, []string{"--runtime-config=api/all=true"}, framework.SharedEtcd())
t.Cleanup(server.TearDownFn)
kubeClientSet, err := kubernetes.NewForConfig(server.ClientConfig)
require.NoError(t, err)
_, resources, err := kubeClientSet.Discovery().ServerGroupsAndResources()
require.NoError(t, err)
for _, rr := range resources {
for _, r := range rr.APIResources {
if strings.Contains(r.Name, "/") {
continue
}
if r.SingularName == "" {
t.Errorf("missing singularName for resource %q in %q", r.Name, rr.GroupVersion)
continue
}
if r.SingularName != strings.ToLower(r.Kind) {
t.Errorf("expected singularName for resource %q in %q to be %q, got %q", r.Name, rr.GroupVersion, strings.ToLower(r.Kind), r.SingularName)
continue
}
}
}
}
func makeCRDSpec(group string, kind string, namespaced bool, versions []string, categories ...string) apiextensionsv1.CustomResourceDefinitionSpec { func makeCRDSpec(group string, kind string, namespaced bool, versions []string, categories ...string) apiextensionsv1.CustomResourceDefinitionSpec {
scope := apiextensionsv1.NamespaceScoped scope := apiextensionsv1.NamespaceScoped
if !namespaced { if !namespaced {