mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added test for NewBalanceFilter
This commit is contained in:
@@ -54,7 +54,7 @@ func NewBalanceFilter(filter map[string]interface{}, defaultTimezone string) (bf
|
||||
bf.Uuid = utils.StringPointer(utils.IfaceAsString(uuid))
|
||||
}
|
||||
// if ty, has := filter[utils.Type]; has {
|
||||
// bf.Uuid = utils.StringPointer(utils.IfaceAsString(ty))
|
||||
// bf.Type = utils.StringPointer(utils.IfaceAsString(ty))
|
||||
// }
|
||||
if val, has := filter[utils.Value]; has {
|
||||
var value float64
|
||||
|
||||
92
engine/balance_filter_test.go
Normal file
92
engine/balance_filter_test.go
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package engine
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"reflect"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestNewBalanceFilter(t *testing.T) {
|
||||
attrs := map[string]interface{}{}
|
||||
expected := &BalanceFilter{}
|
||||
if rply, err := NewBalanceFilter(attrs, ""); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, rply) {
|
||||
t.Errorf("Expected: %s ,received: %s", utils.ToJSON(expected), utils.ToJSON(rply))
|
||||
}
|
||||
|
||||
tNow := time.Now()
|
||||
attrs = map[string]interface{}{
|
||||
utils.ID: "ID",
|
||||
utils.UUID: "UUID",
|
||||
utils.Value: 10.5,
|
||||
utils.ExpiryTime: tNow,
|
||||
utils.Weight: 10,
|
||||
utils.DestinationIDs: "dst1;dst2",
|
||||
utils.RatingSubject: "*zero",
|
||||
utils.Categories: "call;voice",
|
||||
utils.SharedGroups: "shrdGroup",
|
||||
utils.TimingIDs: "*asap",
|
||||
utils.Disabled: false,
|
||||
utils.Blocker: true,
|
||||
}
|
||||
expected = &BalanceFilter{
|
||||
ID: utils.StringPointer("ID"),
|
||||
Uuid: utils.StringPointer("UUID"),
|
||||
Value: &utils.ValueFormula{Static: 10.5},
|
||||
ExpirationDate: utils.TimePointer(tNow),
|
||||
Weight: utils.Float64Pointer(10),
|
||||
DestinationIDs: utils.StringMapPointer(utils.NewStringMap("dst1", "dst2")),
|
||||
RatingSubject: utils.StringPointer("*zero"),
|
||||
Categories: utils.StringMapPointer(utils.NewStringMap("call", "voice")),
|
||||
SharedGroups: utils.StringMapPointer(utils.NewStringMap("shrdGroup")),
|
||||
TimingIDs: utils.StringMapPointer(utils.NewStringMap("*asap")),
|
||||
Disabled: utils.BoolPointer(false),
|
||||
Blocker: utils.BoolPointer(true),
|
||||
}
|
||||
if rply, err := NewBalanceFilter(attrs, ""); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, rply) {
|
||||
t.Errorf("Expected: %s ,received: %s", utils.ToJSON(expected), utils.ToJSON(rply))
|
||||
}
|
||||
attrs[utils.Blocker] = "10"
|
||||
if _, err := NewBalanceFilter(attrs, ""); err == nil {
|
||||
t.Error("Expecxted error received nil")
|
||||
}
|
||||
attrs[utils.Disabled] = "10"
|
||||
if _, err := NewBalanceFilter(attrs, ""); err == nil {
|
||||
t.Error("Expecxted error received nil")
|
||||
}
|
||||
attrs[utils.Weight] = "NotFloat"
|
||||
if _, err := NewBalanceFilter(attrs, ""); err == nil {
|
||||
t.Error("Expecxted error received nil")
|
||||
}
|
||||
attrs[utils.ExpirationDate] = "NotTime"
|
||||
if _, err := NewBalanceFilter(attrs, ""); err == nil {
|
||||
t.Error("Expecxted error received nil")
|
||||
}
|
||||
attrs[utils.Value] = "NotFloat"
|
||||
if _, err := NewBalanceFilter(attrs, ""); err == nil {
|
||||
t.Error("Expecxted error received nil")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user