From 9574a4b782bc4d1d046804597ed6d5f67ae0dbe7 Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Wed, 2 Dec 2015 20:39:55 -0800 Subject: [PATCH] Switch to KindToResource for ThirdPartyResourceData --- pkg/registry/thirdpartyresourcedata/codec.go | 3 +- .../thirdpartyresourcedata/codec_test.go | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/pkg/registry/thirdpartyresourcedata/codec.go b/pkg/registry/thirdpartyresourcedata/codec.go index 6d6b30f499..1cee86d2d2 100644 --- a/pkg/registry/thirdpartyresourcedata/codec.go +++ b/pkg/registry/thirdpartyresourcedata/codec.go @@ -42,7 +42,8 @@ type thirdPartyResourceDataMapper struct { var _ meta.RESTMapper = &thirdPartyResourceDataMapper{} func (t *thirdPartyResourceDataMapper) isThirdPartyResource(resource string) bool { - return resource == strings.ToLower(t.kind)+"s" + plural, _ := meta.KindToResource(t.kind, false) + return resource == plural } func (t *thirdPartyResourceDataMapper) KindFor(resource string) (unversioned.GroupVersionKind, error) { diff --git a/pkg/registry/thirdpartyresourcedata/codec_test.go b/pkg/registry/thirdpartyresourcedata/codec_test.go index a83dad36cb..62125c1467 100644 --- a/pkg/registry/thirdpartyresourcedata/codec_test.go +++ b/pkg/registry/thirdpartyresourcedata/codec_test.go @@ -181,3 +181,44 @@ func TestCreater(t *testing.T) { } } + +func TestResourceIsValid(t *testing.T) { + tests := []struct { + kind string + resource string + valid bool + name string + }{ + { + kind: "Foo", + resource: "foos", + valid: true, + name: "basic", + }, + { + kind: "Party", + resource: "parties", + valid: true, + name: "fun", + }, + { + kind: "bus", + resource: "buses", + valid: true, + name: "transport", + }, + { + kind: "Foo", + resource: "fooies", + name: "bad", + }, + } + for _, test := range tests { + mapper := &thirdPartyResourceDataMapper{kind: test.kind} + mapper.mapper = api.RESTMapper + valid := mapper.ResourceIsValid(test.resource) + if valid != test.valid { + t.Errorf("expected: %v, saw: %v for %s", test.valid, valid, test.name) + } + } +}