Skip to content

Commit

Permalink
Fix: Not to log stat for profile with no adunitconfig (#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-saurabh-narkhede authored Oct 17, 2023
1 parent bb85e65 commit 24d8f76
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/pubmatic/openwrap/database/mysql/adunit_config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mysql

import (
"database/sql"
"encoding/json"
"strconv"
"strings"
Expand All @@ -21,6 +22,9 @@ func (db *mySqlDB) GetAdunitConfig(profileID, displayVersion int) (*adunitconfig
var adunitConfigJSON string
err := db.conn.QueryRow(adunitConfigQuery).Scan(&adunitConfigJSON)
if err != nil {
if err == sql.ErrNoRows {
return nil, nil
}
return nil, err
}

Expand Down
25 changes: 25 additions & 0 deletions modules/pubmatic/openwrap/database/mysql/adunit_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) {
return db
},
},
{
name: "adunitconfig not found for profile(No rows error)",
fields: fields{
cfg: config.Database{
Queries: config.Queries{
GetAdunitConfigForLiveVersion: "^SELECT (.+) FROM wrapper_media_config (.+) LIVE",
},
},
},
args: args{
profileID: 5890,
displayVersion: 0,
},
want: nil,
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{})
mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_media_config (.+) LIVE")).WillReturnRows(rows)
return db
},
},
{
name: "query with display version id 0",
fields: fields{
Expand Down

0 comments on commit 24d8f76

Please sign in to comment.