Skip to content

Commit

Permalink
Merge pull request #801 from PubMatic-OpenWrap/ci
Browse files Browse the repository at this point in the history
Release_30th_May_2024
  • Loading branch information
pm-viral-vala authored May 27, 2024
2 parents 273ce7d + b23eda8 commit 98d1802
Show file tree
Hide file tree
Showing 65 changed files with 8,133 additions and 1,318 deletions.
2 changes: 2 additions & 0 deletions adapters/bidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ type ExtraRequestInfo struct {
PbsEntryPoint metrics.RequestType
GlobalPrivacyControlHeader string
CurrencyConversions currency.Conversions

BidderCoreName openrtb_ext.BidderName // OW specific: required for oRTB bidder
}

func NewExtraRequestInfo(c currency.Conversions) ExtraRequestInfo {
Expand Down
54 changes: 54 additions & 0 deletions adapters/ortbbidder/bidderparams/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package bidderparams

// BidderParamMapper contains property details like location
type BidderParamMapper struct {
location []string
}

// GetLocation returns the location of bidderParam
func (bpm *BidderParamMapper) GetLocation() []string {
return bpm.location
}

// SetLocation sets the location in BidderParamMapper
// Do not modify the location of bidderParam unless you are writing unit test case
func (bpm *BidderParamMapper) SetLocation(location []string) {
bpm.location = location
}

// config contains mappings requestParams and responseParams
type config struct {
requestParams map[string]BidderParamMapper
responseParams map[string]BidderParamMapper
}

// BidderConfig contains map of bidderName to its requestParams and responseParams
type BidderConfig struct {
bidderConfigMap map[string]*config
}

// setRequestParams sets the bidder specific requestParams
func (bcfg *BidderConfig) setRequestParams(bidderName string, requestParams map[string]BidderParamMapper) {
if bcfg == nil {
return
}
if bcfg.bidderConfigMap == nil {
bcfg.bidderConfigMap = make(map[string]*config)
}
if _, found := bcfg.bidderConfigMap[bidderName]; !found {
bcfg.bidderConfigMap[bidderName] = &config{}
}
bcfg.bidderConfigMap[bidderName].requestParams = requestParams
}

// GetRequestParams returns bidder specific requestParams
func (bcfg *BidderConfig) GetRequestParams(bidderName string) (map[string]BidderParamMapper, bool) {
if bcfg == nil || len(bcfg.bidderConfigMap) == 0 {
return nil, false
}
bidderConfig, _ := bcfg.bidderConfigMap[bidderName]
if bidderConfig == nil {
return nil, false
}
return bidderConfig.requestParams, true
}
321 changes: 321 additions & 0 deletions adapters/ortbbidder/bidderparams/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,321 @@
package bidderparams

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestSetRequestParams(t *testing.T) {
type fields struct {
bidderConfig *BidderConfig
}
type args struct {
bidderName string
requestParams map[string]BidderParamMapper
}

tests := []struct {
name string
fields fields
args args
want *BidderConfig
}{
{
name: "bidderConfig_is_nil",
fields: fields{
bidderConfig: nil,
},
args: args{
bidderName: "test",
requestParams: map[string]BidderParamMapper{
"adunit": {
location: []string{"ext", "adunit"},
},
},
},
want: nil,
},
{
name: "bidderConfigMap_is_nil",
fields: fields{
bidderConfig: &BidderConfig{
bidderConfigMap: nil,
},
},
args: args{
bidderName: "test",
requestParams: map[string]BidderParamMapper{
"adunit": {
location: []string{"ext", "adunit"},
},
},
},
want: &BidderConfig{
bidderConfigMap: map[string]*config{
"test": {
requestParams: map[string]BidderParamMapper{
"adunit": {
location: []string{"ext", "adunit"},
},
},
},
},
},
},
{
name: "bidderName_not_found",
fields: fields{
bidderConfig: &BidderConfig{
bidderConfigMap: map[string]*config{},
},
},
args: args{
bidderName: "test",
requestParams: map[string]BidderParamMapper{
"param-1": {
location: []string{"path"},
},
},
},
want: &BidderConfig{
bidderConfigMap: map[string]*config{
"test": {
requestParams: map[string]BidderParamMapper{
"param-1": {
location: []string{"path"},
},
},
},
},
},
},
{
name: "bidderName_found",
fields: fields{
bidderConfig: &BidderConfig{
bidderConfigMap: map[string]*config{
"test": {
requestParams: map[string]BidderParamMapper{
"param-1": {
location: []string{"path-1"},
},
},
},
},
},
},
args: args{
bidderName: "test",
requestParams: map[string]BidderParamMapper{
"param-2": {
location: []string{"path-2"},
},
},
},
want: &BidderConfig{
bidderConfigMap: map[string]*config{
"test": {
requestParams: map[string]BidderParamMapper{
"param-2": {
location: []string{"path-2"},
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.fields.bidderConfig.setRequestParams(tt.args.bidderName, tt.args.requestParams)
assert.Equal(t, tt.want, tt.fields.bidderConfig, "mismatched bidderConfig")
})
}
}

func TestGetBidderRequestProperties(t *testing.T) {
type fields struct {
biddersConfig *BidderConfig
}
type args struct {
bidderName string
}
type want struct {
requestParams map[string]BidderParamMapper
found bool
}
tests := []struct {
name string
fields fields
args args
want want
}{
{
name: "BidderConfig_is_nil",
fields: fields{
biddersConfig: nil,
},
args: args{
bidderName: "test",
},
want: want{
requestParams: nil,
found: false,
},
},
{
name: "BidderConfigMap_is_nil",
fields: fields{
biddersConfig: &BidderConfig{
bidderConfigMap: nil,
},
},
args: args{
bidderName: "test",
},
want: want{
requestParams: nil,
found: false,
},
},
{
name: "BidderName_absent_in_biddersConfigMap",
fields: fields{
biddersConfig: &BidderConfig{
bidderConfigMap: map[string]*config{
"ortb": {},
},
},
},
args: args{
bidderName: "test",
},
want: want{
requestParams: nil,
found: false,
},
},
{
name: "BidderName_present_but_config_is_nil",
fields: fields{
biddersConfig: &BidderConfig{
bidderConfigMap: map[string]*config{
"ortb": nil,
},
},
},
args: args{
bidderName: "test",
},
want: want{
requestParams: nil,
found: false,
},
},
{
name: "BidderName_present_in_biddersConfigMap",
fields: fields{
biddersConfig: &BidderConfig{
bidderConfigMap: map[string]*config{
"test": {
requestParams: map[string]BidderParamMapper{
"param-1": {
location: []string{"value-1"},
},
},
},
},
},
},
args: args{
bidderName: "test",
},
want: want{
requestParams: map[string]BidderParamMapper{
"param-1": {
location: []string{"value-1"},
},
},
found: true,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
params, found := tt.fields.biddersConfig.GetRequestParams(tt.args.bidderName)
assert.Equal(t, tt.want.requestParams, params, "mismatched requestParams")
assert.Equal(t, tt.want.found, found, "mismatched found value")
})
}
}

func TestBidderParamMapperGetLocation(t *testing.T) {
tests := []struct {
name string
bpm BidderParamMapper
want []string
}{
{
name: "location_is_nil",
bpm: BidderParamMapper{
location: nil,
},
want: nil,
},
{
name: "location_is_non_empty",
bpm: BidderParamMapper{
location: []string{"req", "ext"},
},
want: []string{"req", "ext"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.bpm.GetLocation()
assert.Equal(t, tt.want, got, "mismatched location")
})
}
}

func TestBidderParamMapperSetLocation(t *testing.T) {
type args struct {
location []string
}
tests := []struct {
name string
bpm BidderParamMapper
args args
want BidderParamMapper
}{
{
name: "set_location",
bpm: BidderParamMapper{},
args: args{
location: []string{"req", "ext"},
},
want: BidderParamMapper{
location: []string{"req", "ext"},
},
},
{
name: "override_location",
bpm: BidderParamMapper{
location: []string{"imp", "ext"},
},
args: args{
location: []string{"req", "ext"},
},
want: BidderParamMapper{
location: []string{"req", "ext"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.bpm.SetLocation(tt.args.location)
assert.Equal(t, tt.want, tt.bpm, "mismatched location")
})
}
}
Loading

0 comments on commit 98d1802

Please sign in to comment.