Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into prebid_v2.19.0-1
  • Loading branch information
Ankit-Pinge committed Jun 14, 2024
2 parents 38fcf3a + 2262e6d commit f7752b4
Show file tree
Hide file tree
Showing 103 changed files with 6,069 additions and 1,195 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ mockgenmetrics:
mkdir -p modules/pubmatic/openwrap/metrics/mock
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/modules/pubmatic/openwrap/metrics MetricsEngine > modules/pubmatic/openwrap/metrics/mock/mock.go

mockgengeodb:
mkdir -p modules/pubmatic/openwrap/geodb/mock
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/modules/pubmatic/openwrap/geodb Geography > modules/pubmatic/openwrap/geodb/mock/mock.go

mockgenlogger:
mkdir -p analytics/pubmatic/mhttp/mock
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/analytics/pubmatic/mhttp HttpCallInterface,MultiHttpContextInterface > analytics/pubmatic/mhttp/mock/mock.go
Expand Down
2 changes: 0 additions & 2 deletions adapters/bidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ 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
40 changes: 15 additions & 25 deletions adapters/ortbbidder/bidderparams/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@ 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
Location string // do not update this parameter for each request, its being shared across all requests
}

// config contains mappings requestParams and responseParams
Expand All @@ -27,28 +16,29 @@ 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)
// NewBidderConfig initializes and returns the object of BidderConfig
func NewBidderConfig() *BidderConfig {
return &BidderConfig{
bidderConfigMap: make(map[string]*config),
}
}

// SetRequestParams sets the bidder specific requestParams
func (bcfg *BidderConfig) SetRequestParams(bidderName string, requestParams map[string]BidderParamMapper) {
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
func (bcfg *BidderConfig) GetRequestParams(bidderName string) map[string]BidderParamMapper {
if len(bcfg.bidderConfigMap) == 0 {
return nil
}
bidderConfig, _ := bcfg.bidderConfigMap[bidderName]
bidderConfig := bcfg.bidderConfigMap[bidderName]
if bidderConfig == nil {
return nil, false
return nil
}
return bidderConfig.requestParams, true
return bidderConfig.requestParams
}
181 changes: 28 additions & 153 deletions adapters/ortbbidder/bidderparams/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,15 @@ func TestSetRequestParams(t *testing.T) {
bidderName string
requestParams map[string]BidderParamMapper
}

type want struct {
bidderCfg *BidderConfig
}
tests := []struct {
name string
fields fields
args args
want *BidderConfig
want want
}{
{
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{
Expand All @@ -74,16 +34,18 @@ func TestSetRequestParams(t *testing.T) {
bidderName: "test",
requestParams: map[string]BidderParamMapper{
"param-1": {
location: []string{"path"},
Location: "path",
},
},
},
want: &BidderConfig{
bidderConfigMap: map[string]*config{
"test": {
requestParams: map[string]BidderParamMapper{
"param-1": {
location: []string{"path"},
want: want{
bidderCfg: &BidderConfig{
bidderConfigMap: map[string]*config{
"test": {
requestParams: map[string]BidderParamMapper{
"param-1": {
Location: "path",
},
},
},
},
Expand All @@ -98,7 +60,7 @@ func TestSetRequestParams(t *testing.T) {
"test": {
requestParams: map[string]BidderParamMapper{
"param-1": {
location: []string{"path-1"},
Location: "path-1",
},
},
},
Expand All @@ -109,16 +71,18 @@ func TestSetRequestParams(t *testing.T) {
bidderName: "test",
requestParams: map[string]BidderParamMapper{
"param-2": {
location: []string{"path-2"},
Location: "path-2",
},
},
},
want: &BidderConfig{
bidderConfigMap: map[string]*config{
"test": {
requestParams: map[string]BidderParamMapper{
"param-2": {
location: []string{"path-2"},
want: want{
bidderCfg: &BidderConfig{
bidderConfigMap: map[string]*config{
"test": {
requestParams: map[string]BidderParamMapper{
"param-2": {
Location: "path-2",
},
},
},
},
Expand All @@ -128,8 +92,8 @@ func TestSetRequestParams(t *testing.T) {
}
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")
tt.fields.bidderConfig.SetRequestParams(tt.args.bidderName, tt.args.requestParams)
assert.Equal(t, tt.want.bidderCfg, tt.fields.bidderConfig, "mismatched bidderConfig")
})
}
}
Expand All @@ -143,27 +107,13 @@ func TestGetBidderRequestProperties(t *testing.T) {
}
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{
Expand All @@ -176,7 +126,6 @@ func TestGetBidderRequestProperties(t *testing.T) {
},
want: want{
requestParams: nil,
found: false,
},
},
{
Expand All @@ -193,7 +142,6 @@ func TestGetBidderRequestProperties(t *testing.T) {
},
want: want{
requestParams: nil,
found: false,
},
},
{
Expand All @@ -210,7 +158,6 @@ func TestGetBidderRequestProperties(t *testing.T) {
},
want: want{
requestParams: nil,
found: false,
},
},
{
Expand All @@ -221,7 +168,7 @@ func TestGetBidderRequestProperties(t *testing.T) {
"test": {
requestParams: map[string]BidderParamMapper{
"param-1": {
location: []string{"value-1"},
Location: "value-1",
},
},
},
Expand All @@ -234,88 +181,16 @@ func TestGetBidderRequestProperties(t *testing.T) {
want: want{
requestParams: map[string]BidderParamMapper{
"param-1": {
location: []string{"value-1"},
Location: "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)
params := 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")
})
}
}
6 changes: 3 additions & 3 deletions adapters/ortbbidder/bidderparams/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func LoadBidderConfig(dirPath string, isBidderAllowed func(string) bool) (*Bidde
if err != nil {
return nil, fmt.Errorf("error:[%s] dirPath:[%s]", err.Error(), dirPath)
}
bidderConfigMap := &BidderConfig{bidderConfigMap: make(map[string]*config)}
bidderConfigMap := NewBidderConfig()
for _, file := range files {
bidderName, ok := strings.CutSuffix(file.Name(), ".json")
if !ok {
Expand All @@ -36,7 +36,7 @@ func LoadBidderConfig(dirPath string, isBidderAllowed func(string) bool) (*Bidde
if err != nil {
return nil, err
}
bidderConfigMap.setRequestParams(bidderName, requestParams)
bidderConfigMap.SetRequestParams(bidderName, requestParams)
}
return bidderConfigMap, nil
}
Expand Down Expand Up @@ -78,7 +78,7 @@ func prepareRequestParams(bidderName string, requestParamsConfig map[string]any)
return nil, fmt.Errorf("error:[incorrect_location_in_bidderparam] bidder:[%s] bidderParam:[%s]", bidderName, paramName)
}
requestParams[paramName] = BidderParamMapper{
location: strings.Split(locationStr, "."),
Location: locationStr,
}
}
return requestParams, nil
Expand Down
Loading

0 comments on commit f7752b4

Please sign in to comment.