mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 13:49:53 +05:00
Tests in stordb_it_test for tpfilters and tpdispatcher
This commit is contained in:
committed by
Dan Christian Bogos
parent
09a8e64a39
commit
7e566ead49
@@ -2302,7 +2302,6 @@ func testOnStorITActionProfile(t *testing.T) {
|
||||
} 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",
|
||||
|
||||
@@ -43,6 +43,8 @@ var sTestsStorDBit = []func(t *testing.T){
|
||||
testStorDBitIsDBEmpty,
|
||||
testStorDBitCRUDVersions,
|
||||
testStorDBitCRUDTPActionProfiles,
|
||||
testStorDBitCRUDTPDispatcherS,
|
||||
testStorDBitCRUDTPFilters,
|
||||
testStorDBitCRUDTpTimings,
|
||||
testStorDBitCRUDTpDestinations,
|
||||
testStorDBitCRUDTpRates,
|
||||
@@ -208,6 +210,153 @@ func testStorDBitCRUDTPActionProfiles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testStorDBitCRUDTPDispatcherS(t *testing.T) {
|
||||
//READ
|
||||
if _, err := storDB.GetTPDispatcherProfiles("TP1", utils.EmptyString, utils.EmptyString); err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
//WRITE
|
||||
var dsp = []*utils.TPDispatcherProfile{
|
||||
{
|
||||
TPid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Dsp1",
|
||||
FilterIDs: []string{"*string:~*req.Account:1002"},
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: "2014-07-29T15:00:00Z",
|
||||
ExpiryTime: "",
|
||||
},
|
||||
Strategy: utils.MetaFirst,
|
||||
Weight: 10,
|
||||
},
|
||||
{
|
||||
TPid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Dsp2",
|
||||
FilterIDs: []string{"*string:~*req.Destination:10"},
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: "2014-08-15T14:00:00Z",
|
||||
},
|
||||
Strategy: utils.MetaFirst,
|
||||
Weight: 20,
|
||||
},
|
||||
}
|
||||
if err := storDB.SetTPDispatcherProfiles(dsp); err != nil {
|
||||
t.Errorf("Unable to set TPDispatcherProfile")
|
||||
}
|
||||
|
||||
//READ
|
||||
if rcv, err := storDB.GetTPDispatcherProfiles(dsp[0].TPid, utils.EmptyString, utils.EmptyString); err != nil {
|
||||
t.Error(err)
|
||||
} else if !(reflect.DeepEqual(dsp[0], rcv[0]) ||
|
||||
reflect.DeepEqual(dsp[0], rcv[1])) {
|
||||
t.Errorf("Expected: \n%+v\n, received: \n%+v\n || \n%+v",
|
||||
utils.ToJSON(dsp[0]), utils.ToJSON(rcv[0]), utils.ToJSON(rcv[1]))
|
||||
}
|
||||
|
||||
//UPDATE and WRITE
|
||||
dsp[0].FilterIDs = []string{"*prefix:~*Account:1005"}
|
||||
dsp[1].FilterIDs = []string{"*prefix:~*Account:1005"}
|
||||
if err := storDB.SetTPDispatcherProfiles(dsp); err != nil {
|
||||
t.Errorf("Unable to set TPDispatcherProfile")
|
||||
}
|
||||
|
||||
//READ
|
||||
if rcv, err := storDB.GetTPDispatcherProfiles(dsp[0].TPid, utils.EmptyString, utils.EmptyString); err != nil {
|
||||
t.Error(err)
|
||||
} else if !(reflect.DeepEqual(dsp[0], rcv[0]) ||
|
||||
reflect.DeepEqual(dsp[0], rcv[1])) {
|
||||
t.Errorf("Expected: \n%+v\n, received: \n%+v\n || \n%+v",
|
||||
utils.ToJSON(dsp[0]), utils.ToJSON(rcv[0]), utils.ToJSON(rcv[1]))
|
||||
}
|
||||
|
||||
//REMOVE and READ
|
||||
if err := storDB.RemTpData(utils.EmptyString, dsp[0].TPid, nil); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err := storDB.GetTPDispatcherProfiles(dsp[0].TPid, utils.EmptyString, utils.EmptyString); err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testStorDBitCRUDTPFilters(t *testing.T) {
|
||||
//READ
|
||||
if _, err := storDB.GetTPFilters("TP1", utils.EmptyString, utils.EmptyString); err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
//WRITE
|
||||
tpFilters := []*utils.TPFilterProfile{
|
||||
{
|
||||
TPid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Filter1",
|
||||
Filters: []*utils.TPFilter{
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: "Account",
|
||||
Values: []string{"1001", "1002"},
|
||||
},
|
||||
},
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: "2014-07-29T15:00:00Z",
|
||||
ExpiryTime: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
TPid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Filter2",
|
||||
Filters: []*utils.TPFilter{
|
||||
{
|
||||
Type: utils.MetaPrefix,
|
||||
Element: "Destination",
|
||||
Values: []string{"10"},
|
||||
},
|
||||
},
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: "2015-07-29T15:00:00Z",
|
||||
ExpiryTime: "",
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := storDB.SetTPFilters(tpFilters); err != nil {
|
||||
t.Errorf("Unable to set TPFilters")
|
||||
}
|
||||
|
||||
//READ
|
||||
if rcv, err := storDB.GetTPFilters(tpFilters[0].TPid, utils.EmptyString, utils.EmptyString); err != nil {
|
||||
t.Error(err)
|
||||
} else if !(reflect.DeepEqual(tpFilters[0], rcv[0]) ||
|
||||
reflect.DeepEqual(tpFilters[0], rcv[1])) {
|
||||
t.Errorf("Expecting:\n%+v\nReceived:\n%+v\n||\n%+v",
|
||||
utils.ToIJSON(tpFilters[0]), utils.ToIJSON(rcv[0]), utils.ToIJSON(rcv[1]))
|
||||
}
|
||||
|
||||
//UPDATE and WRITE
|
||||
tpFilters[0].Filters[0].Element = "Account"
|
||||
tpFilters[1].Filters[0].Element = "Account"
|
||||
if err := storDB.SetTPFilters(tpFilters); err != nil {
|
||||
t.Errorf("Unable to set TPFilters")
|
||||
}
|
||||
|
||||
//READ
|
||||
if rcv, err := storDB.GetTPFilters(tpFilters[0].TPid, utils.EmptyString, utils.EmptyString); err != nil {
|
||||
t.Error(err)
|
||||
} else if !(reflect.DeepEqual(tpFilters[0], rcv[0]) ||
|
||||
reflect.DeepEqual(tpFilters[0], rcv[1])) {
|
||||
t.Errorf("Expecting:\n%+v\nReceived:\n%+v\n||\n%+v",
|
||||
utils.ToIJSON(tpFilters[0]), utils.ToIJSON(rcv[0]), utils.ToIJSON(rcv[1]))
|
||||
}
|
||||
|
||||
//REMOVE and READ
|
||||
if err := storDB.RemTpData(utils.EmptyString, tpFilters[0].TPid, nil); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err := storDB.GetTPFilters(tpFilters[0].TPid, utils.EmptyString, utils.EmptyString); err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testStorDBitCRUDTpTimings(t *testing.T) {
|
||||
// READ
|
||||
if _, err := storDB.GetTPTimings("testTPid", ""); err != utils.ErrNotFound {
|
||||
|
||||
Reference in New Issue
Block a user