mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Integration tests for ActionProfiles
This commit is contained in:
committed by
Dan Christian Bogos
parent
490fc7b444
commit
bcc78c3ee0
@@ -1,5 +1,5 @@
|
||||
#Tenant,ID,FilterIDs,ActivationInterval,Weight,Schedule,AccountIDs,ActionID,ActionFilterIDs,ActionBlocker,ActionTTL,ActionType,ActionOpts,ActionPath,ActionValue
|
||||
cgrates.org,ONE_TIME_ACT,,,10,"*asap","1001;1002",TOPUP,,false,0s,*topup,,~*balance.TestBalance.Value,10
|
||||
cgrates.org,ONE_TIME_ACT,,,10,*asap,1001;1002,TOPUP,,false,0s,*topup,,~*balance.TestBalance.Value,10
|
||||
cgrates.org,ONE_TIME_ACT,,,,,,SET_BALANCE_TEST_DATA,,false,0s,*set_balance,,~*balance.TestDataBalance.Type,*data
|
||||
cgrates.org,ONE_TIME_ACT,,,,,,TOPUP_TEST_DATA,,false,0s,*topup,,~*balance.TestDataBalance.Value,1024
|
||||
cgrates.org,ONE_TIME_ACT,,,,,,SET_BALANCE_TEST_VOICE,,false,0s,*set_balance,,~*balance.TestVoiceBalance.Type,*voice
|
||||
|
||||
|
@@ -109,6 +109,9 @@ func init() {
|
||||
if err := csvr.LoadRateProfiles(); err != nil {
|
||||
log.Print("error in LoadRateProfiles:", err)
|
||||
}
|
||||
if err := csvr.LoadActionProfiles(); err != nil {
|
||||
log.Print("error in LoadActionProfiles: ", err)
|
||||
}
|
||||
if err := csvr.WriteToDatabase(false, false); err != nil {
|
||||
log.Print("error when writing into database", err)
|
||||
}
|
||||
@@ -1474,6 +1477,81 @@ func TestLoadRateProfiles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadActionProfiles(t *testing.T) {
|
||||
expected := &utils.TPActionProfile{
|
||||
TPid: testTPID,
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ONE_TIME_ACT",
|
||||
FilterIDs: nil,
|
||||
Weight: 10,
|
||||
Schedule: utils.ASAP,
|
||||
AccountIDs: []string{"1001", "1002"},
|
||||
Actions: []*utils.TPAPAction{
|
||||
&utils.TPAPAction{
|
||||
ID: "TOPUP",
|
||||
FilterIDs: []string{},
|
||||
TTL: "0s",
|
||||
Type: "*topup",
|
||||
Path: "~*balance.TestBalance.Value",
|
||||
Value: "10",
|
||||
},
|
||||
&utils.TPAPAction{
|
||||
ID: "SET_BALANCE_TEST_DATA",
|
||||
FilterIDs: []string{},
|
||||
TTL: "0s",
|
||||
Type: "*set_balance",
|
||||
Path: "~*balance.TestDataBalance.Type",
|
||||
Value: "*data",
|
||||
},
|
||||
&utils.TPAPAction{
|
||||
ID: "TOPUP_TEST_DATA",
|
||||
FilterIDs: []string{},
|
||||
TTL: "0s",
|
||||
Type: "*topup",
|
||||
Path: "~*balance.TestDataBalance.Value",
|
||||
Value: "1024",
|
||||
},
|
||||
&utils.TPAPAction{
|
||||
ID: "SET_BALANCE_TEST_VOICE",
|
||||
FilterIDs: []string{},
|
||||
TTL: "0s",
|
||||
Type: "*set_balance",
|
||||
Path: "~*balance.TestVoiceBalance.Type",
|
||||
Value: "*voice",
|
||||
},
|
||||
&utils.TPAPAction{
|
||||
ID: "TOPUP_TEST_VOICE",
|
||||
FilterIDs: []string{},
|
||||
TTL: "0s",
|
||||
Type: "*topup",
|
||||
Path: "~*balance.TestVoiceBalance.Value",
|
||||
Value: "15m15s",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if len(csvr.actionProfiles) != 1 {
|
||||
t.Fatalf("Failed to load ActionProfiles: %s", utils.ToJSON(csvr.actionProfiles))
|
||||
}
|
||||
actPrfKey := utils.TenantID{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ONE_TIME_ACT",
|
||||
}
|
||||
sort.Strings(expected.AccountIDs)
|
||||
sort.Strings(csvr.actionProfiles[actPrfKey].AccountIDs)
|
||||
sort.Slice(expected.Actions, func(i, j int) bool {
|
||||
return false
|
||||
})
|
||||
sort.Slice(csvr.actionProfiles[actPrfKey].AccountIDs, func(i, j int) bool {
|
||||
return false
|
||||
})
|
||||
|
||||
if !reflect.DeepEqual(csvr.actionProfiles[actPrfKey], expected) {
|
||||
t.Errorf("Expecting: %+v,\n received: %+v",
|
||||
utils.ToJSON(expected), utils.ToJSON(csvr.actionProfiles[actPrfKey]))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadDispatcherHosts(t *testing.T) {
|
||||
eDispatcherHosts := &utils.TPDispatcherHost{
|
||||
TPid: testTPID,
|
||||
|
||||
@@ -77,6 +77,7 @@ var (
|
||||
testOnStorITChargerProfile,
|
||||
testOnStorITDispatcherProfile,
|
||||
testOnStorITRateProfile,
|
||||
testOnStorITActionProfile,
|
||||
|
||||
//testOnStorITCacheActionTriggers,
|
||||
//testOnStorITCRUDActionTriggers,
|
||||
@@ -2242,3 +2243,76 @@ func testOnStorITRateProfile(t *testing.T) {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
}
|
||||
|
||||
func testOnStorITActionProfile(t *testing.T) {
|
||||
actPrf := &ActionProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TEST_ID1",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Weight: 20,
|
||||
Schedule: utils.ASAP,
|
||||
AccountIDs: map[string]struct{}{
|
||||
"1001": {},
|
||||
},
|
||||
Actions: []*APAction{
|
||||
{
|
||||
ID: "TOPUP",
|
||||
FilterIDs: []string{},
|
||||
Type: "*topup",
|
||||
Path: "~*balance.TestBalance.Value",
|
||||
},
|
||||
{
|
||||
ID: "TOPUP_TEST_VOICE",
|
||||
FilterIDs: []string{},
|
||||
Type: "*topup",
|
||||
Path: "~*balance.TestVoiceBalance.Value",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
//empty in database
|
||||
if _, err := onStor.GetActionProfile("cgrates.org", "TEST_ID1",
|
||||
true, false, utils.NonTransactional); err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
//get from database
|
||||
if err := onStor.SetActionProfile(actPrf, false); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if rcv, err := onStor.GetActionProfile("cgrates.org", "TEST_ID1",
|
||||
true, false, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rcv, actPrf) {
|
||||
t.Errorf("Expecting: %v, received: %v", actPrf, rcv)
|
||||
}
|
||||
|
||||
//craft akeysFromPrefix
|
||||
expectedKey := []string{"acp_cgrates.org:TEST_ID1"}
|
||||
if rcv, err := onStor.DataDB().GetKeysForPrefix(utils.ActionProfilePrefix); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expectedKey, rcv) {
|
||||
t.Errorf("Expecting: %v, received: %v", expectedKey, rcv)
|
||||
}
|
||||
|
||||
//updateFilters
|
||||
actPrf.FilterIDs = []string{"*prefix:~*req.Destination:10"}
|
||||
if err := onStor.SetActionProfile(actPrf, false); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv, err := onStor.GetActionProfile("cgrates.org", "TEST_ID1",
|
||||
false, false, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(actPrf, rcv) {
|
||||
t.Errorf("Expecting: %v, received: %v", actPrf, rcv)
|
||||
}
|
||||
time.Sleep(sleepDelay)
|
||||
|
||||
//remove from database
|
||||
if err := onStor.RemoveActionProfile("cgrates.org", "TEST_ID1",
|
||||
utils.NonTransactional, false); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err := onStor.GetActionProfile("cgrates.org", "TEST_ID1",
|
||||
false, false, utils.NonTransactional); err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,6 +204,9 @@ results+=($?)
|
||||
echo 'go test github.com/cgrates/cgrates/config -tags=integration'
|
||||
go test github.com/cgrates/cgrates/config -tags=integration
|
||||
results+=($?)
|
||||
echo 'go test github.com/cgrates/cgrates/utils -tags=integration'
|
||||
go test github.com/cgrates/cgrates/utils -tags=integration
|
||||
results+=($?)
|
||||
echo 'go test github.com/cgrates/cgrates/migrator -tags=integration'
|
||||
go test github.com/cgrates/cgrates/migrator -tags=integration
|
||||
results+=($?)
|
||||
|
||||
Reference in New Issue
Block a user