mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-22 23:58:44 +05:00
Cover tests in utils package
This commit is contained in:
committed by
Dan Christian Bogos
parent
dd4d42e323
commit
db7f982169
@@ -116,3 +116,45 @@ func TestTenantIDAccountProfile(t *testing.T) {
|
||||
t.Errorf("Expected %+v, received %+v", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountProfileAsAccountProfile(t *testing.T) {
|
||||
apiAccPrf := &APIAccountProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "test_ID1",
|
||||
Balances: map[string]*APIBalance{
|
||||
"VoiceBalance": {
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Weight: 1.1,
|
||||
Blocker: true,
|
||||
Type: "*abstract",
|
||||
Opts: map[string]interface{}{
|
||||
"Destination": 10,
|
||||
},
|
||||
Units: 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
expected := &AccountProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "test_ID1",
|
||||
Balances: map[string]*Balance{
|
||||
"VoiceBalance": {
|
||||
ID: "VoiceBalance",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Weight: 1.1,
|
||||
Blocker: true,
|
||||
Type: "*abstract",
|
||||
Opts: map[string]interface{}{
|
||||
"Destination": 10,
|
||||
},
|
||||
Units: NewDecimal(0, 0),
|
||||
},
|
||||
},
|
||||
}
|
||||
if rcv, err := apiAccPrf.AsAccountProfile(); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, rcv) {
|
||||
t.Errorf("Expected %+v, received %+v", ToJSON(expected), ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1175,3 +1175,81 @@ func TestUsage(t *testing.T) {
|
||||
t.Errorf("Expected <2m10s> , received <%+v>", result.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewTPBalanceCostIncrement(t *testing.T) {
|
||||
incrementStr := "20"
|
||||
fixedFeeStr := "10"
|
||||
recurentFeeStr := "0.4"
|
||||
filterStr := "*string:*Account:1001"
|
||||
expected := &TPBalanceCostIncrement{
|
||||
FilterIDs: []string{"*string:*Account:1001"},
|
||||
Increment: Float64Pointer(20),
|
||||
FixedFee: Float64Pointer(10),
|
||||
RecurrentFee: Float64Pointer(0.4),
|
||||
}
|
||||
if rcv, err := NewTPBalanceCostIncrement(filterStr, incrementStr, fixedFeeStr, recurentFeeStr); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected %+v, received %+v", expected, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewTPBalanceCostIncrementErrors(t *testing.T) {
|
||||
invalidStr := "not_float64"
|
||||
expectedErr := "strconv.ParseFloat: parsing \"not_float64\": invalid syntax"
|
||||
if _, err := NewTPBalanceCostIncrement(EmptyString, invalidStr, EmptyString, EmptyString); err == nil || err.Error() != expectedErr {
|
||||
t.Errorf("Expected %+v, received %+v", expectedErr, err)
|
||||
}
|
||||
if _, err := NewTPBalanceCostIncrement(EmptyString, EmptyString, invalidStr, EmptyString); err == nil || err.Error() != expectedErr {
|
||||
t.Errorf("Expected %+v, received %+v", expectedErr, err)
|
||||
}
|
||||
if _, err := NewTPBalanceCostIncrement(EmptyString, EmptyString, EmptyString, invalidStr); err == nil || err.Error() != expectedErr {
|
||||
t.Errorf("Expected %+v, received %+v", expectedErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPBalanceCostIncrementAsString(t *testing.T) {
|
||||
costIncr := &TPBalanceCostIncrement{
|
||||
FilterIDs: []string{"*string:*Account:1001"},
|
||||
Increment: Float64Pointer(20),
|
||||
FixedFee: Float64Pointer(10),
|
||||
RecurrentFee: Float64Pointer(0.4),
|
||||
}
|
||||
expected := "*string:*Account:1001;20;10;0.4"
|
||||
if rcv := costIncr.AsString(); expected != rcv {
|
||||
t.Errorf("Expected %+v, received %+v", expected, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewBalanceUnitFactor(t *testing.T) {
|
||||
factorStr := "1.7"
|
||||
filterStr := "*string:*Account:1001"
|
||||
expected := &TPBalanceUnitFactor{
|
||||
FilterIDs: []string{"*string:*Account:1001"},
|
||||
Factor: 1.7,
|
||||
}
|
||||
if rcv, err := NewTPBalanceUnitFactor(filterStr, factorStr); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, rcv) {
|
||||
t.Errorf("Expected %+v, received %+v", expected, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewBalanceUnitFactorError(t *testing.T) {
|
||||
invalidStr := "not_float64"
|
||||
expectedErr := "strconv.ParseFloat: parsing \"not_float64\": invalid syntax"
|
||||
if _, err := NewTPBalanceUnitFactor(EmptyString, invalidStr); err == nil || err.Error() != expectedErr {
|
||||
t.Errorf("Expected %+v, received %+v", expectedErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBalanceUnitFactor(t *testing.T) {
|
||||
unitFctr := &TPBalanceUnitFactor{
|
||||
FilterIDs: []string{"*string:*Account:1001"},
|
||||
Factor: 1.7,
|
||||
}
|
||||
expected := "*string:*Account:1001;1.7"
|
||||
if rcv := unitFctr.AsString(); expected != rcv {
|
||||
t.Errorf("Expected %+v, received %+v", expected, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user