|
| 1 | +/* |
| 2 | +Copyright 2025 The KCP 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 replication |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/stretchr/testify/require" |
| 23 | + |
| 24 | + "k8s.io/apimachinery/pkg/runtime/schema" |
| 25 | +) |
| 26 | + |
| 27 | +func TestGenCachedObjectName(t *testing.T) { |
| 28 | + tests := map[string]struct { |
| 29 | + gvr schema.GroupVersionResource |
| 30 | + namespace string |
| 31 | + name string |
| 32 | + want string |
| 33 | + }{ |
| 34 | + "matching": { |
| 35 | + gvr: schema.GroupVersionResource{ |
| 36 | + Group: "group-1", |
| 37 | + Version: "v1", |
| 38 | + Resource: "resource-1", |
| 39 | + }, |
| 40 | + namespace: "", |
| 41 | + name: "a-resource", |
| 42 | + want: "6dgup41jy1ta41gc4q4hb1hdnmrdgl4rdn5ux0t8ya9nhk3jo6", |
| 43 | + }, |
| 44 | + } |
| 45 | + for tname, tt := range tests { |
| 46 | + t.Run(tname, func(t *testing.T) { |
| 47 | + objName := GenCachedObjectName(tt.gvr, tt.namespace, tt.name) |
| 48 | + require.Equal(t, tt.want, objName, "GenCachedObjectName returned an unexpected object name") |
| 49 | + }) |
| 50 | + } |
| 51 | +} |
0 commit comments