Skip to content

Commit

Permalink
Exclude Disabled Bidders + Add Unit Test
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxNode committed Mar 8, 2021
1 parent c1aab3f commit 88b354e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion config/bidderinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ func (r infoReaderFromDisk) Read(bidder string) ([]byte, error) {
return ioutil.ReadFile(path)
}

// ToGVLVendorIDMap transforms a BidderInfos object to a map of bidder name to GVL id. Disabled
// bidders are omitted from the result.
func (infos BidderInfos) ToGVLVendorIDMap() map[openrtb_ext.BidderName]uint16 {
m := make(map[openrtb_ext.BidderName]uint16, len(infos))
for name, info := range infos {
if info.GVLVendorID != 0 {
if info.Enabled && info.GVLVendorID != 0 {
m[openrtb_ext.BidderName(name)] = info.GVLVendorID
}
}
Expand Down
16 changes: 16 additions & 0 deletions config/bidderinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,19 @@ type fakeInfoReader struct {
func (r fakeInfoReader) Read(bidder string) ([]byte, error) {
return []byte(r.content), r.err
}

func TestToGVLVendorIDMap(t *testing.T) {
givenBidderInfos := BidderInfos{
"bidderA": BidderInfo{Enabled: true, GVLVendorID: 0},
"bidderB": BidderInfo{Enabled: true, GVLVendorID: 100},
"bidderC": BidderInfo{Enabled: false, GVLVendorID: 0},
"bidderD": BidderInfo{Enabled: false, GVLVendorID: 200},
}

expectedGVLVendorIDMap := map[openrtb_ext.BidderName]uint16{
"bidderB": 100,
}

result := givenBidderInfos.ToGVLVendorIDMap()
assert.Equal(t, expectedGVLVendorIDMap, result)
}

0 comments on commit 88b354e

Please sign in to comment.