mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
added test for passing account info from thresholds into actions through opts
This commit is contained in:
committed by
Dan Christian Bogos
parent
f6c300c395
commit
2b27c681bc
@@ -23,34 +23,110 @@ package general_tests
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"path"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/sessions"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestSessionInitiateDisableAccount(t *testing.T) {
|
||||
var cfgDir string
|
||||
cfgJson := `{
|
||||
"general": {
|
||||
"log_level": 7,
|
||||
"reply_timeout": "50s",
|
||||
},
|
||||
"listen": {
|
||||
"rpc_json": ":2012",
|
||||
"rpc_gob": ":2013",
|
||||
"http": ":2080",
|
||||
},
|
||||
"data_db": {
|
||||
"db_type": "redis",
|
||||
"db_port": 6379,
|
||||
"db_name": "10",
|
||||
},
|
||||
"stor_db": {
|
||||
"db_password": "CGRateS.org",
|
||||
},
|
||||
"rals": {
|
||||
"enabled": true,
|
||||
"thresholds_conns": ["*internal"],
|
||||
"max_increments":3000000,
|
||||
},
|
||||
"cdrs": {
|
||||
"enabled": true,
|
||||
"chargers_conns":["*internal"],
|
||||
"attributes_conns":["*localhost"],
|
||||
"rals_conns":["*localhost"],
|
||||
"stats_conns":["*localhost"]
|
||||
},
|
||||
"attributes": {
|
||||
"enabled": true,
|
||||
"stats_conns": ["*localhost"],
|
||||
"resources_conns": ["*localhost"],
|
||||
"apiers_conns": ["*localhost"]
|
||||
},
|
||||
"chargers": {
|
||||
"enabled": true,
|
||||
"attributes_conns": ["*internal"],
|
||||
},
|
||||
"stats": {
|
||||
"enabled": true,
|
||||
"store_interval": "1s",
|
||||
"thresholds_conns": ["*localhost"],
|
||||
},
|
||||
"thresholds": {
|
||||
"enabled": true,
|
||||
"store_interval": "1s",
|
||||
"sessions_conns": ["*localhost"],
|
||||
"apiers_conns": ["*internal"]
|
||||
},
|
||||
"sessions": {
|
||||
"enabled": true,
|
||||
"attributes_conns": ["*internal"],
|
||||
"rals_conns": ["*internal"],
|
||||
"cdrs_conns": ["*localhost"],
|
||||
"chargers_conns": ["*internal"],
|
||||
},
|
||||
"apiers": {
|
||||
"enabled": true,
|
||||
"scheduler_conns": ["*internal"],
|
||||
},
|
||||
"schedulers": {
|
||||
"enabled": true,
|
||||
"cdrs_conns": ["*internal"],
|
||||
"stats_conns": ["*localhost"],
|
||||
},
|
||||
}
|
||||
`
|
||||
var dbCfg engine.DBCfg
|
||||
switch *utils.DBType {
|
||||
case utils.MetaInternal:
|
||||
cfgDir = "tutinternal"
|
||||
dbCfg = engine.DBCfg{StorDB: &engine.DBParams{Type: utils.StringPointer("*internal")}}
|
||||
case utils.MetaMySQL:
|
||||
dbCfg = engine.DBCfg{StorDB: &engine.DBParams{
|
||||
Type: utils.StringPointer("*mysql"),
|
||||
Password: utils.StringPointer("CGRateS.org"),
|
||||
}}
|
||||
case utils.MetaMongo:
|
||||
dbCfg = engine.DBCfg{StorDB: &engine.DBParams{
|
||||
Type: utils.StringPointer("*mongo"),
|
||||
Name: utils.StringPointer("cgrates"),
|
||||
Port: utils.IntPointer(27017),
|
||||
}}
|
||||
case utils.MetaPostgres:
|
||||
t.SkipNow()
|
||||
case utils.MetaMySQL:
|
||||
cfgDir = "tutmysql"
|
||||
case utils.MetaMongo:
|
||||
cfgDir = "tutmongo"
|
||||
default:
|
||||
t.Fatal("Unkwown database type")
|
||||
t.Fatalf("unsupported dbtype %v", *utils.DBType)
|
||||
}
|
||||
|
||||
ng := engine.TestEngine{
|
||||
ConfigPath: path.Join(*utils.DataDir, "conf", "samples", cfgDir),
|
||||
ConfigJSON: cfgJson,
|
||||
DBCfg: dbCfg,
|
||||
TpFiles: map[string]string{
|
||||
utils.AccountActionsCsv: `#Tenant,Account,ActionPlanId,ActionTriggersId,AllowNegative,Disabled
|
||||
cgrates.org,1001,AP1,DISABLE_TRIGGER,,`,
|
||||
@@ -72,10 +148,18 @@ DR_RP,DST_1002,RT1,*up,4,0,`,
|
||||
utils.DestinationsCsv: `#Id,Prefix
|
||||
DST_1002,1002`,
|
||||
utils.RatesCsv: `#Id,ConnectFee,Rate,RateUnit,RateIncrement,GroupIntervalStart
|
||||
RT1,0.2,1,1s,1s,0`,
|
||||
RT1,0.2,0.1,1s,1s,0`,
|
||||
utils.AttributesCsv: `#Tenant,ID,Context,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight
|
||||
cgrates.org,ATTR_ACNT,*any,,,,*opts.*account,*variable,~*req.Account,false,10`,
|
||||
utils.StatsCsv: `#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],QueueLength[4],TTL[5],MinItems[6],Metrics[7],MetricFilterIDs[8],Stored[9],Blocker[10],Weight[11],ThresholdIDs[12]
|
||||
cgrates.org,STATS_1001,*string:~*req.Account:1001,,,-1,,*sum#1,,true,,,THD_1001`,
|
||||
utils.ThresholdsCsv: `#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],MaxHits[4],MinHits[5],MinSleep[6],Blocker[7],Weight[8],ActionIDs[9],Async[10]
|
||||
cgrates.org,THD_1001,*string:~*req.StatID:STATS_1001,,-1,5,0,false,,DISABLE_ACC,false`,
|
||||
},
|
||||
|
||||
LogBuffer: bytes.NewBuffer(nil),
|
||||
}
|
||||
//defer t.Log(ng.LogBuffer)
|
||||
client, _ := ng.Run(t)
|
||||
t.Run("TestAuthorizeEvent", func(t *testing.T) {
|
||||
var accRepl engine.Account
|
||||
@@ -103,13 +187,59 @@ RT1,0.2,1,1s,1s,0`,
|
||||
|
||||
if err := client.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &accRepl); err != nil {
|
||||
t.Error(err)
|
||||
} else if *reply.MaxUsage != (9 * time.Second) {
|
||||
} else if *reply.MaxUsage != (98 * time.Second) {
|
||||
t.Errorf("expected to get usage even though account got disabled")
|
||||
}
|
||||
|
||||
if accRepl.Disabled {
|
||||
t.Errorf("expected account to be not be disabled")
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
t.Run("TestDisableAccountFromThresholds", func(t *testing.T) {
|
||||
var replyStr string
|
||||
rmReq := v1.AttrRemoveAccountActionTriggers{Tenant: "cgrates.org", Account: "1001", GroupID: "DISABLE_TRIGGER"}
|
||||
if err := client.Call(context.Background(), utils.APIerSv1RemoveAccountActionTriggers, rmReq, &replyStr); err != nil {
|
||||
t.Error("Got error on APIerSv1.RemoveActionTiming: ", err.Error())
|
||||
} else if replyStr != utils.OK {
|
||||
t.Error("Unexpected answer received", replyStr)
|
||||
}
|
||||
|
||||
for range 5 {
|
||||
argsEv := &engine.ArgV1ProcessEvent{
|
||||
Flags: []string{utils.MetaRALs, utils.MetaAttributes},
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: utils.GenUUID(),
|
||||
Event: map[string]any{
|
||||
utils.RunID: "run_1",
|
||||
utils.CGRID: utils.GenUUID(),
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.Category: "call",
|
||||
utils.OriginID: "origin1",
|
||||
utils.OriginHost: "OriginHost1",
|
||||
utils.RequestType: utils.MetaPrepaid,
|
||||
utils.Subject: "1001",
|
||||
utils.AccountField: "1001",
|
||||
utils.Destination: "1002",
|
||||
utils.SetupTime: time.Date(2021, time.February, 2, 16, 14, 50, 0, time.UTC),
|
||||
utils.AnswerTime: time.Date(2021, time.February, 2, 16, 15, 0, 0, time.UTC),
|
||||
utils.Usage: 10 * time.Second,
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := client.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &replyStr); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
} else if replyStr != utils.OK {
|
||||
t.Error("Unexpected reply received: ", replyStr)
|
||||
}
|
||||
}
|
||||
var accRepl engine.Account
|
||||
if err := client.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &accRepl); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !accRepl.Disabled {
|
||||
t.Errorf("expected account to be disabled")
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user