mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added tests for DispatcherProfile methods
This commit is contained in:
committed by
Dan Christian Bogos
parent
aa00a3d598
commit
491be710d5
@@ -24,6 +24,24 @@ import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestDispatcherConnClone(t *testing.T) {
|
||||
dConn := &DispatcherConn{
|
||||
ID: "DSP_1",
|
||||
Weight: 30,
|
||||
FilterIDs: []string{"*string:Usage:10"},
|
||||
}
|
||||
eConn := &DispatcherConn{
|
||||
ID: "DSP_1",
|
||||
Weight: 30,
|
||||
FilterIDs: []string{"*string:Usage:10"},
|
||||
}
|
||||
d2Conn := dConn.Clone()
|
||||
d2Conn.ID = "DSP_4"
|
||||
if !reflect.DeepEqual(eConn, dConn) {
|
||||
t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eConn), utils.ToJSON(dConn))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatcherConnsReorderFromIndex(t *testing.T) {
|
||||
dConns := DispatcherConns{
|
||||
{ID: "DSP_1", Weight: 30},
|
||||
@@ -91,3 +109,117 @@ func TestDispatcherConnsShuffle(t *testing.T) {
|
||||
t.Errorf("received: %s", utils.ToJSON(dConns))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatcherConnsSort(t *testing.T) {
|
||||
dConns := DispatcherConns{
|
||||
{ID: "DSP_3", Weight: 10},
|
||||
{ID: "DSP_2", Weight: 20},
|
||||
{ID: "DSP_1", Weight: 30},
|
||||
}
|
||||
eConns := DispatcherConns{
|
||||
{ID: "DSP_1", Weight: 30},
|
||||
{ID: "DSP_2", Weight: 20},
|
||||
{ID: "DSP_3", Weight: 10},
|
||||
}
|
||||
if dConns.Sort(); !reflect.DeepEqual(eConns, dConns) {
|
||||
t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eConns), utils.ToJSON(dConns))
|
||||
}
|
||||
dConns = DispatcherConns{
|
||||
{ID: "DSP_3", Weight: 10},
|
||||
{ID: "DSP_5", Weight: 50},
|
||||
{ID: "DSP_2", Weight: 20},
|
||||
{ID: "DSP_4", Weight: 40},
|
||||
{ID: "DSP_1", Weight: 30},
|
||||
}
|
||||
eConns = DispatcherConns{
|
||||
{ID: "DSP_5", Weight: 50},
|
||||
{ID: "DSP_4", Weight: 40},
|
||||
{ID: "DSP_1", Weight: 30},
|
||||
{ID: "DSP_2", Weight: 20},
|
||||
{ID: "DSP_3", Weight: 10},
|
||||
}
|
||||
if dConns.Sort(); !reflect.DeepEqual(eConns, dConns) {
|
||||
t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eConns), utils.ToJSON(dConns))
|
||||
}
|
||||
dConns.Shuffle()
|
||||
if dConns.Sort(); !reflect.DeepEqual(eConns, dConns) {
|
||||
t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eConns), utils.ToJSON(dConns))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatcherConnsClone(t *testing.T) {
|
||||
dConns := DispatcherConns{
|
||||
{ID: "DSP_1", Weight: 30},
|
||||
{ID: "DSP_2", Weight: 20},
|
||||
{ID: "DSP_3", Weight: 10, FilterIDs: []string{"*string:Usage:10"}},
|
||||
}
|
||||
eConns := DispatcherConns{
|
||||
{ID: "DSP_1", Weight: 30},
|
||||
{ID: "DSP_2", Weight: 20},
|
||||
{ID: "DSP_3", Weight: 10, FilterIDs: []string{"*string:Usage:10"}},
|
||||
}
|
||||
d2Conns := dConns.Clone()
|
||||
d2Conns[0].ID = "DSP_4"
|
||||
if !reflect.DeepEqual(eConns, dConns) {
|
||||
t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eConns), utils.ToJSON(dConns))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatcherConnsConnIDs(t *testing.T) {
|
||||
dConns := DispatcherConns{
|
||||
{ID: "DSP_5", Weight: 50},
|
||||
{ID: "DSP_4", Weight: 40},
|
||||
{ID: "DSP_1", Weight: 30},
|
||||
{ID: "DSP_2", Weight: 20},
|
||||
{ID: "DSP_3", Weight: 10},
|
||||
}
|
||||
eConnIDs := []string{"DSP_5", "DSP_4", "DSP_1", "DSP_2", "DSP_3"}
|
||||
if dConnIDs := dConns.ConnIDs(); !reflect.DeepEqual(eConnIDs, dConnIDs) {
|
||||
t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eConnIDs), utils.ToJSON(dConnIDs))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatcherProfileTenantID(t *testing.T) {
|
||||
dProf := DispatcherProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "DISP_1",
|
||||
}
|
||||
eTenantID := utils.ConcatenatedKey("cgrates.org", "DISP_1")
|
||||
if dTenantID := dProf.TenantID(); !reflect.DeepEqual(eTenantID, dTenantID) {
|
||||
t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eTenantID), utils.ToJSON(dTenantID))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatcherProfilesSort(t *testing.T) {
|
||||
dProf := DispatcherProfiles{
|
||||
{ID: "DSP_3", Weight: 10},
|
||||
{ID: "DSP_2", Weight: 20},
|
||||
{ID: "DSP_1", Weight: 30},
|
||||
}
|
||||
eProf := DispatcherProfiles{
|
||||
{ID: "DSP_1", Weight: 30},
|
||||
{ID: "DSP_2", Weight: 20},
|
||||
{ID: "DSP_3", Weight: 10},
|
||||
}
|
||||
if dProf.Sort(); !reflect.DeepEqual(eProf, dProf) {
|
||||
t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eProf), utils.ToJSON(dProf))
|
||||
}
|
||||
dProf = DispatcherProfiles{
|
||||
{ID: "DSP_3", Weight: 10},
|
||||
{ID: "DSP_5", Weight: 50},
|
||||
{ID: "DSP_2", Weight: 20},
|
||||
{ID: "DSP_4", Weight: 40},
|
||||
{ID: "DSP_1", Weight: 30},
|
||||
}
|
||||
eProf = DispatcherProfiles{
|
||||
{ID: "DSP_5", Weight: 50},
|
||||
{ID: "DSP_4", Weight: 40},
|
||||
{ID: "DSP_1", Weight: 30},
|
||||
{ID: "DSP_2", Weight: 20},
|
||||
{ID: "DSP_3", Weight: 10},
|
||||
}
|
||||
if dProf.Sort(); !reflect.DeepEqual(eProf, dProf) {
|
||||
t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eProf), utils.ToJSON(dProf))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user