Skip to content

Commit

Permalink
tests: revert change to TestKindToResource, split it into subtests, a…
Browse files Browse the repository at this point in the history
…dd Endpoints testcase
  • Loading branch information
pmalek committed Aug 19, 2023
1 parent 333b97d commit 4d1cf44
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions staging/src/k8s.io/apimachinery/pkg/api/meta/restmapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"testing"

"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/gengo/namer"
"k8s.io/gengo/types"
)

func TestRESTMapperVersionAndKindForResource(t *testing.T) {
Expand Down Expand Up @@ -441,36 +439,28 @@ func TestKindToResource(t *testing.T) {
Plural, Singular string
}{
{Kind: "Pod", Plural: "pods", Singular: "pod"},

{Kind: "ReplicationController", Plural: "replicationcontrollers", Singular: "replicationcontroller"},

// Add "ies" when ending with "y"
{Kind: "ImageRepository", Plural: "imagerepositories", Singular: "imagerepository"},
// But take into account exceptions like gateway.
{Kind: "Gateway", Plural: "gateways", Singular: "gateway"},
// Add "es" when ending with "s"
{Kind: "miss", Plural: "misses", Singular: "miss"},
// Add "s" otherwise
{Kind: "lowercase", Plural: "lowercases", Singular: "lowercase"},
// Take into account Endpoints exception.
// Take into account Endpoints.
{Kind: "Endpoints", Plural: "endpoints", Singular: "endpoints"},
// TODO: this fails because UnsafeGuessKindToResource produces gatewaies as a plural form of gateway.
// {Kind: "Gateway", Plural: "gateways", Singular: "gateway"},
}

namer := namer.NewAllLowercasePluralNamer(map[string]string{
"Endpoints": "endpoints",
})
for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.Kind, func(t *testing.T) {
version := schema.GroupVersion{}
gvk := version.WithKind(testCase.Kind)

name := namer.Name(types.Ref(gvk.GroupKind().String(), gvk.Kind))
plural := gvk.GroupVersion().WithResource(name)
singular := gvk.GroupVersion().WithResource(strings.ToLower(gvk.Kind))
plural, singular := UnsafeGuessKindToResource(version.WithKind(testCase.Kind))

if singular != version.WithResource(testCase.Singular) || plural != version.WithResource(testCase.Plural) {
t.Errorf("unexpected plural and singular: %v %v", plural, singular)
t.Errorf("unexpected plural '%v' and singular: '%v'", plural.Resource, singular.Resource)
}
})
}
Expand Down

0 comments on commit 4d1cf44

Please sign in to comment.