1
// Copyright Istio Authors
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
20
"k8s.io/apimachinery/pkg/api/meta"
21
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
24
func TestSetLabel(t *testing.T) {
32
desc: "AddMapLabelMapValue",
38
for _, tt := range tests {
39
t.Run(tt.desc, func(t *testing.T) {
40
resource := &unstructured.Unstructured{Object: make(map[string]any)}
41
gotErr := SetLabel(resource, tt.wantLabel, tt.wantValue)
42
resourceAccessor, _ := meta.Accessor(resource)
43
labels := resourceAccessor.GetLabels()
44
if gotVal, ok := labels[tt.wantLabel]; !ok || gotVal != tt.wantValue || gotErr != tt.wantErr {
45
t.Errorf("%s: ok: %v, got value: %v, want value: %v, got error: %v, want error: %v", tt.desc, ok, gotVal, tt.wantValue, gotErr, tt.wantErr)