istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/config/analysis/diag/helper.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 diag 16 17 import ( 18 "istio.io/istio/pkg/cluster" 19 "istio.io/istio/pkg/config/resource" 20 ) 21 22 var ( 23 _ resource.Origin = &testOrigin{} 24 _ resource.Reference = &testReference{} 25 ) 26 27 type testOrigin struct { 28 name string 29 ref resource.Reference 30 fieldMap map[string]int 31 cluster cluster.ID 32 } 33 34 func (o testOrigin) ClusterName() cluster.ID { 35 return o.cluster 36 } 37 38 func (o testOrigin) FriendlyName() string { 39 return o.name 40 } 41 42 func (o testOrigin) Comparator() string { 43 return o.name 44 } 45 46 func (o testOrigin) Namespace() resource.Namespace { 47 return "" 48 } 49 50 func (o testOrigin) Reference() resource.Reference { 51 return o.ref 52 } 53 54 func (o testOrigin) FieldMap() map[string]int { 55 return o.fieldMap 56 } 57 58 type testReference struct { 59 name string 60 } 61 62 func (r testReference) String() string { 63 return r.name 64 } 65 66 func MockResource(name string) *resource.Instance { 67 return &resource.Instance{ 68 Metadata: resource.Metadata{ 69 FullName: resource.NewShortOrFullName("default", name), 70 }, 71 Origin: testOrigin{name: name}, 72 } 73 }