istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pilot/pkg/security/trustdomain/util_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 trustdomain 16 17 import ( 18 "testing" 19 ) 20 21 func TestStringMatch(t *testing.T) { 22 tests := []struct { 23 desc string 24 element string 25 list []string 26 expected bool 27 }{ 28 { 29 desc: "wildcard", 30 element: "*", 31 list: []string{"match-me"}, 32 expected: true, 33 }, 34 { 35 desc: "suffix=match", 36 element: "yo*", 37 list: []string{"yo", "yolo", "yo-yo"}, 38 expected: true, 39 }, 40 { 41 desc: "no-sub", 42 element: "foo", 43 list: []string{"bar"}, 44 expected: false, 45 }, 46 { 47 desc: "prefix-match", 48 element: "*yo", 49 list: []string{"yoyo", "goyo"}, 50 expected: true, 51 }, 52 { 53 desc: "empty", 54 element: "", 55 list: []string{"yo", "tawg"}, 56 expected: false, 57 }, 58 } 59 60 for _, tt := range tests { 61 t.Run(tt.desc, func(t *testing.T) { 62 if got := stringMatch(tt.element, tt.list); got != tt.expected { 63 t.Errorf("%s: expected %v got %v", tt.desc, tt.expected, got) 64 } 65 }) 66 } 67 }