github.com/prebid/prebid-server/v2@v2.18.0/privacy/gpp/sid_test.go (about) 1 package gpp 2 3 import ( 4 "testing" 5 6 gpplib "github.com/prebid/go-gpp" 7 gppConstants "github.com/prebid/go-gpp/constants" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestIsSIDInList(t *testing.T) { 12 type testInput struct { 13 gppSIDs []int8 14 sid gppConstants.SectionID 15 } 16 testCases := []struct { 17 desc string 18 in testInput 19 expected bool 20 }{ 21 { 22 desc: "nil_gppSID_array,_expect_false", 23 in: testInput{ 24 gppSIDs: nil, 25 sid: gppConstants.SectionTCFEU2, 26 }, 27 expected: false, 28 }, 29 { 30 desc: "empty_gppSID_array, expect_false", 31 in: testInput{ 32 gppSIDs: []int8{}, 33 sid: gppConstants.SectionTCFEU2, 34 }, 35 expected: false, 36 }, 37 { 38 desc: "SID_not_found_in_gppSID_array,_expect_false", 39 in: testInput{ 40 gppSIDs: []int8{int8(8), int8(9)}, 41 sid: gppConstants.SectionTCFEU2, 42 }, 43 expected: false, 44 }, 45 { 46 desc: "SID_found_in_gppSID_array,_expect_true", 47 in: testInput{ 48 gppSIDs: []int8{int8(2)}, 49 sid: gppConstants.SectionTCFEU2, 50 }, 51 expected: true, 52 }, 53 } 54 for _, tc := range testCases { 55 t.Run(tc.desc, func(t *testing.T) { assert.Equal(t, tc.expected, IsSIDInList(tc.in.gppSIDs, tc.in.sid)) }) 56 } 57 } 58 59 func TestIndexOfSID(t *testing.T) { 60 type testInput struct { 61 gpp gpplib.GppContainer 62 sid gppConstants.SectionID 63 } 64 testCases := []struct { 65 desc string 66 in testInput 67 expected int 68 }{ 69 { 70 desc: "Empty_SectionTypes_array,_expect_-1_out", 71 in: testInput{ 72 gpp: gpplib.GppContainer{}, 73 sid: gppConstants.SectionTCFEU2, 74 }, 75 expected: -1, 76 }, 77 { 78 desc: "SID_not_found_in_SectionTypes_array,_expect_-1_out", 79 in: testInput{ 80 gpp: gpplib.GppContainer{ 81 Version: 1, 82 SectionTypes: []gppConstants.SectionID{gppConstants.SectionUSPV1}, 83 }, 84 sid: gppConstants.SectionTCFEU2, 85 }, 86 expected: -1, 87 }, 88 { 89 desc: "SID_matches_an_element_in_SectionTypes_array,_expect_index_1_out", 90 in: testInput{ 91 gpp: gpplib.GppContainer{ 92 Version: 1, 93 SectionTypes: []gppConstants.SectionID{ 94 gppConstants.SectionUSPV1, 95 gppConstants.SectionTCFEU2, 96 gppConstants.SectionUSPCA, 97 }, 98 }, 99 sid: gppConstants.SectionTCFEU2, 100 }, 101 expected: 1, 102 }, 103 } 104 for _, tc := range testCases { 105 t.Run(tc.desc, func(t *testing.T) { assert.Equal(t, tc.expected, IndexOfSID(tc.in.gpp, tc.in.sid)) }) 106 } 107 }