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

UOE-10950 : kgpv and kgpsv getting empty in logger for flag test=1 #877

Merged
merged 10 commits into from
Aug 30, 2024
11 changes: 1 addition & 10 deletions modules/pubmatic/openwrap/bidderparams/pubmatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,7 @@ func PreparePubMaticParamsV25(rctx models.RequestCtx, cache cache.Cache, bidRequ
isRegexKGP = true
}

if rctx.IsTestRequest == 1 {
matchedSlot, matchedPattern, isRegexSlot = getMatchingSlotAndPattern(rctx, cache, slots, slotMap, slotMappingInfo, isRegexKGP, isRegexSlot, partnerID, &extImpPubMatic, imp)
params, err := json.Marshal(extImpPubMatic)
return matchedSlot, matchedPattern, isRegexSlot, params, err
}

if rctx.IsTestRequest > 0 {
if len(slots) > 0 {
extImpPubMatic.AdSlot = slots[0]
}
if rctx.IsTestRequest == models.TestValueTwo {
params, err := json.Marshal(extImpPubMatic)
return extImpPubMatic.AdSlot, "", false, params, err
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
293 changes: 285 additions & 8 deletions modules/pubmatic/openwrap/bidderparams/pubmatic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,78 @@ func TestPreparePubMaticParamsV25(t *testing.T) {
imp: getTestImp("/Test_Adunit1234", true, false),
partnerID: 1,
},
setup: func() {
mockCache.EXPECT().GetMappingsFromCacheV25(gomock.Any(), gomock.Any()).Return(map[string]models.SlotMapping{
"/test_adunit12345@div1@200x300": {
PartnerId: 1,
AdapterId: 1,
SlotName: "/Test_Adunit1234@Div1@200x300",
SlotMappings: map[string]interface{}{
"site": "12313",
"adtag": "45343",
"slotName": "/Test_Adunit1234@Div1@200x300",
},
},
})
mockCache.EXPECT().GetSlotToHashValueMapFromCacheV25(gomock.Any(), gomock.Any()).Return(models.SlotMappingInfo{
OrderedSlotList: []string{"*", ".*@.*@.*"},
HashValueMap: map[string]string{
".*@.*@.*": "2aa34b52a9e941c1594af7565e599c8d", // Code should match the given slot name with this regex
},
})
mockCache.EXPECT().Get("psregex_5890_123_1_1_/Test_Adunit1234@Div1@200x300").Return(nil, false)
mockCache.EXPECT().Set("psregex_5890_123_1_1_/Test_Adunit1234@Div1@200x300", regexSlotEntry{SlotName: "/Test_Adunit1234@Div1@200x300", RegexPattern: ".*@.*@.*"}).Times(1)
},
want: want{
matchedSlot: "/Test_Adunit1234@Div1@200x300",
matchedPattern: ".*@.*@.*",
isRegexSlot: true,
params: []byte(`{"publisherId":"5890","adSlot":"2aa34b52a9e941c1594af7565e599c8d","wrapper":{"version":1,"profile":123},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`),
wantErr: false,
},
},
{
name: "exact_matched_slot_found_adslot_updated_from_PubMatic_secondary_flow",
args: args{
rctx: models.RequestCtx{
IsTestRequest: 0,
PubID: 5890,
ProfileID: 123,
DisplayID: 1,
PartnerConfigMap: map[int]map[string]string{
1: {
models.PREBID_PARTNER_NAME: "pubmatic",
models.BidderCode: "pubmatic",
models.TIMEOUT: "200",
models.KEY_GEN_PATTERN: "_AU_@_DIV_@_W_x_H_",
models.SERVER_SIDE_FLAG: "1",
models.KEY_PROFILE_ID: "1323",
},
},
},
cache: mockCache,
impExt: models.ImpExtension{
Bidder: map[string]*models.BidderExtension{
"pubmatic": {
KeyWords: []models.KeyVal{
{
Key: "test_key1",
Values: []string{"test_value1", "test_value2"},
},
{
Key: "test_key2",
Values: []string{"test_value1", "test_value2"},
},
},
},
},
Wrapper: &models.ExtImpWrapper{
Div: "Div1",
},
},
imp: getTestImp("/Test_Adunit1234", true, false),
partnerID: 1,
},
setup: func() {
mockCache.EXPECT().GetMappingsFromCacheV25(gomock.Any(), gomock.Any()).Return(map[string]models.SlotMapping{
"/test_adunit1234@div1@200x300": {
Expand All @@ -310,7 +382,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) {
matchedSlot: "/Test_Adunit1234@Div1@200x300",
matchedPattern: "",
isRegexSlot: false,
params: []byte(`{"publisherId":"5890","adSlot":"/Test_Adunit1234@Div1@200x300","wrapper":{"version":1,"profile":123},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`),
params: []byte(`{"publisherId":"5890","adSlot":"/Test_Adunit1234@DIV1@200x300","wrapper":{"version":0,"profile":1323},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`),
wantErr: false,
},
},
Expand Down Expand Up @@ -365,7 +437,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) {
SlotMappings: map[string]interface{}{
"site": "12313",
"adtag": "45343",
"slotName": "/Test_Adunit1234@DIV1@200x300",
"slotName": "ABCD",
},
},
})
Expand All @@ -377,7 +449,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) {
matchedSlot: "/Test_Adunit1234@Div1@200x300",
matchedPattern: "",
isRegexSlot: false,
params: []byte(`{"publisherId":"5890","adSlot":"/Test_Adunit1234@DIV1@200x300","wrapper":{"version":0,"profile":1323},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`),
params: []byte(`{"publisherId":"5890","adSlot":"ABCD","wrapper":{"version":0,"profile":1323},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`),
wantErr: false,
},
},
Expand Down Expand Up @@ -715,6 +787,78 @@ func TestPreparePubMaticParamsV25(t *testing.T) {
wantErr: false,
},
},
{
name: "regex_matched_slot_found_adSlot_upadted_from_hashValue_for_test_value_1",
args: args{
rctx: models.RequestCtx{
IsTestRequest: 1,
PubID: 5890,
ProfileID: 123,
DisplayID: 1,
PartnerConfigMap: map[int]map[string]string{
1: {
models.PREBID_PARTNER_NAME: "pubmatic",
models.BidderCode: "pubmatic",
models.TIMEOUT: "200",
models.KEY_GEN_PATTERN: "_AU_@_DIV_@_W_x_H_",
models.SERVER_SIDE_FLAG: "1",
},
},
},
cache: mockCache,
impExt: models.ImpExtension{
Bidder: map[string]*models.BidderExtension{
"pubmatic": {
KeyWords: []models.KeyVal{
{
Key: "test_key1",
Values: []string{"test_value1", "test_value2"},
},
{
Key: "test_key2",
Values: []string{"test_value1", "test_value2"},
},
},
},
},
Wrapper: &models.ExtImpWrapper{
Div: "Div1",
},
},
imp: getTestImp("/Test_Adunit1234", true, false),
partnerID: 1,
},
setup: func() {
mockCache.EXPECT().GetMappingsFromCacheV25(gomock.Any(), gomock.Any()).Return(map[string]models.SlotMapping{
".*@div.*@.*": {
PartnerId: 1,
AdapterId: 1,
SlotName: "/Test_Adunit1234@Div1@200x300",
SlotMappings: map[string]interface{}{
"site": "12313",
"adtag": "45343",
},
},
})
mockCache.EXPECT().GetSlotToHashValueMapFromCacheV25(gomock.Any(), gomock.Any()).Return(models.SlotMappingInfo{
OrderedSlotList: []string{"test", "test1"},
HashValueMap: map[string]string{
".*@Div.*@.*": "2aa34b52a9e941c1594af7565e599c8d",
},
})
mockCache.EXPECT().Get("psregex_5890_123_1_1_/Test_Adunit1234@Div1@200x300").Return(regexSlotEntry{
SlotName: "/Test_Adunit1234@Div1@200x300",
RegexPattern: ".*@Div.*@.*",
}, true)
},
want: want{
matchedSlot: "/Test_Adunit1234@Div1@200x300",
matchedPattern: ".*@Div.*@.*",
isRegexSlot: true,
params: []byte(`{"publisherId":"5890","adSlot":"2aa34b52a9e941c1594af7565e599c8d","wrapper":{"version":1,"profile":123},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`),
wantErr: false,
},
},
{
name: "valid_pubmatic_native_params",
args: args{
Expand Down Expand Up @@ -1046,7 +1190,7 @@ func TestPreparePubMaticParamsV25(t *testing.T) {
},
},
{
name: "For test value 1",
name: "For_test_value_1_for_regex",
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
args: args{
rctx: models.RequestCtx{
IsTestRequest: 1,
Expand Down Expand Up @@ -1116,6 +1260,139 @@ func TestPreparePubMaticParamsV25(t *testing.T) {
wantErr: false,
},
},
{
name: "For_test_value_1_for_non_regex",
args: args{
rctx: models.RequestCtx{
IsTestRequest: 1,
PubID: 5890,
ProfileID: 123,
DisplayID: 1,
PartnerConfigMap: map[int]map[string]string{
1: {
models.PREBID_PARTNER_NAME: "pubmatic",
models.BidderCode: "pubmatic",
models.TIMEOUT: "200",
models.KEY_GEN_PATTERN: "_AU_@_W_x_H_",
models.SERVER_SIDE_FLAG: "1",
},
},
},
cache: mockCache,
impExt: models.ImpExtension{
Bidder: map[string]*models.BidderExtension{
"pubmatic": {
KeyWords: []models.KeyVal{
{
Key: "test_key1",
Values: []string{"test_value1", "test_value2"},
},
{
Key: "test_key2",
Values: []string{"test_value1", "test_value2"},
},
},
},
},
Wrapper: &models.ExtImpWrapper{
Div: "Div1",
},
},
imp: getTestImp("/Test_Adunit1234", false, false),
partnerID: 1,
},
setup: func() {
mockCache.EXPECT().GetMappingsFromCacheV25(gomock.Any(), gomock.Any()).Return(map[string]models.SlotMapping{
"/test_adunit1234@1x1": {
PartnerId: 1,
AdapterId: 1,
SlotName: "/Test_Adunit1234@1x1",
SlotMappings: map[string]interface{}{
"site": "12313",
"adtag": "45343",
models.KEY_OW_SLOT_NAME: "/Test_Adunit1234@1x1",
},
},
})
mockCache.EXPECT().GetSlotToHashValueMapFromCacheV25(gomock.Any(), gomock.Any()).Return(models.SlotMappingInfo{
OrderedSlotList: []string{"test", "test1"},
})
},
want: want{
matchedSlot: "/Test_Adunit1234@1x1",
matchedPattern: "",
isRegexSlot: false,
params: []byte(`{"publisherId":"5890","adSlot":"/Test_Adunit1234@1x1","wrapper":{"version":1,"profile":123},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`),
wantErr: false,
},
},
{
name: "for_test_value_1_exact_matched_slot_found_adslot_updated_from_PubMatic_secondary_flow",
pm-isha-bharti marked this conversation as resolved.
Show resolved Hide resolved
args: args{
rctx: models.RequestCtx{
IsTestRequest: 1,
PubID: 5890,
ProfileID: 123,
DisplayID: 1,
PartnerConfigMap: map[int]map[string]string{
1: {
models.PREBID_PARTNER_NAME: "pubmatic",
models.BidderCode: "pubmatic",
models.TIMEOUT: "200",
models.KEY_GEN_PATTERN: "_AU_@_DIV_@_W_x_H_",
models.SERVER_SIDE_FLAG: "1",
models.KEY_PROFILE_ID: "1323",
},
},
},
cache: mockCache,
impExt: models.ImpExtension{
Bidder: map[string]*models.BidderExtension{
"pubmatic": {
KeyWords: []models.KeyVal{
{
Key: "test_key1",
Values: []string{"test_value1", "test_value2"},
},
{
Key: "test_key2",
Values: []string{"test_value1", "test_value2"},
},
},
},
},
Wrapper: &models.ExtImpWrapper{
Div: "Div1",
},
},
imp: getTestImp("/Test_Adunit1234", true, false),
partnerID: 1,
},
setup: func() {
mockCache.EXPECT().GetMappingsFromCacheV25(gomock.Any(), gomock.Any()).Return(map[string]models.SlotMapping{
"/test_adunit1234@div1@200x300": {
PartnerId: 1,
AdapterId: 1,
SlotName: "/Test_Adunit1234@Div1@200x300",
SlotMappings: map[string]interface{}{
"site": "12313",
"adtag": "45343",
"slotName": "/Test_Adunit1234@DIV1@200x300",
},
},
})
mockCache.EXPECT().GetSlotToHashValueMapFromCacheV25(gomock.Any(), gomock.Any()).Return(models.SlotMappingInfo{
OrderedSlotList: []string{"test", "test1"},
})
},
want: want{
matchedSlot: "/Test_Adunit1234@Div1@200x300",
matchedPattern: "",
isRegexSlot: false,
params: []byte(`{"publisherId":"5890","adSlot":"/Test_Adunit1234@DIV1@200x300","wrapper":{"version":0,"profile":1323},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`),
wantErr: false,
},
},
{
name: "For_test_value_2_with_regex",
args: args{
Expand Down Expand Up @@ -1158,10 +1435,10 @@ func TestPreparePubMaticParamsV25(t *testing.T) {
partnerID: 1,
},
want: want{
matchedSlot: "/Test_Adunit1234@Div1@200x300",
matchedSlot: "",
matchedPattern: "",
isRegexSlot: false,
params: []byte(`{"publisherId":"5890","adSlot":"/Test_Adunit1234@Div1@200x300","wrapper":{"version":1,"profile":123},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`),
params: []byte(`{"publisherId":"5890","adSlot":"","wrapper":{"version":1,"profile":123},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`),
wantErr: false,
},
},
Expand Down Expand Up @@ -1207,10 +1484,10 @@ func TestPreparePubMaticParamsV25(t *testing.T) {
partnerID: 1,
},
want: want{
matchedSlot: "/Test_Adunit1234@200x300",
matchedSlot: "",
matchedPattern: "",
isRegexSlot: false,
params: []byte(`{"publisherId":"5890","adSlot":"/Test_Adunit1234@200x300","wrapper":{"version":1,"profile":123},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`),
params: []byte(`{"publisherId":"5890","adSlot":"","wrapper":{"version":1,"profile":123},"keywords":[{"key":"test_key1","value":["test_value1","test_value2"]},{"key":"test_key2","value":["test_value1","test_value2"]}]}`),
wantErr: false,
},
},
Expand Down
Loading