Skip to content

Commit

Permalink
DCOPS-1343: Handle legacy invalid profiles (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-nilesh-chate authored Oct 11, 2023
1 parent 461764f commit bb85e65
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/pubmatic/openwrap/database/mysql/adunit_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ func (db *mySqlDB) GetAdunitConfig(profileID, displayVersion int) (*adunitconfig
adunitConfig.ConfigPattern = models.MACRO_AD_UNIT_ID
}

// safe check for old legacy profiles
// new profiles cannot be created as UI-API has config object validation
if adunitConfig.Config == nil {
adunitConfig.Config = make(map[string]*adunitconfig.AdConfig)
}

if _, ok := adunitConfig.Config["default"]; !ok {
adunitConfig.Config["default"] = &adunitconfig.AdConfig{}
}
Expand Down
30 changes: 30 additions & 0 deletions modules/pubmatic/openwrap/database/mysql/adunit_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,36 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) {
return db
},
},
{
name: "config key not present",
fields: fields{
cfg: config.Database{
Queries: config.Queries{
GetAdunitConfigQuery: "^SELECT (.+) FROM wrapper_media_config (.+)",
},
},
},
args: args{
profileID: 5890,
displayVersion: 1,
},
want: &adunitconfig.AdUnitConfig{
ConfigPattern: "_DIV_",
Config: map[string]*adunitconfig.AdConfig{
"default": {},
},
},
wantErr: false,
setup: func() *sql.DB {
db, mock, err := sqlmock.New()
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
rows := sqlmock.NewRows([]string{"adunitConfig"}).AddRow(`{"configPattern": "_DIV_"}`)
mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_media_config (.+)")).WillReturnRows(rows)
return db
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit bb85e65

Please sign in to comment.