mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
uniformed the error for duplicate key
This commit is contained in:
@@ -55,6 +55,27 @@ func TestCDRsITInternal(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCDRsITMongo(t *testing.T) {
|
||||
cdrsConfDIR = "cdrsv1mongo"
|
||||
for _, stest := range sTestsCDRsIT {
|
||||
t.Run(cdrsConfDIR, stest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCDRsITMySql(t *testing.T) {
|
||||
cdrsConfDIR = "cdrsv1mysql"
|
||||
for _, stest := range sTestsCDRsIT {
|
||||
t.Run(cdrsConfDIR, stest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCDRsITPostgres(t *testing.T) {
|
||||
cdrsConfDIR = "cdrsv1postgres"
|
||||
for _, stest := range sTestsCDRsIT {
|
||||
t.Run(cdrsConfDIR, stest)
|
||||
}
|
||||
}
|
||||
|
||||
func testV1CDRsInitConfig(t *testing.T) {
|
||||
var err error
|
||||
cdrsCfgPath = path.Join(*dataDir, "conf", "samples", cdrsConfDIR)
|
||||
|
||||
44
data/conf/samples/cdrsv1mongo/cgrates.json
Normal file
44
data/conf/samples/cdrsv1mongo/cgrates.json
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
// CGRateS Configuration file
|
||||
//
|
||||
// Used in apier/v1/cdrs_it_test
|
||||
|
||||
|
||||
"data_db": {
|
||||
"db_type": "mongo",
|
||||
"db_name": "10",
|
||||
"db_port": 27017,
|
||||
},
|
||||
|
||||
|
||||
"stor_db": {
|
||||
"db_type": "mongo",
|
||||
"db_name": "cgrates",
|
||||
"db_port": 27017,
|
||||
},
|
||||
|
||||
"rals": {
|
||||
"enabled": true
|
||||
},
|
||||
|
||||
|
||||
"scheduler": {
|
||||
"enabled": true
|
||||
},
|
||||
|
||||
|
||||
"cdrs": {
|
||||
"enabled": true,
|
||||
"rals_conns": [
|
||||
{"address": "127.0.0.1:2012", "transport":"*json"},
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
"apier": {
|
||||
"scheduler_conns": [ // connections to SchedulerS for reloads
|
||||
{"address": "*internal"},
|
||||
],
|
||||
},
|
||||
|
||||
}
|
||||
41
data/conf/samples/cdrsv1mysql/cgrates.json
Normal file
41
data/conf/samples/cdrsv1mysql/cgrates.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
// CGRateS Configuration file
|
||||
//
|
||||
// Used in apier/v1/cdrs_it_test
|
||||
|
||||
|
||||
"data_db": { // database used to store runtime data (eg: accounts, cdr stats)
|
||||
"db_type": "redis", // data_db type: <redis|mongo>
|
||||
"db_port": 6379, // data_db port to reach the database
|
||||
"db_name": "10", // data_db database name to connect to
|
||||
},
|
||||
|
||||
"stor_db": {
|
||||
"db_password": "CGRateS.org",
|
||||
},
|
||||
|
||||
"rals": {
|
||||
"enabled": true
|
||||
},
|
||||
|
||||
|
||||
"scheduler": {
|
||||
"enabled": true
|
||||
},
|
||||
|
||||
|
||||
"cdrs": {
|
||||
"enabled": true,
|
||||
"rals_conns": [
|
||||
{"address": "127.0.0.1:2012", "transport":"*json"},
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
"apier": {
|
||||
"scheduler_conns": [ // connections to SchedulerS for reloads
|
||||
{"address": "*internal"},
|
||||
],
|
||||
},
|
||||
|
||||
}
|
||||
43
data/conf/samples/cdrsv1postgres/cgrates.json
Normal file
43
data/conf/samples/cdrsv1postgres/cgrates.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
// CGRateS Configuration file
|
||||
//
|
||||
// Used in apier/v1/cdrs_it_test
|
||||
|
||||
|
||||
"data_db": { // database used to store runtime data (eg: accounts, cdr stats)
|
||||
"db_type": "redis", // data_db type: <redis|mongo>
|
||||
"db_port": 6379, // data_db port to reach the database
|
||||
"db_name": "10", // data_db database name to connect to
|
||||
},
|
||||
|
||||
"stor_db": {
|
||||
"db_type": "postgres", // stor database type to use: <mysql|postgres>
|
||||
"db_port": 5432, // the port to reach the stordb
|
||||
"db_password": "CGRateS.org",
|
||||
},
|
||||
|
||||
"rals": {
|
||||
"enabled": true
|
||||
},
|
||||
|
||||
|
||||
"scheduler": {
|
||||
"enabled": true
|
||||
},
|
||||
|
||||
|
||||
"cdrs": {
|
||||
"enabled": true,
|
||||
"rals_conns": [
|
||||
{"address": "127.0.0.1:2012", "transport":"*json"},
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
"apier": {
|
||||
"scheduler_conns": [ // connections to SchedulerS for reloads
|
||||
{"address": "*internal"},
|
||||
],
|
||||
},
|
||||
|
||||
}
|
||||
@@ -943,6 +943,9 @@ func (ms *MongoStorage) SetCDR(cdr *CDR, allowUpdate bool) (err error) {
|
||||
// return err
|
||||
} else {
|
||||
_, err = ms.getCol(ColCDRs).InsertOne(sctx, cdr)
|
||||
if err != nil && strings.Contains(err.Error(), "E11000") { // Mongo returns E11000 when key is duplicated
|
||||
err = utils.ErrExists
|
||||
}
|
||||
}
|
||||
return err
|
||||
})
|
||||
|
||||
@@ -879,6 +879,9 @@ func (self *SQLStorage) SetCDR(cdr *CDR, allowUpdate bool) error {
|
||||
if saved.Error != nil {
|
||||
tx.Rollback()
|
||||
if !allowUpdate {
|
||||
if strings.Contains(saved.Error.Error(), "1062") || strings.Contains(saved.Error.Error(), "duplicate key") { // returns 1062/pq when key is duplicated
|
||||
return utils.ErrExists
|
||||
}
|
||||
return saved.Error
|
||||
}
|
||||
tx = self.db.Begin()
|
||||
|
||||
Reference in New Issue
Block a user