diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index 79fb0f254..a43a29e96 100644 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -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", diff --git a/migrator/tp_action_profile_it_test.go b/migrator/tp_action_profile_it_test.go index eae16f7f8..4a4c30860 100644 --- a/migrator/tp_action_profile_it_test.go +++ b/migrator/tp_action_profile_it_test.go @@ -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])) } diff --git a/migrator/tp_dispatchers_it_test.go b/migrator/tp_dispatchers_it_test.go index 5d1cb9034..5f55f635f 100644 --- a/migrator/tp_dispatchers_it_test.go +++ b/migrator/tp_dispatchers_it_test.go @@ -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])) diff --git a/migrator/tp_routes_it_test.go b/migrator/tp_routes_it_test.go index 013a8bf17..429438464 100644 --- a/migrator/tp_routes_it_test.go +++ b/migrator/tp_routes_it_test.go @@ -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])) }