mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Fixed output when the input is an empty slice
This commit is contained in:
committed by
Dan Christian Bogos
parent
447264d3ea
commit
bb686a092f
@@ -4955,6 +4955,74 @@ func TestAPItoModelTPRoutesCase1(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPItoModelTPRoutesEmptySlice(t *testing.T) {
|
||||
tpRoute := []*utils.TPRouteProfile{
|
||||
{
|
||||
TPid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "RoutePrf",
|
||||
FilterIDs: []string{},
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: "2014-07-29T15:00:00Z",
|
||||
ExpiryTime: "2014-08-29T15:00:00Z",
|
||||
},
|
||||
Sorting: "*lc",
|
||||
SortingParameters: []string{},
|
||||
Routes: []*utils.TPRoute{
|
||||
{
|
||||
ID: "route1",
|
||||
FilterIDs: []string{},
|
||||
AccountIDs: []string{},
|
||||
RatingPlanIDs: []string{},
|
||||
ResourceIDs: []string{},
|
||||
StatIDs: []string{"Stat1", "Stat2"},
|
||||
Weight: 10,
|
||||
Blocker: false,
|
||||
RouteParameters: "SortingParam1",
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
},
|
||||
}
|
||||
expMdl := RouteMdls{
|
||||
{
|
||||
Tpid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "RoutePrf",
|
||||
FilterIDs: "",
|
||||
ActivationInterval: "2014-07-29T15:00:00Z;2014-08-29T15:00:00Z",
|
||||
Sorting: "*lc",
|
||||
SortingParameters: "",
|
||||
RouteID: "route1",
|
||||
RouteFilterIDs: "",
|
||||
RouteAccountIDs: "",
|
||||
RouteRatingplanIDs: "",
|
||||
RouteResourceIDs: "",
|
||||
RouteStatIDs: "Stat1;Stat2",
|
||||
RouteWeight: 10,
|
||||
RouteBlocker: false,
|
||||
RouteParameters: "SortingParam1",
|
||||
Weight: 20,
|
||||
},
|
||||
}
|
||||
var mdl RouteMdls
|
||||
if mdl = APItoModelTPRoutes(tpRoute[0]); !reflect.DeepEqual(mdl, expMdl) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(expMdl), utils.ToJSON(mdl))
|
||||
}
|
||||
|
||||
//back to route profile
|
||||
//all the empty slices will be nil because of converting back an empty string into a slice
|
||||
tpRoute[0].FilterIDs = nil
|
||||
tpRoute[0].SortingParameters = nil
|
||||
tpRoute[0].Routes[0].FilterIDs = nil
|
||||
tpRoute[0].Routes[0].AccountIDs = nil
|
||||
tpRoute[0].Routes[0].RatingPlanIDs = nil
|
||||
tpRoute[0].Routes[0].ResourceIDs = nil
|
||||
if newRcv := mdl.AsTPRouteProfile(); !reflect.DeepEqual(newRcv, tpRoute) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(tpRoute), utils.ToJSON(newRcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPItoModelTPRoutesCase2(t *testing.T) {
|
||||
structTest := &utils.TPRouteProfile{
|
||||
TPid: "TP1",
|
||||
|
||||
@@ -154,6 +154,7 @@ func testTpACtPrfCheckData(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error when getting TPActionProfile from database", err)
|
||||
}
|
||||
actPrf[0].Actions[0].FilterIDs = nil // because of converting and empty string into a slice
|
||||
if !reflect.DeepEqual(rcv[0], actPrf[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(actPrf[0]), utils.ToJSON(rcv[0]))
|
||||
}
|
||||
|
||||
@@ -143,6 +143,7 @@ func testTpDispITCheckData(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal("Error when getting TpDispatchers ", err.Error())
|
||||
}
|
||||
tpDisps[0].Subsystems = nil // because of converting and empty string into a slice
|
||||
if !reflect.DeepEqual(tpDisps[0], result[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v",
|
||||
utils.ToJSON(tpDisps[0]), utils.ToJSON(result[0]))
|
||||
|
||||
@@ -157,6 +157,7 @@ func testTpSplITCheckData(t *testing.T) {
|
||||
t.Error("Error when getting TpSuppliers ", err.Error())
|
||||
}
|
||||
sort.Strings(result[0].FilterIDs)
|
||||
tpSuppliers[0].SortingParameters = nil // because of converting and empty string into a slice
|
||||
if !reflect.DeepEqual(tpSuppliers[0], result[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(tpSuppliers[0]), utils.ToJSON(result[0]))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user