github.com/prebid/prebid-server/v2@v2.18.0/privacy/component_test.go (about) 1 package privacy 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestComponentMatchesName(t *testing.T) { 10 testCases := []struct { 11 name string 12 given Component 13 target string 14 result bool 15 }{ 16 { 17 name: "match", 18 given: Component{Type: "a", Name: "b"}, 19 target: "b", 20 result: true, 21 }, 22 { 23 name: "wrong-field", 24 given: Component{Type: "a", Name: "b"}, 25 target: "a", 26 result: false, 27 }, 28 { 29 name: "different-value", 30 given: Component{Type: "a", Name: "b"}, 31 target: "foo", 32 result: false, 33 }, 34 { 35 name: "different-case", 36 given: Component{Type: "a", Name: "b"}, 37 target: "B", 38 result: true, 39 }, 40 } 41 42 for _, test := range testCases { 43 t.Run(test.name, func(t *testing.T) { 44 assert.Equal(t, test.result, test.given.MatchesName(test.target)) 45 }) 46 } 47 } 48 49 func TestComponentMatchesType(t *testing.T) { 50 testCases := []struct { 51 name string 52 given Component 53 target string 54 result bool 55 }{ 56 { 57 name: "match", 58 given: Component{Type: "a", Name: "b"}, 59 target: "a", 60 result: true, 61 }, 62 { 63 name: "wrong-field", 64 given: Component{Type: "a", Name: "b"}, 65 target: "b", 66 result: false, 67 }, 68 { 69 name: "different-value", 70 given: Component{Type: "a", Name: "b"}, 71 target: "foo", 72 result: false, 73 }, 74 { 75 name: "different-case", 76 given: Component{Type: "a", Name: "b"}, 77 target: "A", 78 result: true, 79 }, 80 } 81 82 for _, test := range testCases { 83 t.Run(test.name, func(t *testing.T) { 84 assert.Equal(t, test.result, test.given.MatchesType(test.target)) 85 }) 86 } 87 }