mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added test for CDRe for both mysql and mongo CDRs
This commit is contained in:
committed by
Dan Christian Bogos
parent
e13a10ea6c
commit
90012a4719
@@ -52,7 +52,7 @@ func (apier *ApierV1) GetCdrs(attrs utils.AttrGetCdrs, reply *[]*engine.External
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
if cdrs, _, err := apier.CdrDb.GetCDRs(cdrsFltr, false); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
return err
|
||||
} else if len(cdrs) == 0 {
|
||||
*reply = make([]*engine.ExternalCDR, 0)
|
||||
} else {
|
||||
|
||||
178
general_tests/cdre_it_test.go
Normal file
178
general_tests/cdre_it_test.go
Normal file
@@ -0,0 +1,178 @@
|
||||
// +build integration
|
||||
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package general_tests
|
||||
|
||||
import (
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/apier/v1"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
cdreCfgPath string
|
||||
cdreCfg *config.CGRConfig
|
||||
cdreRPC *rpc.Client
|
||||
cdreDataDir = "/usr/share/cgrates"
|
||||
cdreDelay int
|
||||
cdreConfigDIR string
|
||||
)
|
||||
|
||||
var sTestsCDRE = []func(t *testing.T){
|
||||
testCDREInitCfg,
|
||||
testCDREInitDataDb,
|
||||
testCDREResetStorDb,
|
||||
testCDREStartEngine,
|
||||
testCDRERpcConn,
|
||||
testCDREGetCdrs,
|
||||
testCDREExportNotFound,
|
||||
testCDREProcessCdr,
|
||||
testCDREExport,
|
||||
testCDREStopEngine,
|
||||
}
|
||||
|
||||
func TestCDREITMySql(t *testing.T) {
|
||||
cdreConfigDIR = "tutmysql"
|
||||
for _, stest := range sTestsCDRE {
|
||||
t.Run(cdreConfigDIR, stest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCDREITMongo(t *testing.T) {
|
||||
cdreConfigDIR = "tutmongo"
|
||||
for _, stest := range sTestsCDRE {
|
||||
t.Run(cdreConfigDIR, stest)
|
||||
}
|
||||
}
|
||||
|
||||
func testCDREInitCfg(t *testing.T) {
|
||||
var err error
|
||||
cdreCfgPath = path.Join(cdreDataDir, "conf", "samples", cdreConfigDIR)
|
||||
cdreCfg, err = config.NewCGRConfigFromFolder(cdreCfgPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cdreCfg.DataFolderPath = cdreDataDir
|
||||
config.SetCgrConfig(cdreCfg)
|
||||
switch cdreConfigDIR {
|
||||
case "tutmongo":
|
||||
cdreDelay = 4000
|
||||
default:
|
||||
cdreDelay = 2000
|
||||
}
|
||||
}
|
||||
|
||||
func testCDREInitDataDb(t *testing.T) {
|
||||
if err := engine.InitDataDb(cdreCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testCDREResetStorDb(t *testing.T) {
|
||||
if err := engine.InitStorDb(cdreCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testCDREStartEngine(t *testing.T) {
|
||||
if _, err := engine.StopStartEngine(cdreCfgPath, cdreDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testCDRERpcConn(t *testing.T) {
|
||||
var err error
|
||||
cdreRPC, err = jsonrpc.Dial("tcp", cdreCfg.RPCJSONListen)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testCDREGetCdrs(t *testing.T) {
|
||||
var reply []*engine.ExternalCDR
|
||||
req := utils.RPCCDRsFilter{}
|
||||
if err := cdreRPC.Call("ApierV1.GetCdrs", req, &reply); err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func testCDREExportNotFound(t *testing.T) {
|
||||
var replyExport v1.RplExportedCDRs
|
||||
exportArgs := v1.ArgExportCDRs{
|
||||
ExportPath: utils.StringPointer("/tmp"),
|
||||
ExportFileName: utils.StringPointer("TestTutITExportCDR.csv"),
|
||||
ExportTemplate: utils.StringPointer("TestTutITExportCDR"),
|
||||
RPCCDRsFilter: utils.RPCCDRsFilter{},
|
||||
}
|
||||
if err := cdreRPC.Call("ApierV1.ExportCDRs", exportArgs, &replyExport); err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testCDREProcessCdr(t *testing.T) {
|
||||
cdr := &engine.CDR{ToR: utils.VOICE, OriginID: "testCDREProcessCdr", OriginHost: "192.168.1.1",
|
||||
Source: "TestTutITExportCDR", RequestType: utils.META_RATED,
|
||||
Tenant: "cgrates.org", Category: "call", Account: "1001",
|
||||
Subject: "1001", Destination: "1003",
|
||||
SetupTime: time.Date(2016, 11, 30, 17, 5, 24, 0, time.UTC),
|
||||
AnswerTime: time.Date(2016, 11, 30, 17, 6, 4, 0, time.UTC),
|
||||
Usage: time.Duration(98) * time.Second,
|
||||
ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}}
|
||||
cdr.ComputeCGRID()
|
||||
var reply string
|
||||
if err := cdreRPC.Call("CdrsV1.ProcessCdr", cdr, &reply); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply received: ", reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testCDREExport(t *testing.T) {
|
||||
var replyExport v1.RplExportedCDRs
|
||||
exportArgs := v1.ArgExportCDRs{
|
||||
ExportPath: utils.StringPointer("/tmp"),
|
||||
ExportFileName: utils.StringPointer("TestTutITExportCDR.csv"),
|
||||
ExportTemplate: utils.StringPointer("TestTutITExportCDR"),
|
||||
RPCCDRsFilter: utils.RPCCDRsFilter{},
|
||||
}
|
||||
if err := cdreRPC.Call("ApierV1.ExportCDRs", exportArgs, &replyExport); err != nil {
|
||||
t.Error(err)
|
||||
} else if replyExport.TotalRecords != 1 {
|
||||
t.Errorf("Unexpected total records: %+v", replyExport.TotalRecords)
|
||||
}
|
||||
expFilePath := path.Join(*exportArgs.ExportPath, *exportArgs.ExportFileName)
|
||||
if err := os.Remove(expFilePath); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testCDREStopEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(100); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
150
migrator/tp_destination_it_test.go
Normal file
150
migrator/tp_destination_it_test.go
Normal file
@@ -0,0 +1,150 @@
|
||||
// +build integration
|
||||
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package migrator
|
||||
|
||||
// import (
|
||||
// "log"
|
||||
// "path"
|
||||
// "reflect"
|
||||
// "testing"
|
||||
|
||||
// "github.com/cgrates/cgrates/config"
|
||||
// "github.com/cgrates/cgrates/engine"
|
||||
// "github.com/cgrates/cgrates/utils"
|
||||
// )
|
||||
|
||||
// var (
|
||||
// tpDstPathIn string
|
||||
// tpDstPathOut string
|
||||
// tpDstCfgIn *config.CGRConfig
|
||||
// tpDstCfgOut *config.CGRConfig
|
||||
// tpDstMigrator *Migrator
|
||||
// tpDestination []*utils.TPDestination
|
||||
// )
|
||||
|
||||
// var sTestsTpDstIT = []func(t *testing.T){
|
||||
// testTpDstITConnect,
|
||||
// testTpDstITFlush,
|
||||
// testTpDstITPopulate,
|
||||
// testTpDstITMove,
|
||||
// testTpDstITCheckData,
|
||||
// }
|
||||
|
||||
// func TestTpDstMove(t *testing.T) {
|
||||
// for _, stest := range sTestsTpDstIT {
|
||||
// t.Run("TestTpDstMove", stest)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func testTpDstITConnect(t *testing.T) {
|
||||
// var err error
|
||||
// tpDstPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
|
||||
// tpDstCfgIn, err = config.NewCGRConfigFromFolder(tpDstPathIn)
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// tpDstPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
|
||||
// tpDstCfgOut, err = config.NewCGRConfigFromFolder(tpDstPathOut)
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// storDBIn, err := engine.ConfigureStorDB(tpDstCfgIn.StorDBType, tpDstCfgIn.StorDBHost,
|
||||
// tpDstCfgIn.StorDBPort, tpDstCfgIn.StorDBName,
|
||||
// tpDstCfgIn.StorDBUser, tpDstCfgIn.StorDBPass,
|
||||
// config.CgrConfig().StorDBMaxOpenConns,
|
||||
// config.CgrConfig().StorDBMaxIdleConns,
|
||||
// config.CgrConfig().StorDBConnMaxLifetime,
|
||||
// config.CgrConfig().StorDBCDRSIndexes)
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// storDBOut, err := engine.ConfigureStorDB(tpDstCfgOut.StorDBType,
|
||||
// tpDstCfgOut.StorDBHost, tpDstCfgOut.StorDBPort, tpDstCfgOut.StorDBName,
|
||||
// tpDstCfgOut.StorDBUser, tpDstCfgOut.StorDBPass,
|
||||
// config.CgrConfig().StorDBMaxOpenConns,
|
||||
// config.CgrConfig().StorDBMaxIdleConns,
|
||||
// config.CgrConfig().StorDBConnMaxLifetime,
|
||||
// config.CgrConfig().StorDBCDRSIndexes)
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// tpDstMigrator, err = NewMigrator(nil, nil, tpDstCfgIn.DataDbType,
|
||||
// tpDstCfgIn.DBDataEncoding, storDBIn, storDBOut, tpDstCfgIn.StorDBType, nil,
|
||||
// tpDstCfgIn.DataDbType, tpDstCfgIn.DBDataEncoding, nil,
|
||||
// tpDstCfgIn.StorDBType, false, false, false, false, false)
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func testTpDstITFlush(t *testing.T) {
|
||||
// if err := tpDstMigrator.storDBIn.Flush(
|
||||
// path.Join(tpDstCfgIn.DataFolderPath, "storage", tpDstCfgIn.StorDBType)); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
|
||||
// if err := tpDstMigrator.storDBOut.Flush(
|
||||
// path.Join(tpDstCfgOut.DataFolderPath, "storage", tpDstCfgOut.StorDBType)); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func testTpDstITPopulate(t *testing.T) {
|
||||
// tpDestination = []*utils.TPDestination{
|
||||
// &utils.TPDestination{
|
||||
// TPid: "TPD",
|
||||
// ID: "GERMANY",
|
||||
// Prefixes: []string{"+49", "+4915"},
|
||||
// },
|
||||
// }
|
||||
// if err := tpDstMigrator.storDBIn.SetTPDestinations(tpDestination); err != nil {
|
||||
// t.Error("Error when setting TpDestination ", err.Error())
|
||||
// }
|
||||
// currentVersion := engine.CurrentStorDBVersions()
|
||||
// err := tpDstMigrator.storDBOut.SetVersions(currentVersion, false)
|
||||
// if err != nil {
|
||||
// t.Error("Error when setting version for TpDestination ", err.Error())
|
||||
// }
|
||||
// }
|
||||
|
||||
// func testTpDstITMove(t *testing.T) {
|
||||
// err, _ := tpDstMigrator.Migrate([]string{utils.MetaTpDestinations})
|
||||
// if err != nil {
|
||||
// t.Error("Error when migrating TpDestination ", err.Error())
|
||||
// }
|
||||
// }
|
||||
|
||||
// func testTpDstITCheckData(t *testing.T) {
|
||||
// result, err := tpDstMigrator.storDBOut.GetTPDestinations(
|
||||
// tpDestination[0].TPid, tpDestination[0].ID)
|
||||
// if err != nil {
|
||||
// t.Error("Error when getting TpDestination ", err.Error())
|
||||
// }
|
||||
// if !reflect.DeepEqual(tpDestination[0], result[0]) {
|
||||
// t.Errorf("Expecting: %+v, received: %+v",
|
||||
// utils.ToJSON(tpDestination[0]), utils.ToJSON(result[0]))
|
||||
// }
|
||||
// result, err = tpDstMigrator.storDBIn.GetTPDestinations(
|
||||
// tpDestination[0].TPid, tpDestination[0].ID)
|
||||
// if err != utils.ErrNotFound {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// }
|
||||
@@ -133,19 +133,19 @@ func testTpStatsITPopulate(t *testing.T) {
|
||||
},
|
||||
}
|
||||
if err := tpStatsMigrator.storDBIn.SetTPStats(tpStats); err != nil {
|
||||
t.Error("Error when setting TpFilter ", err.Error())
|
||||
t.Error("Error when setting TpStat ", err.Error())
|
||||
}
|
||||
currentVersion := engine.CurrentStorDBVersions()
|
||||
err := tpStatsMigrator.storDBOut.SetVersions(currentVersion, false)
|
||||
if err != nil {
|
||||
t.Error("Error when setting version for TpFilter ", err.Error())
|
||||
t.Error("Error when setting version for TpStat ", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func testTpStatsITMove(t *testing.T) {
|
||||
err, _ := tpStatsMigrator.Migrate([]string{utils.MetaTpStats})
|
||||
if err != nil {
|
||||
t.Error("Error when migrating TpFilter ", err.Error())
|
||||
t.Error("Error when migrating TpStat ", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ func testTpStatsITCheckData(t *testing.T) {
|
||||
result, err := tpStatsMigrator.storDBOut.GetTPStats(
|
||||
tpStats[0].TPid, tpStats[0].ID)
|
||||
if err != nil {
|
||||
t.Error("Error when getting TpFilter ", err.Error())
|
||||
t.Error("Error when getting TpStat ", err.Error())
|
||||
}
|
||||
if !reflect.DeepEqual(tpStats[0], result[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v",
|
||||
|
||||
Reference in New Issue
Block a user