Update name from suppliers to route in libroutes.go

This commit is contained in:
TeoV
2020-11-11 17:19:33 +02:00
committed by Dan Christian Bogos
parent a30bdfe8df
commit afe2df5260

View File

@@ -29,7 +29,7 @@ func TestLibSuppliersSortCost(t *testing.T) {
sSpls := &SortedRoutes{
SortedRoutes: []*SortedRoute{
{
RouteID: "supplier1",
RouteID: "route1",
SortingData: map[string]interface{}{
utils.Cost: 0.1,
utils.Weight: 10.0,
@@ -37,7 +37,7 @@ func TestLibSuppliersSortCost(t *testing.T) {
RouteParameters: "param1",
},
{
RouteID: "supplier2",
RouteID: "route2",
SortingData: map[string]interface{}{
utils.Cost: 0.1,
utils.Weight: 20.0,
@@ -45,7 +45,7 @@ func TestLibSuppliersSortCost(t *testing.T) {
RouteParameters: "param2",
},
{
RouteID: "supplier3",
RouteID: "route3",
SortingData: map[string]interface{}{
utils.Cost: 0.05,
utils.Weight: 10.0,
@@ -58,7 +58,7 @@ func TestLibSuppliersSortCost(t *testing.T) {
eOrderedSpls := &SortedRoutes{
SortedRoutes: []*SortedRoute{
{
RouteID: "supplier3",
RouteID: "route3",
SortingData: map[string]interface{}{
utils.Cost: 0.05,
utils.Weight: 10.0,
@@ -66,7 +66,7 @@ func TestLibSuppliersSortCost(t *testing.T) {
RouteParameters: "param3",
},
{
RouteID: "supplier2",
RouteID: "route2",
SortingData: map[string]interface{}{
utils.Cost: 0.1,
utils.Weight: 20.0,
@@ -74,7 +74,7 @@ func TestLibSuppliersSortCost(t *testing.T) {
RouteParameters: "param2",
},
{
RouteID: "supplier1",
RouteID: "route1",
SortingData: map[string]interface{}{
utils.Cost: 0.1,
utils.Weight: 10.0,
@@ -93,21 +93,21 @@ func TestLibRoutesSortWeight(t *testing.T) {
sSpls := &SortedRoutes{
SortedRoutes: []*SortedRoute{
{
RouteID: "supplier1",
RouteID: "route1",
SortingData: map[string]interface{}{
utils.Weight: 10.0,
},
RouteParameters: "param1",
},
{
RouteID: "supplier2",
RouteID: "route2",
SortingData: map[string]interface{}{
utils.Weight: 20.0,
},
RouteParameters: "param2",
},
{
RouteID: "supplier3",
RouteID: "route3",
SortingData: map[string]interface{}{
utils.Weight: 10.5,
},
@@ -119,21 +119,21 @@ func TestLibRoutesSortWeight(t *testing.T) {
eOrderedSpls := &SortedRoutes{
SortedRoutes: []*SortedRoute{
{
RouteID: "supplier2",
RouteID: "route2",
SortingData: map[string]interface{}{
utils.Weight: 20.0,
},
RouteParameters: "param2",
},
{
RouteID: "supplier3",
RouteID: "route3",
SortingData: map[string]interface{}{
utils.Weight: 10.5,
},
RouteParameters: "param3",
},
{
RouteID: "supplier1",
RouteID: "route1",
SortingData: map[string]interface{}{
utils.Weight: 10.0,
},
@@ -153,14 +153,14 @@ func TestSortedRoutesDigest(t *testing.T) {
Sorting: utils.MetaWeight,
SortedRoutes: []*SortedRoute{
{
RouteID: "supplier2",
RouteID: "route2",
SortingData: map[string]interface{}{
"Weight": 20.0,
},
RouteParameters: "param2",
},
{
RouteID: "supplier1",
RouteID: "route1",
SortingData: map[string]interface{}{
"Weight": 10.0,
},
@@ -168,7 +168,7 @@ func TestSortedRoutesDigest(t *testing.T) {
},
},
}
exp := "supplier2:param2,supplier1:param1"
exp := "route2:param2,route1:param1"
rcv := eSpls.Digest()
if !reflect.DeepEqual(rcv, exp) {
t.Errorf("Expecting: %+v, received: %+v", exp, rcv)
@@ -181,14 +181,14 @@ func TestSortedRoutesDigest2(t *testing.T) {
Sorting: utils.MetaWeight,
SortedRoutes: []*SortedRoute{
{
RouteID: "supplier1",
RouteID: "route1",
SortingData: map[string]interface{}{
"Weight": 30.0,
},
RouteParameters: "param1",
},
{
RouteID: "supplier2",
RouteID: "route2",
SortingData: map[string]interface{}{
"Weight": 20.0,
},
@@ -196,7 +196,7 @@ func TestSortedRoutesDigest2(t *testing.T) {
},
},
}
exp := "supplier1:param1,supplier2:param2"
exp := "route1:param1,route2:param2"
rcv := eSpls.Digest()
if !reflect.DeepEqual(rcv, exp) {
t.Errorf("Expecting: %+v, received: %+v", exp, rcv)
@@ -220,7 +220,7 @@ func TestLibRoutesSortHighestCost(t *testing.T) {
sSpls := &SortedRoutes{
SortedRoutes: []*SortedRoute{
{
RouteID: "supplier1",
RouteID: "route1",
SortingData: map[string]interface{}{
utils.Cost: 0.1,
utils.Weight: 15.0,
@@ -228,7 +228,7 @@ func TestLibRoutesSortHighestCost(t *testing.T) {
RouteParameters: "param1",
},
{
RouteID: "supplier2",
RouteID: "route2",
SortingData: map[string]interface{}{
utils.Cost: 0.2,
utils.Weight: 20.0,
@@ -236,7 +236,7 @@ func TestLibRoutesSortHighestCost(t *testing.T) {
RouteParameters: "param2",
},
{
RouteID: "supplier3",
RouteID: "route3",
SortingData: map[string]interface{}{
utils.Cost: 0.05,
utils.Weight: 10.0,
@@ -249,7 +249,7 @@ func TestLibRoutesSortHighestCost(t *testing.T) {
eOrderedSpls := &SortedRoutes{
SortedRoutes: []*SortedRoute{
{
RouteID: "supplier2",
RouteID: "route2",
SortingData: map[string]interface{}{
utils.Cost: 0.2,
utils.Weight: 20.0,
@@ -257,7 +257,7 @@ func TestLibRoutesSortHighestCost(t *testing.T) {
RouteParameters: "param2",
},
{
RouteID: "supplier1",
RouteID: "route1",
SortingData: map[string]interface{}{
utils.Cost: 0.1,
utils.Weight: 15.0,
@@ -265,7 +265,7 @@ func TestLibRoutesSortHighestCost(t *testing.T) {
RouteParameters: "param1",
},
{
RouteID: "supplier3",
RouteID: "route3",
SortingData: map[string]interface{}{
utils.Cost: 0.05,
utils.Weight: 10.0,
@@ -285,8 +285,8 @@ func TestLibRoutesSortQOS(t *testing.T) {
sSpls := &SortedRoutes{
SortedRoutes: []*SortedRoute{
{
//the average value for supplier1 for *acd is 0.5 , *tcd 1.1
RouteID: "supplier1",
//the average value for route1 for *acd is 0.5 , *tcd 1.1
RouteID: "route1",
SortingData: map[string]interface{}{
utils.Cost: 0.5,
utils.Weight: 10.0,
@@ -295,8 +295,8 @@ func TestLibRoutesSortQOS(t *testing.T) {
},
},
{
//the average value for supplier2 for *acd is 0.5 , *tcd 4.1
RouteID: "supplier2",
//the average value for route2 for *acd is 0.5 , *tcd 4.1
RouteID: "route2",
SortingData: map[string]interface{}{
utils.Cost: 0.1,
utils.Weight: 15.0,
@@ -305,8 +305,8 @@ func TestLibRoutesSortQOS(t *testing.T) {
},
},
{
//the average value for supplier3 for *acd is 0.4 , *tcd 5.1
RouteID: "supplier3",
//the average value for route3 for *acd is 0.4 , *tcd 5.1
RouteID: "route3",
SortingData: map[string]interface{}{
utils.Cost: 1.1,
utils.Weight: 17.8,
@@ -320,7 +320,7 @@ func TestLibRoutesSortQOS(t *testing.T) {
//sort base on *acd and *tcd
sSpls.SortQOS([]string{utils.MetaACD, utils.MetaTCD})
rcv := make([]string, len(sSpls.SortedRoutes))
eIds := []string{"supplier2", "supplier1", "supplier3"}
eIds := []string{"route2", "route1", "route3"}
for i, spl := range sSpls.SortedRoutes {
rcv[i] = spl.RouteID
@@ -336,8 +336,8 @@ func TestLibRoutesSortQOS2(t *testing.T) {
sSpls := &SortedRoutes{
SortedRoutes: []*SortedRoute{
{
//the average value for supplier1 for *acd is 0.5 , *tcd 1.1
RouteID: "supplier1",
//the average value for route1 for *acd is 0.5 , *tcd 1.1
RouteID: "route1",
SortingData: map[string]interface{}{
utils.Weight: 10.0,
utils.MetaACD: 0.5,
@@ -345,10 +345,10 @@ func TestLibRoutesSortQOS2(t *testing.T) {
},
},
{
//the worst value for supplier1 for *acd is 0.5 , *tcd 1.1
//supplier1 and supplier2 have the same value for *acd and *tcd
//the worst value for route1 for *acd is 0.5 , *tcd 1.1
//route1 and route2 have the same value for *acd and *tcd
//will be sorted based on weight
RouteID: "supplier2",
RouteID: "route2",
SortingData: map[string]interface{}{
utils.Weight: 17.0,
utils.MetaACD: 0.5,
@@ -357,7 +357,7 @@ func TestLibRoutesSortQOS2(t *testing.T) {
},
{
RouteID: "supplier3",
RouteID: "route3",
SortingData: map[string]interface{}{
utils.Cost: 0.5,
utils.Weight: 10.0,
@@ -369,7 +369,7 @@ func TestLibRoutesSortQOS2(t *testing.T) {
}
sSpls.SortQOS([]string{utils.MetaACD, utils.MetaTCD})
rcv := make([]string, len(sSpls.SortedRoutes))
eIds := []string{"supplier3", "supplier2", "supplier1"}
eIds := []string{"route3", "route2", "route1"}
for i, spl := range sSpls.SortedRoutes {
rcv[i] = spl.RouteID
@@ -385,10 +385,10 @@ func TestLibRoutesSortQOS3(t *testing.T) {
sSpls := &SortedRoutes{
SortedRoutes: []*SortedRoute{
{
//the worst value for supplier1 for *pdd is 0.7 , *tcd 1.1
//supplier1 and supplier3 have the same value for *pdd
//the worst value for route1 for *pdd is 0.7 , *tcd 1.1
//route1 and route3 have the same value for *pdd
//will be sorted based on weight
RouteID: "supplier1",
RouteID: "route1",
SortingData: map[string]interface{}{
utils.Weight: 15.0,
utils.MetaPDD: 0.7,
@@ -396,8 +396,8 @@ func TestLibRoutesSortQOS3(t *testing.T) {
},
},
{
//the worst value for supplier2 for *pdd is 1.2, *tcd 1.1
RouteID: "supplier2",
//the worst value for route2 for *pdd is 1.2, *tcd 1.1
RouteID: "route2",
SortingData: map[string]interface{}{
utils.Weight: 10.0,
utils.MetaPDD: 1.2,
@@ -405,8 +405,8 @@ func TestLibRoutesSortQOS3(t *testing.T) {
},
},
{
//the worst value for supplier3 for *pdd is 0.7, *tcd 10.1
RouteID: "supplier3",
//the worst value for route3 for *pdd is 0.7, *tcd 10.1
RouteID: "route3",
SortingData: map[string]interface{}{
utils.Weight: 10.0,
utils.MetaPDD: 0.7,
@@ -417,7 +417,7 @@ func TestLibRoutesSortQOS3(t *testing.T) {
}
sSpls.SortQOS([]string{utils.MetaPDD})
rcv := make([]string, len(sSpls.SortedRoutes))
eIds := []string{"supplier1", "supplier3", "supplier2"}
eIds := []string{"route1", "route3", "route2"}
for i, spl := range sSpls.SortedRoutes {
rcv[i] = spl.RouteID
@@ -432,7 +432,7 @@ func TestLibRoutesSortQOS4(t *testing.T) {
sSpls := &SortedRoutes{
SortedRoutes: []*SortedRoute{
{
RouteID: "supplier1",
RouteID: "route1",
SortingData: map[string]interface{}{
utils.MetaACD: 0.2,
utils.MetaTCD: 15.0,
@@ -440,7 +440,7 @@ func TestLibRoutesSortQOS4(t *testing.T) {
},
},
{
RouteID: "supplier2",
RouteID: "route2",
SortingData: map[string]interface{}{
utils.MetaACD: 0.2,
utils.MetaTCD: 20.0,
@@ -448,7 +448,7 @@ func TestLibRoutesSortQOS4(t *testing.T) {
},
},
{
RouteID: "supplier3",
RouteID: "route3",
SortingData: map[string]interface{}{
utils.MetaACD: 0.1,
utils.MetaTCD: 10.0,
@@ -459,7 +459,7 @@ func TestLibRoutesSortQOS4(t *testing.T) {
}
sSpls.SortQOS([]string{utils.MetaASR, utils.MetaACD, utils.MetaTCD})
rcv := make([]string, len(sSpls.SortedRoutes))
eIds := []string{"supplier1", "supplier3", "supplier2"}
eIds := []string{"route1", "route3", "route2"}
for i, spl := range sSpls.SortedRoutes {
rcv[i] = spl.RouteID
@@ -474,7 +474,7 @@ func TestLibRoutesSortQOS5(t *testing.T) {
sSpls := &SortedRoutes{
SortedRoutes: []*SortedRoute{
{
RouteID: "supplier1",
RouteID: "route1",
SortingData: map[string]interface{}{
utils.MetaACD: 0.2,
utils.MetaTCD: 15.0,
@@ -483,7 +483,7 @@ func TestLibRoutesSortQOS5(t *testing.T) {
},
},
{
RouteID: "supplier2",
RouteID: "route2",
SortingData: map[string]interface{}{
utils.MetaACD: 0.2,
utils.MetaTCD: 20.0,
@@ -492,7 +492,7 @@ func TestLibRoutesSortQOS5(t *testing.T) {
},
},
{
RouteID: "supplier3",
RouteID: "route3",
SortingData: map[string]interface{}{
utils.MetaACD: 0.1,
utils.MetaTCD: 10.0,
@@ -504,7 +504,7 @@ func TestLibRoutesSortQOS5(t *testing.T) {
}
sSpls.SortQOS([]string{utils.MetaTCC, utils.MetaASR, utils.MetaACD, utils.MetaTCD})
rcv := make([]string, len(sSpls.SortedRoutes))
eIds := []string{"supplier2", "supplier3", "supplier1"}
eIds := []string{"route2", "route3", "route1"}
for i, spl := range sSpls.SortedRoutes {
rcv[i] = spl.RouteID
@@ -519,21 +519,21 @@ func TestLibRoutesSortQOS6(t *testing.T) {
sSpls := &SortedRoutes{
SortedRoutes: []*SortedRoute{
{
RouteID: "supplier1",
RouteID: "route1",
SortingData: map[string]interface{}{
utils.Weight: 15.0,
utils.MetaACD: 0.2,
},
},
{
RouteID: "supplier2",
RouteID: "route2",
SortingData: map[string]interface{}{
utils.Weight: 25.0,
utils.MetaACD: 0.2,
},
},
{
RouteID: "supplier3",
RouteID: "route3",
SortingData: map[string]interface{}{
utils.Weight: 20.0,
utils.MetaACD: 0.1,
@@ -543,7 +543,7 @@ func TestLibRoutesSortQOS6(t *testing.T) {
}
sSpls.SortQOS([]string{utils.MetaACD})
rcv := make([]string, len(sSpls.SortedRoutes))
eIds := []string{"supplier2", "supplier1", "supplier3"}
eIds := []string{"route2", "route1", "route3"}
for i, spl := range sSpls.SortedRoutes {
rcv[i] = spl.RouteID
@@ -558,21 +558,21 @@ func TestLibRoutesSortQOS7(t *testing.T) {
sSpls := &SortedRoutes{
SortedRoutes: []*SortedRoute{
{
RouteID: "supplier1",
RouteID: "route1",
SortingData: map[string]interface{}{
utils.Weight: 15.0,
utils.MetaACD: -1.0,
},
},
{
RouteID: "supplier2",
RouteID: "route2",
SortingData: map[string]interface{}{
utils.Weight: 25.0,
utils.MetaACD: -1.0,
},
},
{
RouteID: "supplier3",
RouteID: "route3",
SortingData: map[string]interface{}{
utils.Weight: 20.0,
utils.MetaACD: -1.0,
@@ -582,7 +582,7 @@ func TestLibRoutesSortQOS7(t *testing.T) {
}
sSpls.SortQOS([]string{utils.MetaACD})
rcv := make([]string, len(sSpls.SortedRoutes))
eIds := []string{"supplier2", "supplier3", "supplier1"}
eIds := []string{"route2", "route3", "route1"}
for i, spl := range sSpls.SortedRoutes {
rcv[i] = spl.RouteID
@@ -597,21 +597,21 @@ func TestLibRoutesSortQOS8(t *testing.T) {
sSpls := &SortedRoutes{
SortedRoutes: []*SortedRoute{
{
RouteID: "supplier1",
RouteID: "route1",
SortingData: map[string]interface{}{
utils.Weight: 15.0,
utils.MetaACD: -1.0,
},
},
{
RouteID: "supplier2",
RouteID: "route2",
SortingData: map[string]interface{}{
utils.Weight: 25.0,
utils.MetaACD: -1.0,
},
},
{
RouteID: "supplier3",
RouteID: "route3",
SortingData: map[string]interface{}{
utils.Weight: 20.0,
utils.MetaACD: 10.0,
@@ -621,7 +621,7 @@ func TestLibRoutesSortQOS8(t *testing.T) {
}
sSpls.SortQOS([]string{utils.MetaACD})
rcv := make([]string, len(sSpls.SortedRoutes))
eIds := []string{"supplier3", "supplier2", "supplier1"}
eIds := []string{"route3", "route2", "route1"}
for i, spl := range sSpls.SortedRoutes {
rcv[i] = spl.RouteID
@@ -636,7 +636,7 @@ func TestLibRoutesSortLoadDistribution(t *testing.T) {
sSpls := &SortedRoutes{
SortedRoutes: []*SortedRoute{
{
RouteID: "supplier1",
RouteID: "route1",
SortingData: map[string]interface{}{
utils.Weight: 25.0,
utils.Ratio: 4.0,
@@ -644,7 +644,7 @@ func TestLibRoutesSortLoadDistribution(t *testing.T) {
},
},
{
RouteID: "supplier2",
RouteID: "route2",
SortingData: map[string]interface{}{
utils.Weight: 15.0,
utils.Ratio: 10.0,
@@ -652,7 +652,7 @@ func TestLibRoutesSortLoadDistribution(t *testing.T) {
},
},
{
RouteID: "supplier3",
RouteID: "route3",
SortingData: map[string]interface{}{
utils.Weight: 25.0,
utils.Ratio: 1.0,
@@ -663,7 +663,7 @@ func TestLibRoutesSortLoadDistribution(t *testing.T) {
}
sSpls.SortLoadDistribution()
rcv := make([]string, len(sSpls.SortedRoutes))
eIds := []string{"supplier2", "supplier1", "supplier3"}
eIds := []string{"route2", "route1", "route3"}
for i, spl := range sSpls.SortedRoutes {
rcv[i] = spl.RouteID
}
@@ -676,7 +676,7 @@ func TestLibRoutesSortLoadDistribution(t *testing.T) {
func TestLibRoutesLCSameWeight(t *testing.T) {
sSpls := &SortedRoutes{}
sortedSlice := &SortedRoutes{}
for i := 0; i <= 100; i++ {
for i := 0; i <= 10; i++ {
route := &SortedRoute{RouteID: strconv.Itoa(i), SortingData: map[string]interface{}{
utils.Cost: 0.1,
utils.Weight: 10.0,
@@ -684,19 +684,21 @@ func TestLibRoutesLCSameWeight(t *testing.T) {
sSpls.SortedRoutes = append(sSpls.SortedRoutes, route)
sortedSlice.SortedRoutes = append(sortedSlice.SortedRoutes, route)
}
sSpls.SortLeastCost()
// we expect to receive this in a random order
// the comparison logic is the following if the slice is the same as sorted slice we return error
if reflect.DeepEqual(sortedSlice, sSpls) {
t.Errorf("Expecting: %+v, \n received: %+v",
sortedSlice, sSpls)
for i := 0; i < 3; i++ {
sSpls.SortLeastCost()
// we expect to receive this in a random order
// the comparison logic is the following if the slice is the same as sorted slice we return error
if reflect.DeepEqual(sortedSlice, sSpls) {
t.Errorf("Expecting: %+v, \n received: %+v",
sortedSlice, sSpls)
}
}
}
func TestLibRoutesHCSameWeight(t *testing.T) {
sSpls := &SortedRoutes{}
sortedSlice := &SortedRoutes{}
for i := 0; i <= 100; i++ {
for i := 0; i <= 10; i++ {
route := &SortedRoute{RouteID: strconv.Itoa(i), SortingData: map[string]interface{}{
utils.Cost: 0.1,
utils.Weight: 10.0,
@@ -704,19 +706,21 @@ func TestLibRoutesHCSameWeight(t *testing.T) {
sSpls.SortedRoutes = append(sSpls.SortedRoutes, route)
sortedSlice.SortedRoutes = append(sortedSlice.SortedRoutes, route)
}
sSpls.SortHighestCost()
// we expect to receive this in a random order
// the comparison logic is the following if the slice is the same as sorted slice we return error
if reflect.DeepEqual(sortedSlice, sSpls) {
t.Errorf("Expecting: %+v, \n received: %+v",
sortedSlice, sSpls)
for i := 0; i < 3; i++ {
sSpls.SortHighestCost()
// we expect to receive this in a random order
// the comparison logic is the following if the slice is the same as sorted slice we return error
if reflect.DeepEqual(sortedSlice, sSpls) {
t.Errorf("Expecting: %+v, \n received: %+v",
sortedSlice, sSpls)
}
}
}
func TestLibRoutesResAscSameWeight(t *testing.T) {
sSpls := &SortedRoutes{}
sortedSlice := &SortedRoutes{}
for i := 0; i <= 100; i++ {
for i := 0; i <= 10; i++ {
route := &SortedRoute{RouteID: strconv.Itoa(i), SortingData: map[string]interface{}{
utils.ResourceUsage: 5.0,
utils.Weight: 10.0,
@@ -724,19 +728,21 @@ func TestLibRoutesResAscSameWeight(t *testing.T) {
sSpls.SortedRoutes = append(sSpls.SortedRoutes, route)
sortedSlice.SortedRoutes = append(sortedSlice.SortedRoutes, route)
}
sSpls.SortResourceAscendent()
// we expect to receive this in a random order
// the comparison logic is the following if the slice is the same as sorted slice we return error
if reflect.DeepEqual(sortedSlice, sSpls) {
t.Errorf("Expecting: %+v, \n received: %+v",
sortedSlice, sSpls)
for i := 0; i < 3; i++ {
sSpls.SortResourceAscendent()
// we expect to receive this in a random order
// the comparison logic is the following if the slice is the same as sorted slice we return error
if reflect.DeepEqual(sortedSlice, sSpls) {
t.Errorf("Expecting: %+v, \n received: %+v",
sortedSlice, sSpls)
}
}
}
func TestLibRoutesResDescSameWeight(t *testing.T) {
sSpls := &SortedRoutes{}
sortedSlice := &SortedRoutes{}
for i := 0; i <= 100; i++ {
for i := 0; i <= 10; i++ {
route := &SortedRoute{RouteID: strconv.Itoa(i), SortingData: map[string]interface{}{
utils.ResourceUsage: 5.0,
utils.Weight: 10.0,
@@ -744,19 +750,22 @@ func TestLibRoutesResDescSameWeight(t *testing.T) {
sSpls.SortedRoutes = append(sSpls.SortedRoutes, route)
sortedSlice.SortedRoutes = append(sortedSlice.SortedRoutes, route)
}
sSpls.SortResourceDescendent()
// we expect to receive this in a random order
// the comparison logic is the following if the slice is the same as sorted slice we return error
if reflect.DeepEqual(sortedSlice, sSpls) {
t.Errorf("Expecting: %+v, \n received: %+v",
sortedSlice, sSpls)
for i := 0; i < 3; i++ {
sSpls.SortResourceDescendent()
// we expect to receive this in a random order
// the comparison logic is the following if the slice is the same as sorted slice we return error
if reflect.DeepEqual(sortedSlice, sSpls) {
t.Errorf("Expecting: %+v, \n received: %+v",
sortedSlice, sSpls)
}
}
}
func TestLibRoutesLoadDistSameWeight(t *testing.T) {
sSpls := &SortedRoutes{}
sortedSlice := &SortedRoutes{}
for i := 0; i <= 100; i++ {
for i := 0; i <= 10; i++ {
route := &SortedRoute{RouteID: strconv.Itoa(i), SortingData: map[string]interface{}{
utils.Ratio: 4.0,
utils.Load: 3.0,
@@ -765,19 +774,21 @@ func TestLibRoutesLoadDistSameWeight(t *testing.T) {
sSpls.SortedRoutes = append(sSpls.SortedRoutes, route)
sortedSlice.SortedRoutes = append(sortedSlice.SortedRoutes, route)
}
sSpls.SortLoadDistribution()
// we expect to receive this in a random order
// the comparison logic is the following if the slice is the same as sorted slice we return error
if reflect.DeepEqual(sortedSlice, sSpls) {
t.Errorf("Expecting: %+v, \n received: %+v",
sortedSlice, sSpls)
for i := 0; i < 3; i++ {
sSpls.SortLoadDistribution()
// we expect to receive this in a random order
// the comparison logic is the following if the slice is the same as sorted slice we return error
if reflect.DeepEqual(sortedSlice, sSpls) {
t.Errorf("Expecting: %+v, \n received: %+v",
sortedSlice, sSpls)
}
}
}
func TestLibRoutesQOSSameWeight(t *testing.T) {
sSpls := &SortedRoutes{}
sortedSlice := &SortedRoutes{}
for i := 0; i <= 100; i++ {
for i := 0; i <= 10; i++ {
route := &SortedRoute{RouteID: strconv.Itoa(i), SortingData: map[string]interface{}{
utils.Weight: 10.0,
utils.MetaACD: -1.0,
@@ -785,31 +796,35 @@ func TestLibRoutesQOSSameWeight(t *testing.T) {
sSpls.SortedRoutes = append(sSpls.SortedRoutes, route)
sortedSlice.SortedRoutes = append(sortedSlice.SortedRoutes, route)
}
sSpls.SortQOS([]string{utils.MetaACD})
// we expect to receive this in a random order
// the comparison logic is the following if the slice is the same as sorted slice we return error
if reflect.DeepEqual(sortedSlice, sSpls) {
t.Errorf("Expecting: %+v, \n received: %+v",
sortedSlice, sSpls)
for i := 0; i < 3; i++ {
sSpls.SortQOS([]string{utils.MetaACD})
// we expect to receive this in a random order
// the comparison logic is the following if the slice is the same as sorted slice we return error
if reflect.DeepEqual(sortedSlice, sSpls) {
t.Errorf("Expecting: %+v, \n received: %+v",
sortedSlice, sSpls)
}
}
}
func TestLibRoutesSameWeight(t *testing.T) {
sSpls := &SortedRoutes{}
sortedSlice := &SortedRoutes{}
for i := 0; i <= 100; i++ {
for i := 0; i <= 10; i++ {
route := &SortedRoute{RouteID: strconv.Itoa(i), SortingData: map[string]interface{}{
utils.Weight: 10.0,
}}
sSpls.SortedRoutes = append(sSpls.SortedRoutes, route)
sortedSlice.SortedRoutes = append(sortedSlice.SortedRoutes, route)
}
sSpls.SortWeight()
// we expect to receive this in a random order
// the comparison logic is the following if the slice is the same as sorted slice we return error
if reflect.DeepEqual(sortedSlice, sSpls) {
t.Errorf("Expecting: %+v, \n received: %+v",
sortedSlice, sSpls)
for i := 0; i < 3; i++ {
sSpls.SortWeight()
// we expect to receive this in a random order
// the comparison logic is the following if the slice is the same as sorted slice we return error
if reflect.DeepEqual(sortedSlice, sSpls) {
t.Errorf("Expecting: %+v, \n received: %+v",
sortedSlice, sSpls)
}
}
}