mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 14:19:54 +05:00
Add test for TPCdrStats and update test on TPAccountActions
This commit is contained in:
@@ -89,7 +89,7 @@ func testV1RsLoadConfig(t *testing.T) {
|
||||
case "tutmongo": // Mongo needs more time to reset db, need to investigate
|
||||
resDelay = 4000
|
||||
default:
|
||||
resDelay = 1000
|
||||
resDelay = 2000
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ func (self *ApierV1) GetTPAccountActionIds(attrs AttrGetTPAccountActionIds, repl
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPAccountActions, utils.TPDistinctIds{"loadid", "direction", "tenant", "account"}, nil, &attrs.Paginator); err != nil {
|
||||
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPAccountActions, utils.TPDistinctIds{"loadid", "tenant", "account"}, nil, &attrs.Paginator); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else if ids == nil {
|
||||
return utils.ErrNotFound
|
||||
|
||||
@@ -50,7 +50,8 @@ var sTestsTPAccActions = []func(t *testing.T){
|
||||
testTPAccActionsGetTPAccActionBeforeSet,
|
||||
testTPAccActionsSetTPAccAction,
|
||||
testTPAccActionsGetTPAccActionAfterSet,
|
||||
testTPAccActionsGetTPAccActionIds,
|
||||
testTPAccActionsGetTPAccountActionLoadIds,
|
||||
testTPAccActionsGetTPAccountActionIds,
|
||||
testTPAccActionsUpdateTPAccAction,
|
||||
testTPAccActionsGetTPAccActionAfterUpdate,
|
||||
testTPAccActionsRemTPAccAction,
|
||||
@@ -156,7 +157,7 @@ func testTPAccActionsGetTPAccActionAfterSet(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testTPAccActionsGetTPAccActionIds(t *testing.T) {
|
||||
func testTPAccActionsGetTPAccountActionLoadIds(t *testing.T) {
|
||||
var result []string
|
||||
expectedTPID := []string{"ID"}
|
||||
if err := tpAccActionsRPC.Call("ApierV1.GetTPAccountActionLoadIds", &AttrGetTPAccountActionIds{TPid: "TPAcc"}, &result); err != nil {
|
||||
@@ -164,7 +165,16 @@ func testTPAccActionsGetTPAccActionIds(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expectedTPID, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPAccActionsGetTPAccountActionIds(t *testing.T) {
|
||||
var result []string
|
||||
expectedTPID := []string{"ID:cgrates.org:1001"}
|
||||
if err := tpAccActionsRPC.Call("ApierV1.GetTPAccountActionIds", &AttrGetTPAccountActionIds{TPid: "TPAcc"}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expectedTPID, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPAccActionsUpdateTPAccAction(t *testing.T) {
|
||||
|
||||
@@ -45,9 +45,10 @@ func (self *ApierV1) GetTPCdrStats(attrs AttrGetTPCdrStats, reply *utils.TPCdrSt
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if css, err := self.StorDb.GetTPCdrStats(attrs.TPid, attrs.ID); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else if len(css) == 0 {
|
||||
return utils.ErrNotFound
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
*reply = *css[0]
|
||||
}
|
||||
@@ -79,7 +80,7 @@ func (self *ApierV1) RemTPCdrStats(attrs AttrGetTPCdrStats, reply *string) error
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBLTPSharedGroups, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBLTPCdrStats, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = utils.OK
|
||||
|
||||
346
apier/v1/tpcdrstats_it_test.go
Normal file
346
apier/v1/tpcdrstats_it_test.go
Normal file
@@ -0,0 +1,346 @@
|
||||
// +build offline_tp
|
||||
|
||||
/*
|
||||
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 v1
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
"path"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
tpCdrStatCfgPath string
|
||||
tpCdrStatCfg *config.CGRConfig
|
||||
tpCdrStatRPC *rpc.Client
|
||||
tpCdrStatDataDir = "/usr/share/cgrates"
|
||||
tpCdrStats *utils.TPCdrStats
|
||||
tpCdrStatDelay int
|
||||
tpCdrStatConfigDIR string //run tests for specific configuration
|
||||
|
||||
)
|
||||
|
||||
var sTestsTPCdrStats = []func(t *testing.T){
|
||||
testTPCdrStatsInitCfg,
|
||||
testTPCdrStatsResetStorDb,
|
||||
testTPCdrStatsStartEngine,
|
||||
testTPCdrStatsRpcConn,
|
||||
testTPCdrStatsGetTPCdrStatsBeforeSet,
|
||||
testTPCdrStatsSetTPCdrStats,
|
||||
testTPCdrStatsGetTPCdrStatsAfterSet,
|
||||
testTPCdrStatsGetTPCdrStatsIds,
|
||||
testTPCdrStatsUpdateTPCdrStats,
|
||||
testTPCdrStatsGetTPCdrStatsAfterUpdate,
|
||||
testTPCdrStatsRemTPCdrStats,
|
||||
testTPCdrStatsGetTPCdrStatsAfterRemove,
|
||||
testTPCdrStatsKillEngine,
|
||||
}
|
||||
|
||||
//Test start here
|
||||
func TestTPCdrStatsITMySql(t *testing.T) {
|
||||
tpCdrStatConfigDIR = "tutmysql"
|
||||
for _, stest := range sTestsTPCdrStats {
|
||||
t.Run(tpCdrStatConfigDIR, stest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPCdrStatsITMongo(t *testing.T) {
|
||||
tpCdrStatConfigDIR = "tutmongo"
|
||||
for _, stest := range sTestsTPCdrStats {
|
||||
t.Run(tpCdrStatConfigDIR, stest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPCdrStatsITPG(t *testing.T) {
|
||||
tpCdrStatConfigDIR = "tutpostgres"
|
||||
for _, stest := range sTestsTPCdrStats {
|
||||
t.Run(tpCdrStatConfigDIR, stest)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPCdrStatsInitCfg(t *testing.T) {
|
||||
var err error
|
||||
tpCdrStatCfgPath = path.Join(tpCdrStatDataDir, "conf", "samples", tpCdrStatConfigDIR)
|
||||
tpCdrStatCfg, err = config.NewCGRConfigFromFolder(tpCdrStatCfgPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
tpCdrStatCfg.DataFolderPath = tpCdrStatDataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
||||
config.SetCgrConfig(tpCdrStatCfg)
|
||||
switch tpCdrStatConfigDIR {
|
||||
case "tutmongo": // Mongo needs more time to reset db, need to investigate
|
||||
tpCdrStatDelay = 2000
|
||||
default:
|
||||
tpCdrStatDelay = 1000
|
||||
}
|
||||
}
|
||||
|
||||
// Wipe out the cdr database
|
||||
func testTPCdrStatsResetStorDb(t *testing.T) {
|
||||
if err := engine.InitStorDb(tpCdrStatCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Start CGR Engine
|
||||
func testTPCdrStatsStartEngine(t *testing.T) {
|
||||
if _, err := engine.StopStartEngine(tpCdrStatCfgPath, tpCdrStatDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Connect rpc client to rater
|
||||
func testTPCdrStatsRpcConn(t *testing.T) {
|
||||
var err error
|
||||
tpCdrStatRPC, err = jsonrpc.Dial("tcp", tpCdrStatCfg.RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPCdrStatsGetTPCdrStatsBeforeSet(t *testing.T) {
|
||||
var reply *utils.TPCdrStats
|
||||
if err := tpCdrStatRPC.Call("ApierV1.GetTPCdrStats", &AttrGetTPCdrStats{TPid: "TPCdr", ID: "ID"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPCdrStatsSetTPCdrStats(t *testing.T) {
|
||||
tpCdrStats = &utils.TPCdrStats{
|
||||
TPid: "TPCdr",
|
||||
ID: "ID",
|
||||
CdrStats: []*utils.TPCdrStat{
|
||||
&utils.TPCdrStat{
|
||||
QueueLength: "10",
|
||||
TimeWindow: "0",
|
||||
SaveInterval: "10s",
|
||||
Metrics: "ASR",
|
||||
SetupInterval: "",
|
||||
TORs: "",
|
||||
CdrHosts: "",
|
||||
CdrSources: "",
|
||||
ReqTypes: "",
|
||||
Directions: "",
|
||||
Tenants: "cgrates.org",
|
||||
Categories: "",
|
||||
Accounts: "",
|
||||
Subjects: "1001",
|
||||
DestinationIds: "1003",
|
||||
PddInterval: "",
|
||||
UsageInterval: "",
|
||||
Suppliers: "suppl1",
|
||||
DisconnectCauses: "",
|
||||
MediationRunIds: "*default",
|
||||
RatedAccounts: "",
|
||||
RatedSubjects: "",
|
||||
CostInterval: "",
|
||||
ActionTriggers: "CDRST1_WARN",
|
||||
},
|
||||
&utils.TPCdrStat{
|
||||
QueueLength: "10",
|
||||
TimeWindow: "0",
|
||||
SaveInterval: "10s",
|
||||
Metrics: "ACC",
|
||||
SetupInterval: "",
|
||||
TORs: "",
|
||||
CdrHosts: "",
|
||||
CdrSources: "",
|
||||
ReqTypes: "",
|
||||
Directions: "",
|
||||
Tenants: "cgrates.org",
|
||||
Categories: "",
|
||||
Accounts: "",
|
||||
Subjects: "1002",
|
||||
DestinationIds: "1003",
|
||||
PddInterval: "",
|
||||
UsageInterval: "",
|
||||
Suppliers: "suppl1",
|
||||
DisconnectCauses: "",
|
||||
MediationRunIds: "*default",
|
||||
RatedAccounts: "",
|
||||
RatedSubjects: "",
|
||||
CostInterval: "",
|
||||
ActionTriggers: "CDRST1_WARN",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var result string
|
||||
if err := tpCdrStatRPC.Call("ApierV1.SetTPCdrStats", tpCdrStats, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPCdrStatsGetTPCdrStatsAfterSet(t *testing.T) {
|
||||
var reply *utils.TPCdrStats
|
||||
if err := tpCdrStatRPC.Call("ApierV1.GetTPCdrStats", &AttrGetTPCdrStats{TPid: "TPCdr", ID: "ID"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(tpCdrStats.TPid, reply.TPid) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", tpCdrStats.TPid, reply.TPid)
|
||||
} else if !reflect.DeepEqual(tpCdrStats.ID, reply.ID) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", tpCdrStats.ID, reply.ID)
|
||||
} else if !reflect.DeepEqual(len(tpCdrStats.CdrStats), len(reply.CdrStats)) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", len(tpCdrStats.CdrStats), len(reply.CdrStats))
|
||||
}
|
||||
}
|
||||
|
||||
func testTPCdrStatsGetTPCdrStatsIds(t *testing.T) {
|
||||
var result []string
|
||||
expectedTPID := []string{"ID"}
|
||||
if err := tpCdrStatRPC.Call("ApierV1.GetTPCdrStatsIds", &AttrGetTPCdrStatIds{TPid: "TPCdr"}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expectedTPID, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPCdrStatsUpdateTPCdrStats(t *testing.T) {
|
||||
tpCdrStats.CdrStats = []*utils.TPCdrStat{
|
||||
&utils.TPCdrStat{
|
||||
QueueLength: "10",
|
||||
TimeWindow: "0",
|
||||
SaveInterval: "10s",
|
||||
Metrics: "ASR",
|
||||
SetupInterval: "",
|
||||
TORs: "",
|
||||
CdrHosts: "",
|
||||
CdrSources: "",
|
||||
ReqTypes: "",
|
||||
Directions: "",
|
||||
Tenants: "cgrates.org",
|
||||
Categories: "",
|
||||
Accounts: "",
|
||||
Subjects: "1001",
|
||||
DestinationIds: "1003",
|
||||
PddInterval: "",
|
||||
UsageInterval: "",
|
||||
Suppliers: "suppl1",
|
||||
DisconnectCauses: "",
|
||||
MediationRunIds: "*default",
|
||||
RatedAccounts: "",
|
||||
RatedSubjects: "",
|
||||
CostInterval: "",
|
||||
ActionTriggers: "CDRST1_WARN",
|
||||
},
|
||||
&utils.TPCdrStat{
|
||||
QueueLength: "10",
|
||||
TimeWindow: "0",
|
||||
SaveInterval: "10s",
|
||||
Metrics: "ACC",
|
||||
SetupInterval: "",
|
||||
TORs: "",
|
||||
CdrHosts: "",
|
||||
CdrSources: "",
|
||||
ReqTypes: "",
|
||||
Directions: "",
|
||||
Tenants: "cgrates.org",
|
||||
Categories: "",
|
||||
Accounts: "",
|
||||
Subjects: "1002",
|
||||
DestinationIds: "1003",
|
||||
PddInterval: "",
|
||||
UsageInterval: "",
|
||||
Suppliers: "suppl1",
|
||||
DisconnectCauses: "",
|
||||
MediationRunIds: "*default",
|
||||
RatedAccounts: "",
|
||||
RatedSubjects: "",
|
||||
CostInterval: "",
|
||||
ActionTriggers: "CDRST1_WARN",
|
||||
},
|
||||
&utils.TPCdrStat{
|
||||
QueueLength: "10",
|
||||
TimeWindow: "0",
|
||||
SaveInterval: "10s",
|
||||
Metrics: "ACC",
|
||||
SetupInterval: "",
|
||||
TORs: "",
|
||||
CdrHosts: "",
|
||||
CdrSources: "",
|
||||
ReqTypes: "",
|
||||
Directions: "",
|
||||
Tenants: "cgrates.org",
|
||||
Categories: "",
|
||||
Accounts: "",
|
||||
Subjects: "1002",
|
||||
DestinationIds: "1003",
|
||||
PddInterval: "",
|
||||
UsageInterval: "",
|
||||
Suppliers: "suppl1",
|
||||
DisconnectCauses: "",
|
||||
MediationRunIds: "*default",
|
||||
RatedAccounts: "",
|
||||
RatedSubjects: "",
|
||||
CostInterval: "",
|
||||
ActionTriggers: "CDRST1001_WARN",
|
||||
},
|
||||
}
|
||||
var result string
|
||||
if err := tpCdrStatRPC.Call("ApierV1.SetTPCdrStats", tpCdrStats, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testTPCdrStatsGetTPCdrStatsAfterUpdate(t *testing.T) {
|
||||
var reply *utils.TPCdrStats
|
||||
if err := tpCdrStatRPC.Call("ApierV1.GetTPCdrStats", &AttrGetTPCdrStats{TPid: "TPCdr", ID: "ID"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(tpCdrStats.TPid, reply.TPid) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", tpCdrStats.TPid, reply.TPid)
|
||||
} else if !reflect.DeepEqual(tpCdrStats.ID, reply.ID) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", tpCdrStats.ID, reply.ID)
|
||||
} else if !reflect.DeepEqual(len(tpCdrStats.CdrStats), len(reply.CdrStats)) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", len(tpCdrStats.CdrStats), len(reply.CdrStats))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testTPCdrStatsRemTPCdrStats(t *testing.T) {
|
||||
var resp string
|
||||
if err := tpCdrStatRPC.Call("ApierV1.RemTPCdrStats", &AttrGetTPCdrStats{TPid: "TPCdr", ID: "ID"}, &resp); err != nil {
|
||||
t.Error(err)
|
||||
} else if resp != utils.OK {
|
||||
t.Error("Unexpected reply returned", resp)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testTPCdrStatsGetTPCdrStatsAfterRemove(t *testing.T) {
|
||||
var reply *utils.TPCdrStats
|
||||
if err := tpCdrStatRPC.Call("ApierV1.GetTPCdrStats", &AttrGetTPCdrStats{TPid: "TPCdr", ID: "ID"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPCdrStatsKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(tpCdrStatDelay); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ var (
|
||||
var sTestsTPResources = []func(t *testing.T){
|
||||
testTPResInitCfg,
|
||||
testTPResResetStorDb,
|
||||
//testTPResStartEngine,
|
||||
testTPResStartEngine,
|
||||
testTPResRpcConn,
|
||||
testTPResGetTPResourceBeforeSet,
|
||||
testTPResSetTPResource,
|
||||
|
||||
Reference in New Issue
Block a user