istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pilot/pkg/model/proxy_view_test.go (about) 1 // Copyright Istio Authors. All Rights Reserved. 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 model_test 16 17 import ( 18 "testing" 19 20 . "github.com/onsi/gomega" 21 22 "istio.io/istio/pilot/pkg/model" 23 "istio.io/istio/pkg/network" 24 ) 25 26 func TestProxyView(t *testing.T) { 27 cases := []struct { 28 name string 29 networkView []string 30 network string 31 visible bool 32 }{ 33 { 34 name: "no views", 35 network: "network1", 36 visible: true, 37 }, 38 { 39 name: "network visible", 40 networkView: []string{"network1"}, 41 network: "network1", 42 visible: true, 43 }, 44 { 45 name: "network not visible", 46 networkView: []string{"network1"}, 47 network: "network2", 48 visible: false, 49 }, 50 { 51 name: "no network label", 52 networkView: []string{"network1"}, 53 network: "", 54 visible: true, 55 }, 56 } 57 58 for _, c := range cases { 59 c := c 60 t.Run(c.name, func(t *testing.T) { 61 g := NewWithT(t) 62 63 view := (&model.Proxy{ 64 Metadata: &model.NodeMetadata{ 65 RequestedNetworkView: c.networkView, 66 }, 67 }).GetView() 68 69 actual := view.IsVisible(&model.IstioEndpoint{ 70 Network: network.ID(c.network), 71 }) 72 73 g.Expect(actual).To(Equal(c.visible)) 74 }) 75 } 76 }