diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index ef66930f7..c5f9bc37d 100644 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -4523,3 +4523,35 @@ func TestAsTPRateProfile(t *testing.T) { t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(eRprf), utils.ToJSON(rcv[0])) } } + +func TestModelHelperCsvLoadError(t *testing.T) { + + type testStruct struct { + Id int64 + Tpid string + Tag string `index:"cat" re:"\w+\s*,\s*"` + Prefix string `index:"1" re:"\+?\d+.?\d*"` + CreatedAt time.Time + } + var testStruct1 testStruct + _, err := csvLoad(testStruct1, []string{"TEST_DEST", "+492"}) + if err == nil || err.Error() != "invalid testStruct.Tag index cat" { + t.Errorf("Expecting: ,\nReceived: <%+v>", err) + } +} + +func TestModelHelperCsvLoadError2(t *testing.T) { + type testStruct struct { + Id int64 + Tpid string + Tag string `index:"0" re:"cat"` + Prefix string `index:"1" re:"\+?\d+.?\d*"` + CreatedAt time.Time + } + var testStruct1 testStruct + _, err := csvLoad(testStruct1, []string{"TEST_DEST", "+492"}) + + if err == nil || err.Error() != "invalid testStruct.Tag value TEST_DEST" { + t.Errorf("Expecting: ,\nReceived: <%+v>", err) + } +} diff --git a/engine/rateinterval_test.go b/engine/rateinterval_test.go index 6294d93b3..b9f00c223 100644 --- a/engine/rateinterval_test.go +++ b/engine/rateinterval_test.go @@ -575,3 +575,138 @@ func BenchmarkRateIntervalContainsDate(b *testing.B) { i.Contains(d, false) } } + +func TestRateIntervalCronStringDefault(t *testing.T) { + rit := &RITiming{ + StartTime: "223000", + } + cron := rit.CronString() + if !reflect.DeepEqual(cron, "* * * * * * *") { + t.Errorf("\nExpecting: <* * * * * * *>,\n Received: <%+v>", cron) + } +} + +func TestRateIntervalCronStringMonthDayNegative(t *testing.T) { + rit := &RITiming{ + StartTime: "223000", + MonthDays: utils.MonthDays{-1}, + } + cron := rit.CronString() + if !reflect.DeepEqual(cron, "* * * L * * *") { + t.Errorf("\nExpecting: <* * * L * * *>,\n Received: <%+v>", cron) + } +} + +func TestRateIntervalIsActiveAt(t *testing.T) { + rit := &RITiming{} + cronActive := rit.IsActive() + if !reflect.DeepEqual(cronActive, true) { + t.Errorf("\nExpecting: ,\n Received: <%+v>", cronActive) + } +} + +func TestRateIntervalIsActiveAtNot(t *testing.T) { + rit := &RITiming{ + Years: utils.Years{1000}, + } + cronActive := rit.IsActive() + if !reflect.DeepEqual(cronActive, false) { + t.Errorf("\nExpecting: ,\n Received: <%+v>", cronActive) + } +} + +func TestRateIntervalFieldAsInterfaceError(t *testing.T) { + rateTest := &RGRate{ + Value: 2.2, + } + _, err := rateTest.FieldAsInterface([]string{"FALSE"}) + if err == nil && err.Error() != "unsupported field prefix: " { + t.Errorf("\nExpecting: >,\n Received: <%+v>", err) + } +} + +func TestRateIntervalFieldAsInterfaceError2(t *testing.T) { + rateTest := &RGRate{} + _, err := rateTest.FieldAsInterface([]string{"value1", "value2"}) + + if err == nil && err != utils.ErrNotFound { + t.Errorf("\nExpecting: ,\n Received: <%+v>", err) + } +} + +func TestRateIntervalFieldAsInterfaceRateIncrement(t *testing.T) { + rateTest := &RGRate{ + RateIncrement: time.Second, + } + if result, err := rateTest.FieldAsInterface([]string{"RateIncrement"}); err != nil { + t.Errorf("\nExpecting: ,\n Received: <%+v>", err) + } else if !reflect.DeepEqual(result, time.Second) { + t.Errorf("\nExpecting: <1s>,\n Received: <%+v>", result) + } + +} + +func TestRateIntervalFieldAsInterfaceGroupIntervalStart(t *testing.T) { + rateTest := &RGRate{ + GroupIntervalStart: time.Second, + } + if result, err := rateTest.FieldAsInterface([]string{"GroupIntervalStart"}); err != nil { + t.Errorf("\nExpecting: ,\n Received: <%+v>", err) + } else if !reflect.DeepEqual(result, time.Second) { + t.Errorf("\nExpecting: <1s>,\n Received: <%+v>", result) + } + +} + +func TestRateIntervalFieldAsInterfaceRateUnit(t *testing.T) { + rateTest := &RGRate{ + RateUnit: time.Second, + } + if result, err := rateTest.FieldAsInterface([]string{"RateUnit"}); err != nil { + t.Errorf("\nExpecting: ,\n Received: <%+v>", err) + } else if !reflect.DeepEqual(result, time.Second) { + t.Errorf("\nExpecting: <1s>,\n Received: <%+v>", result) + } + +} + +func TestRateGroupsEqual(t *testing.T) { + rateGroupOG := RateGroups{&RGRate{ + Value: 2.2, + }} + rateGroupOther := RateGroups{&RGRate{ + Value: 2.2, + }} + result := rateGroupOG.Equal(rateGroupOther) + if !reflect.DeepEqual(result, true) { + t.Errorf("\nExpecting: ,\n Received: <%+v>", result) + } +} + +func TestRateGroupsEqualFalse(t *testing.T) { + rateGroupOG := RateGroups{&RGRate{ + Value: 2.2, + }} + rateGroupOther := RateGroups{&RGRate{ + Value: 2.5, + }} + result := rateGroupOG.Equal(rateGroupOther) + if !reflect.DeepEqual(result, false) { + t.Errorf("\nExpecting: ,\n Received: <%+v>", result) + } +} + +func TestRateGroupsUnEqual(t *testing.T) { + rateGroupOG := RateGroups{&RGRate{ + Value: 2.2, + }, + &RGRate{}, + } + rateGroupOther := RateGroups{&RGRate{ + Value: 2.5, + }} + result := rateGroupOG.Equal(rateGroupOther) + if !reflect.DeepEqual(result, false) { + t.Errorf("\nExpecting: ,\n Received: <%+v>", result) + } +}