Skip to content

Commit

Permalink
returned query specific error
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-priyanka-bagade committed Nov 17, 2024
1 parent 7f077d4 commit 0ac7132
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 27 deletions.
2 changes: 1 addition & 1 deletion modules/pubmatic/openwrap/cache/gocache/adpod_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func (c *cache) populateCacheWithAdpodConfig(pubID, profileID, displayVersion int) (err error) {
adpodConfig, err := c.db.GetAdpodConfig(pubID, profileID, displayVersion)
if err != nil {
glog.Errorf(models.ErrDBQueryFailed, models.LiveVersionInnerQuery+"/"+models.DisplayVersionInnerQuery, pubID, profileID, err)
glog.Errorf(models.ErrDBQueryFailed, models.GetAdpodConfig, pubID, profileID, err)
return err
}

Expand Down
9 changes: 5 additions & 4 deletions modules/pubmatic/openwrap/database/mysql/adpod_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mysql
import (
"context"
"encoding/json"
"errors"
"strings"
"time"

Expand All @@ -13,15 +14,15 @@ import (
func (db *mySqlDB) GetAdpodConfig(pubID, profileID, displayVersion int) (*adpodconfig.AdpodConfig, error) {
versionID, displayVersion, _, _, err := db.getVersionIdAndProfileDetails(profileID, displayVersion, pubID)
if err != nil {
return nil, err
return nil, errors.New("LiveVersionInnerQuery/DisplayVersionInnerQuery Failure Error")
}

ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Millisecond*time.Duration(db.cfg.MaxDbContextTimeout)))
defer cancel()

rows, err := db.conn.QueryContext(ctx, db.cfg.Queries.GetAdpodConfig, versionID)
if err != nil {
return nil, err
return nil, errors.New("GetAdpodConfigQuery Failure Error")
}
defer rows.Close()

Expand All @@ -48,12 +49,12 @@ func (db *mySqlDB) GetAdpodConfig(pubID, profileID, displayVersion int) (*adpodc
}

if err != nil {
return nil, err
return nil, errors.New("Unmarshal Error")
}
}

if err = rows.Err(); err != nil {
return nil, err
return nil, errors.New("Row scan Failure Error")
}

return config, nil
Expand Down
3 changes: 2 additions & 1 deletion modules/pubmatic/openwrap/database/mysql/partner_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mysql
import (
"context"
"database/sql"
"errors"
"fmt"
"strconv"
"time"
Expand All @@ -15,7 +16,7 @@ import (
func (db *mySqlDB) GetActivePartnerConfigurations(pubID, profileID int, displayVersion int) (map[int]map[string]string, error) {
versionID, displayVersionID, platform, profileType, err := db.getVersionIdAndProfileDetails(profileID, displayVersion, pubID)
if err != nil {
return nil, err
return nil, errors.New("LiveVersionInnerQuery/DisplayVersionInnerQuery Failure Error")
}

partnerConfigMap, err := db.getActivePartnerConfigurations(profileID, versionID)
Expand Down
26 changes: 7 additions & 19 deletions modules/pubmatic/openwrap/database/mysql/partner_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) {
fields fields
args args
want map[int]map[string]string
wantErr bool
wantErr error
setup func() *sql.DB
}{
{
Expand All @@ -46,7 +46,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) {
},

want: nil,
wantErr: true,
wantErr: errors.New("LiveVersionInnerQuery/DisplayVersionInnerQuery Failure Error"),
setup: func() *sql.DB {
db, mock, err := sqlmock.New()
if err != nil {
Expand Down Expand Up @@ -74,18 +74,15 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) {
profileID: 19109,
displayVersion: 0,
},

want: nil,
wantErr: true,
wantErr: errors.New("all expectations were already fulfilled, call to Query '%!(EXTRA int=1000, int=251, int=19109, int=251, int=251)' with args [] was not expected"),
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)
}

rowsWrapperVersion := sqlmock.NewRows([]string{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY, models.ProfileTypeKey}).AddRow("251", "9", models.PLATFORM_DISPLAY, "1")
mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion)

return db
},
},
Expand All @@ -105,7 +102,6 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) {
profileID: 19109,
displayVersion: 0,
},

want: map[int]map[string]string{
101: {
"bidderCode": "pubmatic",
Expand All @@ -129,16 +125,14 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) {
"type": "1",
},
},
wantErr: false,
wantErr: nil,
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)
}

rowsWrapperVersion := sqlmock.NewRows([]string{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY, models.ProfileTypeKey}).AddRow("251", "9", models.PLATFORM_DISPLAY, "1")
mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion)

rowsPartnerConfig := sqlmock.NewRows([]string{"partnerId", "prebidPartnerName", "bidderCode", "isAlias", "entityTypeID", "testConfig", "vendorId", "keyName", "value"}).
AddRow("-1", "ALL", "ALL", 0, -1, 0, -1, "platform", "display").
AddRow("-1", "ALL", "ALL", 0, -1, 0, -1, "gdpr", "0").
Expand All @@ -165,7 +159,6 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) {
profileID: 19109,
displayVersion: 3,
},

want: map[int]map[string]string{
101: {
"bidderCode": "pubmatic",
Expand All @@ -189,16 +182,14 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) {
"type": "1",
},
},
wantErr: false,
wantErr: nil,
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)
}

rowsWrapperVersion := sqlmock.NewRows([]string{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY, models.ProfileTypeKey}).AddRow("251", "9", models.PLATFORM_DISPLAY, "1")
mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 3, 5890).WillReturnRows(rowsWrapperVersion)

rowsPartnerConfig := sqlmock.NewRows([]string{"partnerId", "prebidPartnerName", "bidderCode", "isAlias", "entityTypeID", "testConfig", "vendorId", "keyName", "value"}).
AddRow("-1", "ALL", "ALL", 0, -1, 0, -1, "platform", "display").
AddRow("-1", "ALL", "ALL", 0, -1, 0, -1, "gdpr", "0").
Expand All @@ -225,7 +216,6 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) {
profileID: 19109,
displayVersion: 3,
},

want: map[int]map[string]string{
234: {
"bidderCode": "test-vastbidder",
Expand Down Expand Up @@ -257,16 +247,14 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) {
"type": "1",
},
},
wantErr: false,
wantErr: nil,
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)
}

rowsWrapperVersion := sqlmock.NewRows([]string{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY, models.ProfileTypeKey}).AddRow("251", "9", models.PLATFORM_DISPLAY, "1")
mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 3, 5890).WillReturnRows(rowsWrapperVersion)

rowsPartnerConfig := sqlmock.NewRows([]string{"partnerId", "prebidPartnerName", "bidderCode", "isAlias", "entityTypeID", "testConfig", "vendorId", "keyName", "value"}).
AddRow("-1", "ALL", "ALL", 0, -1, 0, -1, "platform", "display").
AddRow("-1", "ALL", "ALL", 0, -1, 0, -1, "gdpr", "0").
Expand All @@ -287,7 +275,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) {
cfg: tt.fields.cfg,
}
gotPartnerConfigMap, err := db.GetActivePartnerConfigurations(tt.args.pubID, tt.args.profileID, tt.args.displayVersion)
if (err != nil) != tt.wantErr {
if err != nil && tt.wantErr != nil && err.Error() != tt.wantErr.Error() {
t.Errorf("mySqlDB.GetActivePartnerConfigurations() error = %v, wantErr %v", err, tt.wantErr)
return
}
Expand Down
4 changes: 2 additions & 2 deletions modules/pubmatic/openwrap/models/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,8 @@ const (
PublisherFeatureMapQuery = "GetPublisherFeatureMapQuery"
AnalyticsThrottlingPercentageQuery = "GetAnalyticsThrottlingPercentage"
GetAdpodConfig = "GetAdpodConfig"
DisplayVersionInnerQuery = "DisplayVersionInnerQuery"
LiveVersionInnerQuery = "LiveVersionInnerQuery"
// DisplayVersionInnerQuery = "DisplayVersionInnerQuery"
// LiveVersionInnerQuery = "LiveVersionInnerQuery"
//PMSlotToMappings = "GetPMSlotToMappings"
TestQuery = "TestQuery"
ProfileTypePlatformMapQuery = "GetProfileTypePlatformMapQuery"
Expand Down

0 comments on commit 0ac7132

Please sign in to comment.