From 0ac7132617384645925924bf6b4dde7c5e1a9a8d Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Sun, 17 Nov 2024 22:44:45 +0530 Subject: [PATCH] returned query specific error --- .../openwrap/cache/gocache/adpod_config.go | 2 +- .../openwrap/database/mysql/adpod_config.go | 9 ++++--- .../openwrap/database/mysql/partner_config.go | 3 ++- .../database/mysql/partner_config_test.go | 26 +++++-------------- modules/pubmatic/openwrap/models/constants.go | 4 +-- 5 files changed, 17 insertions(+), 27 deletions(-) diff --git a/modules/pubmatic/openwrap/cache/gocache/adpod_config.go b/modules/pubmatic/openwrap/cache/gocache/adpod_config.go index 3e4ac88d4f4..de1239fe924 100644 --- a/modules/pubmatic/openwrap/cache/gocache/adpod_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/adpod_config.go @@ -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 } diff --git a/modules/pubmatic/openwrap/database/mysql/adpod_config.go b/modules/pubmatic/openwrap/database/mysql/adpod_config.go index 484805e25af..4214349381d 100644 --- a/modules/pubmatic/openwrap/database/mysql/adpod_config.go +++ b/modules/pubmatic/openwrap/database/mysql/adpod_config.go @@ -3,6 +3,7 @@ package mysql import ( "context" "encoding/json" + "errors" "strings" "time" @@ -13,7 +14,7 @@ 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))) @@ -21,7 +22,7 @@ func (db *mySqlDB) GetAdpodConfig(pubID, profileID, displayVersion int) (*adpodc 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() @@ -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 diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config.go b/modules/pubmatic/openwrap/database/mysql/partner_config.go index b47b270dfa5..1f0f7a2f6d8 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config.go @@ -3,6 +3,7 @@ package mysql import ( "context" "database/sql" + "errors" "fmt" "strconv" "time" @@ -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) diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config_test.go b/modules/pubmatic/openwrap/database/mysql/partner_config_test.go index 9c115c8b692..e25669f8f64 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config_test.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config_test.go @@ -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 }{ { @@ -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 { @@ -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 }, }, @@ -105,7 +102,6 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { profileID: 19109, displayVersion: 0, }, - want: map[int]map[string]string{ 101: { "bidderCode": "pubmatic", @@ -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"). @@ -165,7 +159,6 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { profileID: 19109, displayVersion: 3, }, - want: map[int]map[string]string{ 101: { "bidderCode": "pubmatic", @@ -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"). @@ -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", @@ -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"). @@ -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 } diff --git a/modules/pubmatic/openwrap/models/constants.go b/modules/pubmatic/openwrap/models/constants.go index 532d5bcc37c..118b041e6b8 100755 --- a/modules/pubmatic/openwrap/models/constants.go +++ b/modules/pubmatic/openwrap/models/constants.go @@ -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"