istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pilot/pkg/config/kube/crd/config_test.go (about) 1 // Copyright Istio Authors 2 // 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 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 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. 14 15 package crd_test 16 17 import ( 18 "encoding/json" 19 "reflect" 20 "testing" 21 22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 24 "istio.io/istio/pilot/pkg/config/kube/crd" 25 "istio.io/istio/pkg/ptr" 26 ) 27 28 func TestKind(t *testing.T) { 29 obj := crd.IstioKind{} 30 31 spec := json.RawMessage(`{"a":"b"}`) 32 obj.Spec = spec 33 if got := obj.GetSpec(); !reflect.DeepEqual(spec, got) { 34 t.Errorf("GetSpec() => got %v, want %v", got, spec) 35 } 36 37 status := ptr.Of(json.RawMessage(`{"c":"d"}`)) 38 obj.Status = status 39 if got := obj.GetStatus(); !reflect.DeepEqual(status, got) { 40 t.Errorf("GetStatus() => got %v, want %v", got, status) 41 } 42 43 meta := metav1.ObjectMeta{Name: "test"} 44 obj.ObjectMeta = meta 45 if got := obj.GetObjectMeta(); !reflect.DeepEqual(meta, got) { 46 t.Errorf("GetObjectMeta() => got %v, want %v", got, meta) 47 } 48 49 if got := obj.DeepCopy(); !reflect.DeepEqual(*got, obj) { 50 t.Errorf("DeepCopy() => got %v, want %v", got, obj) 51 } 52 53 if got := obj.DeepCopyObject(); !reflect.DeepEqual(got, &obj) { 54 t.Errorf("DeepCopyObject() => got %v, want %v", got, obj) 55 } 56 57 var empty *crd.IstioKind 58 if empty.DeepCopy() != nil { 59 t.Error("DeepCopy of nil should return nil") 60 } 61 62 if empty.DeepCopyObject() != nil { 63 t.Error("DeepCopyObject of nil should return nil") 64 } 65 }