forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #801 from PubMatic-OpenWrap/ci
Release_30th_May_2024
- Loading branch information
Showing
65 changed files
with
8,133 additions
and
1,318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
}) | ||
} | ||
} |
Oops, something went wrong.