knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/apis/kind2resource_test.go (about)

     1  /*
     2  Copyright 2018 The Knative Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package apis
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/google/go-cmp/cmp"
    23  	"k8s.io/apimachinery/pkg/runtime/schema"
    24  )
    25  
    26  func TestGVK2GVR(t *testing.T) {
    27  	tests := []struct {
    28  		name  string
    29  		input schema.GroupVersionKind
    30  		want  schema.GroupVersionResource
    31  	}{{
    32  		name: "simple",
    33  		input: schema.GroupVersionKind{
    34  			Group:   "test.knative.dev",
    35  			Version: "v1",
    36  			Kind:    "Resource",
    37  		},
    38  		want: schema.GroupVersionResource{
    39  			Group:    "test.knative.dev",
    40  			Version:  "v1",
    41  			Resource: "resources",
    42  		},
    43  	}, {
    44  		name: "non-trivial",
    45  		input: schema.GroupVersionKind{
    46  			Group:   "test.knative.dev",
    47  			Version: "v1",
    48  			Kind:    "Mess",
    49  		},
    50  		want: schema.GroupVersionResource{
    51  			Group:    "test.knative.dev",
    52  			Version:  "v1",
    53  			Resource: "messes",
    54  		},
    55  	}, {
    56  		name: "another non-trivial (not ies)",
    57  		input: schema.GroupVersionKind{
    58  			Group:   "test.knative.dev",
    59  			Version: "v1",
    60  			Kind:    "Gateway",
    61  		},
    62  		want: schema.GroupVersionResource{
    63  			Group:    "test.knative.dev",
    64  			Version:  "v1",
    65  			Resource: "gateways",
    66  		},
    67  	}}
    68  
    69  	// TODO(mattmoor): Errata: pony, cactus, ?
    70  
    71  	for _, test := range tests {
    72  		t.Run(test.name, func(t *testing.T) {
    73  			got := KindToResource(test.input)
    74  			if diff := cmp.Diff(test.want, got); diff != "" {
    75  				t.Error("KindToResource (-want, +got) =", diff)
    76  			}
    77  		})
    78  	}
    79  }