diff --git a/utils/account_test.go b/utils/account_test.go index b4d39e0b5..39d21d6db 100644 --- a/utils/account_test.go +++ b/utils/account_test.go @@ -260,6 +260,21 @@ func TestAPIBalanceAsBalance(t *testing.T) { t.Errorf("Expected %+v \n, received %+v", ToJSON(expected), ToJSON(rcv)) } + // Can't convert units + blc.Units = "can't convert" + exp := "can't convert to decimal" + if _, err := blc.AsBalance(); err == nil || err.Error() != exp { + t.Errorf("Expected %v \n but received \n %v", exp, err.Error()) + } + blc.Units = "0" + + //Can't convert increment + blc.CostIncrements[0].Increment = "error" + exp = "can't convert to decimal" + if _, err := blc.AsBalance(); err == nil || err.Error() != exp { + t.Errorf("Expected %v \n but received \n %v", exp, err.Error()) + } + blc.CostIncrements[0].Increment = "1" } func TestAccountBalancesAlteredCompareLength(t *testing.T) { diff --git a/utils/coreutils_test.go b/utils/coreutils_test.go index 6073d569c..074140967 100644 --- a/utils/coreutils_test.go +++ b/utils/coreutils_test.go @@ -1466,3 +1466,37 @@ func TestCoreUtilsSplitPath(t *testing.T) { t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, rcv) } } + +func TestFibDuration(t *testing.T) { + // fib := Fib() + // if tmp := fib(); tmp != 1 { + // t.Error("Expecting: 1, received ", tmp) + // } + // if tmp := fib(); tmp != 1 { + // t.Error("Expecting: 1, received ", tmp) + // } + // if tmp := fib(); tmp != 2 { + // t.Error("Expecting: 2, received ", tmp) + // } + // if tmp := fib(); tmp != 3 { + // t.Error("Expecting: 3, received ", tmp) + // } + // if tmp := fib(); tmp != 5 { + // t.Error("Expecting: 5, received ", tmp) + // } + if tmp := FibDuration(1 * time.Second); tmp() != 1*time.Second { + t.Error("Expecting: 1, received ", tmp()) + } + if tmp := FibDuration(1 * time.Second); tmp() != 1*time.Second { + t.Error("Expecting: 1, received ", tmp()) + } + if tmp := FibDuration(2 * time.Second); tmp() != 2*time.Second { + t.Error("Expecting: 2, received ", tmp()) + } + if tmp := FibDuration(2 * time.Second); tmp() != 2*time.Second { + t.Error("Expecting: 2, received ", tmp()) + } + if tmp := FibDuration(2 * time.Second); tmp() != 2*time.Second { + t.Error("Expecting: 2, received ", tmp()) + } +} diff --git a/utils/decimal_test.go b/utils/decimal_test.go index 5145f4a52..59bd2daa3 100644 --- a/utils/decimal_test.go +++ b/utils/decimal_test.go @@ -352,7 +352,7 @@ func TestDecimalFloat64(t *testing.T) { } func TestDecimalDuration(t *testing.T) { - d := NewDecimal(3, 0) + d := NewDecimal(int64(3), 0) rcv, ok := d.Duration() if !ok { t.Error("Cannot convert") diff --git a/utils/librates.go b/utils/librates.go index 7aca1f7d4..3a08da736 100644 --- a/utils/librates.go +++ b/utils/librates.go @@ -273,7 +273,7 @@ func (rI *RateSIncrement) AsRateSIncrementCost() (rIc *RateSIncrementCost) { // Equals returns the equality between two RateSIntervalCost func (rIC *RateSIntervalCost) Equals(nRIc *RateSIntervalCost, rIlRef, nRilRef map[string]*IntervalRate) (eq bool) { - if (rIC.Increments != nil && rIC.Increments == nil || + if (rIC.Increments != nil && nRIc.Increments == nil || rIC.Increments == nil && nRIc.Increments != nil || len(rIC.Increments) != len(nRIc.Increments)) || rIC.CompressFactor != nRIc.CompressFactor { return diff --git a/utils/librates_test.go b/utils/librates_test.go index 69872546a..5fdf9740d 100644 --- a/utils/librates_test.go +++ b/utils/librates_test.go @@ -1628,3 +1628,44 @@ func TestAPIRateAsRateError(t *testing.T) { t.Errorf("Expected %v \n but received \n %v", exp, err.Error()) } } + +func TestIntervalRateEqualsNilIR(t *testing.T) { + var iR *IntervalRate + iR = nil + iR.Equals(nil) + + iR = &IntervalRate{ + Unit: NewDecimal(int64(2), 0), + } + iR.Equals(nil) +} + +func TestRateSIntervalCostEquals(t *testing.T) { + rIC := &RateSIntervalCost{ + Increments: nil, + } + nRIc := &RateSIntervalCost{ + Increments: []*RateSIncrementCost{ + { + RateIntervalIndex: 0, + RateID: "RI1", + CompressFactor: int64(1), + Usage: NewDecimal(int64(2), 0), + }, + }, + } + if rIC.Equals(nRIc, nil, nil) { + t.Error("Shouldn't match") + } + rIC.Increments = []*RateSIncrementCost{ + { + RateIntervalIndex: 3, + RateID: "RI2", + CompressFactor: int64(3), + Usage: NewDecimal(int64(5), 0), + }, + } + if rIC.Equals(nRIc, nil, nil) { + t.Error("Shouldn't match") + } +}