Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTT-1799: support macros in oRTB bidder endpoint-url #805

Merged
merged 11 commits into from
Jun 12, 2024
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
31 changes: 7 additions & 24 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 @@ -29,26 +18,20 @@ type BidderConfig struct {

// 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
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
}
179 changes: 27 additions & 152 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 @@ -129,7 +93,7 @@ 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")
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")
})
}
}
2 changes: 1 addition & 1 deletion adapters/ortbbidder/bidderparams/parser.go
Original file line number Diff line number Diff line change
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
10 changes: 5 additions & 5 deletions adapters/ortbbidder/bidderparams/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestPrepareRequestParams(t *testing.T) {
},
want: want{
requestParams: map[string]BidderParamMapper{
"adunitid": {location: []string{"app", "adunitid"}},
"adunitid": {Location: "app.adunitid"},
},
err: nil,
},
Expand All @@ -144,8 +144,8 @@ func TestPrepareRequestParams(t *testing.T) {
},
want: want{
requestParams: map[string]BidderParamMapper{
"adunitid": {location: []string{"app", "adunitid"}},
"slotname": {location: []string{"ext", "slot"}},
"adunitid": {Location: "app.adunitid"},
"slotname": {Location: "ext.slot"},
},
err: nil,
},
Expand Down Expand Up @@ -249,8 +249,8 @@ func TestLoadBidderConfig(t *testing.T) {
bidderConfigMap: map[string]*config{
"owortb_test": {
requestParams: map[string]BidderParamMapper{
"adunitid": {location: []string{"app", "adunit", "id"}},
"slotname": {location: []string{"ext", "slotname"}},
"adunitid": {Location: "app.adunit.id"},
"slotname": {Location: "ext.slotname"},
},
},
}},
Expand Down
Loading
Loading