mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-13 19:56:38 +05:00
Add integration tests for AccountUpdate
This commit is contained in:
committed by
Dan Christian Bogos
parent
dad3f290a6
commit
0820fa2372
201
general_tests/accountswiththresholds_it_test.go
Normal file
201
general_tests/accountswiththresholds_it_test.go
Normal file
@@ -0,0 +1,201 @@
|
||||
// +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"
|
||||
"path"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
accWThdCfgPath string
|
||||
accWThdCfg *config.CGRConfig
|
||||
accWThdRpc *rpc.Client
|
||||
accWThdConfDIR string //run tests for specific configuration
|
||||
accountWT *engine.Account
|
||||
accWThdDelay int
|
||||
|
||||
sTestsAccWThd = []func(t *testing.T){
|
||||
testAccWThdLoadConfig,
|
||||
testAccWThdInitDataDb,
|
||||
testAccWThdResetStorDb,
|
||||
testAccWThdStartEngine,
|
||||
testAccWThdRpcConn,
|
||||
testAccWThdSetThresholdProfile,
|
||||
testAccWThdGetThresholdProfile,
|
||||
testAccWThdExecuteAction,
|
||||
// testAccWThdLoadTarrifPlans,
|
||||
testAccWThdStopEngine,
|
||||
}
|
||||
)
|
||||
|
||||
// Test starts here
|
||||
func TestAccWThdIT(t *testing.T) {
|
||||
switch *dbType {
|
||||
case utils.MetaInternal:
|
||||
accWThdConfDIR = "tutinternal"
|
||||
case utils.MetaMySQL:
|
||||
accWThdConfDIR = "tutmysql"
|
||||
case utils.MetaMongo:
|
||||
accWThdConfDIR = "tutmongo"
|
||||
case utils.MetaPostgres:
|
||||
t.SkipNow()
|
||||
default:
|
||||
t.Fatal("Unknown Database type")
|
||||
}
|
||||
|
||||
for _, stest := range sTestsAccWThd {
|
||||
t.Run(accWThdConfDIR, stest)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccWThdLoadConfig(t *testing.T) {
|
||||
var err error
|
||||
accWThdCfgPath = path.Join(*dataDir, "conf", "samples", accWThdConfDIR)
|
||||
if accWThdCfg, err = config.NewCGRConfigFromPath(accWThdCfgPath); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
accWThdDelay = 1000
|
||||
}
|
||||
|
||||
func testAccWThdInitDataDb(t *testing.T) {
|
||||
if err := engine.InitDataDb(accWThdCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccWThdResetStorDb(t *testing.T) {
|
||||
if err := engine.InitStorDb(accWThdCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccWThdStartEngine(t *testing.T) {
|
||||
if _, err := engine.StopStartEngine(accWThdCfgPath, accWThdDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccWThdRpcConn(t *testing.T) {
|
||||
var err error
|
||||
accWThdRpc, err = newRPCClient(accWThdCfg.ListenCfg()) // We connect over JSON so we can troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal("Could not connect to rater: ", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// func testAccWThdLoadTarrifPlans(t *testing.T) {
|
||||
// var reply string
|
||||
// attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")}
|
||||
// if err := accWThdRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
|
||||
// t.Error(err)
|
||||
// } else if reply != utils.OK {
|
||||
// t.Error("Unexpected reply returned", reply)
|
||||
// }
|
||||
// time.Sleep(200 * time.Millisecond)
|
||||
// }
|
||||
|
||||
func testAccWThdSetThresholdProfile(t *testing.T) {
|
||||
ThdPrf := &engine.ThresholdProfileWithAPIOpts{
|
||||
ThresholdProfile: &engine.ThresholdProfile{
|
||||
Tenant: "cgrates.org",
|
||||
FilterIDs: []string{"*string:~*req.Account:1002"},
|
||||
ID: "THD_ACNT_1002",
|
||||
MaxHits: 1,
|
||||
},
|
||||
}
|
||||
var reply string
|
||||
if err := accWThdRpc.Call(utils.APIerSv1SetThresholdProfile, ThdPrf, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccWThdGetThresholdProfile(t *testing.T) {
|
||||
expThdPrf := &engine.ThresholdProfile{
|
||||
Tenant: "cgrates.org",
|
||||
FilterIDs: []string{"*string:~*req.Account:1002"},
|
||||
ID: "THD_ACNT_1002",
|
||||
MaxHits: 1,
|
||||
}
|
||||
|
||||
args := &utils.TenantID{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "THD_ACNT_1002",
|
||||
}
|
||||
|
||||
var result1 *engine.ThresholdProfile
|
||||
if err := accWThdRpc.Call(utils.APIerSv1GetThresholdProfile, args, &result1); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(result1, expThdPrf) {
|
||||
t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", utils.ToJSON(expThdPrf), utils.ToJSON(result1))
|
||||
}
|
||||
|
||||
expThd := &engine.Threshold{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "THD_ACNT_1002",
|
||||
Hits: 0,
|
||||
}
|
||||
|
||||
var result2 *engine.Threshold
|
||||
if err := accWThdRpc.Call(utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: args}, &result2); err != nil {
|
||||
t.Error(err)
|
||||
} else if result2.Snooze = expThd.Snooze; !reflect.DeepEqual(result2, expThd) {
|
||||
t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", utils.ToJSON(expThd), utils.ToJSON(result2))
|
||||
}
|
||||
}
|
||||
|
||||
func testAccWThdExecuteAction(t *testing.T) {
|
||||
tStart := time.Date(2021, 5, 5, 12, 0, 0, 0, time.UTC)
|
||||
cc := new(engine.CallCost)
|
||||
err = accWThdRpc.Call(utils.ResponderMaxDebit, &engine.CallDescriptorWithAPIOpts{
|
||||
CallDescriptor: &engine.CallDescriptor{
|
||||
Category: utils.Call,
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "*01ms",
|
||||
Account: "1002",
|
||||
Destination: "1003",
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tStart.Add(5 * time.Second),
|
||||
LoopIndex: 0,
|
||||
DurationIndex: 5 * time.Second,
|
||||
ToR: utils.MetaVoice,
|
||||
CgrID: "12345678910",
|
||||
RunID: utils.MetaDefault,
|
||||
},
|
||||
}, cc)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccWThdStopEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(accWThdDelay); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user