istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/config/analysis/testing/fixtures/context.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 fixtures 16 17 import ( 18 "istio.io/istio/pkg/config" 19 "istio.io/istio/pkg/config/analysis" 20 "istio.io/istio/pkg/config/analysis/diag" 21 "istio.io/istio/pkg/config/resource" 22 ) 23 24 // Context is a test fixture of analysis.Context 25 type Context struct { 26 Resources []*resource.Instance 27 Reports []diag.Message 28 } 29 30 var _ analysis.Context = &Context{} 31 32 // Report implements analysis.Context 33 func (ctx *Context) Report(_ config.GroupVersionKind, t diag.Message) { 34 ctx.Reports = append(ctx.Reports, t) 35 } 36 37 // Find implements analysis.Context 38 func (ctx *Context) Find(config.GroupVersionKind, resource.FullName) *resource.Instance { return nil } 39 40 // Exists implements analysis.Context 41 func (ctx *Context) Exists(config.GroupVersionKind, resource.FullName) bool { return false } 42 43 // ForEach implements analysis.Context 44 func (ctx *Context) ForEach(_ config.GroupVersionKind, fn analysis.IteratorFn) { 45 for _, r := range ctx.Resources { 46 fn(r) 47 } 48 } 49 50 // Canceled implements analysis.Context 51 func (ctx *Context) Canceled() bool { return false } 52 53 func (ctx *Context) SetAnalyzer(analyzerName string) {}