mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
improved coverage tests at utils
This commit is contained in:
committed by
Dan Christian Bogos
parent
fda4b00f5d
commit
1c3db609a3
@@ -748,28 +748,35 @@ func TestParseZeroRatingSubject(t *testing.T) {
|
||||
MetaVoice: "*zero1s",
|
||||
}
|
||||
for i, s := range subj {
|
||||
if d, err := ParseZeroRatingSubject(MetaVoice, s, dfltRatingSubject, true); err != nil || d != dur[i] {
|
||||
t.Error("Error parsing rating subject: ", s, d, err)
|
||||
if i == 0 {
|
||||
if d, err := ParseZeroRatingSubject(MetaVoice, s, dfltRatingSubject, false); err == nil {
|
||||
t.Error("Error parsing rating subject: ", s, d, err)
|
||||
}
|
||||
|
||||
} else {
|
||||
if d, err := ParseZeroRatingSubject(MetaVoice, s, dfltRatingSubject, true); err != nil || d != dur[i] {
|
||||
t.Error("Error parsing rating subject: ", s, d, err)
|
||||
}
|
||||
|
||||
}
|
||||
if d, err := ParseZeroRatingSubject(MetaData, EmptyString, dfltRatingSubject, true); err != nil || d != time.Nanosecond {
|
||||
t.Error("Error parsing rating subject: ", EmptyString, d, err)
|
||||
}
|
||||
if d, err := ParseZeroRatingSubject(MetaSMS, EmptyString, dfltRatingSubject, true); err != nil || d != time.Nanosecond {
|
||||
t.Error("Error parsing rating subject: ", EmptyString, d, err)
|
||||
}
|
||||
if d, err := ParseZeroRatingSubject(MetaMMS, EmptyString, dfltRatingSubject, true); err != nil || d != time.Nanosecond {
|
||||
t.Error("Error parsing rating subject: ", EmptyString, d, err)
|
||||
}
|
||||
if d, err := ParseZeroRatingSubject(MetaMonetary, EmptyString, dfltRatingSubject, true); err != nil || d != time.Nanosecond {
|
||||
t.Error("Error parsing rating subject: ", EmptyString, d, err)
|
||||
}
|
||||
expecting := "malformed rating subject: test"
|
||||
if _, err := ParseZeroRatingSubject(MetaMonetary, "test", dfltRatingSubject, true); err == nil || err.Error() != expecting {
|
||||
t.Errorf("Expecting: %+v, received: %+v ", expecting, err)
|
||||
}
|
||||
}
|
||||
if d, err := ParseZeroRatingSubject(MetaData, EmptyString, dfltRatingSubject, true); err != nil || d != time.Nanosecond {
|
||||
t.Error("Error parsing rating subject: ", EmptyString, d, err)
|
||||
}
|
||||
if d, err := ParseZeroRatingSubject(MetaSMS, EmptyString, dfltRatingSubject, true); err != nil || d != time.Nanosecond {
|
||||
t.Error("Error parsing rating subject: ", EmptyString, d, err)
|
||||
}
|
||||
if d, err := ParseZeroRatingSubject(MetaMMS, EmptyString, dfltRatingSubject, true); err != nil || d != time.Nanosecond {
|
||||
t.Error("Error parsing rating subject: ", EmptyString, d, err)
|
||||
}
|
||||
if d, err := ParseZeroRatingSubject(MetaMonetary, EmptyString, dfltRatingSubject, true); err != nil || d != time.Nanosecond {
|
||||
t.Error("Error parsing rating subject: ", EmptyString, d, err)
|
||||
}
|
||||
expecting := "malformed rating subject: test"
|
||||
if _, err := ParseZeroRatingSubject(MetaMonetary, "test", dfltRatingSubject, true); err == nil || err.Error() != expecting {
|
||||
t.Errorf("Expecting: %+v, received: %+v ", expecting, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConcatenatedKey(t *testing.T) {
|
||||
if key := ConcatenatedKey("a"); key != "a" {
|
||||
t.Error("Unexpected key value received: ", key)
|
||||
@@ -1185,6 +1192,16 @@ func TestDurationPointer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSliceStringPointer(t *testing.T) {
|
||||
sl := []string{"test"}
|
||||
result := SliceStringPointer(sl)
|
||||
exp := result
|
||||
if !reflect.DeepEqual(result, exp) {
|
||||
t.Errorf("Expeced:%+q but received %+q", exp, result)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestToIJSON(t *testing.T) {
|
||||
str := "string"
|
||||
received := ToIJSON(str)
|
||||
@@ -1884,4 +1901,8 @@ func TestCoreUtilsFibDurationSeqNrOverflow(t *testing.T) {
|
||||
t.Errorf("expected: <%+v>, \nreceived: <%+v>", AbsoluteMaxDuration, rcv)
|
||||
}
|
||||
}
|
||||
fib = FibDuration(time.Second, 6)
|
||||
if rcv := fib(); rcv != 6 {
|
||||
t.Errorf("expected: <%+v>, \nreceived: <%+v>", AbsoluteMaxDuration, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1132,6 +1132,9 @@ func TestLenTimeConverter3(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expected, rcv) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected, rcv)
|
||||
}
|
||||
if rcv, err := cnv.Convert(nil); err != nil {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloat64Converter(t *testing.T) {
|
||||
@@ -1180,6 +1183,10 @@ func TestSliceConverter(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expected2, rcv) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected, rcv)
|
||||
}
|
||||
|
||||
if _, err := cnv.Convert(`test`); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestE164FromNAPTRConverter(t *testing.T) {
|
||||
@@ -1191,6 +1198,9 @@ func TestE164FromNAPTRConverter(t *testing.T) {
|
||||
if !reflect.DeepEqual(exp, cnv) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", exp, cnv)
|
||||
}
|
||||
if _, err := cnv.Convert("8.7.6.5.4.3.2.1"); err == nil {
|
||||
t.Error("Error")
|
||||
}
|
||||
if e164, err := cnv.Convert("8.7.6.5.4.3.2.1.0.1.6.e164.arpa."); err != nil {
|
||||
t.Error(err)
|
||||
} else if e164 != "61012345678" {
|
||||
@@ -1207,6 +1217,7 @@ func TestDomainNameFromNAPTRConverter(t *testing.T) {
|
||||
if !reflect.DeepEqual(exp, cnv) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", exp, cnv)
|
||||
}
|
||||
|
||||
if dName, err := cnv.Convert("8.7.6.5.4.3.2.1.0.1.6.e164.arpa."); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if dName != "e164.arpa" {
|
||||
|
||||
@@ -144,3 +144,17 @@ func TestSafeMapStorageClone(t *testing.T) {
|
||||
t.Errorf("Expected %v \n but received \n %v", expected, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSafeMapClonedMapStorage(t *testing.T) {
|
||||
|
||||
ms := &SafeMapStorage{
|
||||
MapStorage: MapStorage{
|
||||
"field1": 2,
|
||||
"field2": 3,
|
||||
},
|
||||
}
|
||||
|
||||
if reply := ms.ClonedMapStorage(); reflect.DeepEqual(ms, reply) {
|
||||
t.Errorf("Expected %v \n but received \n %v", ms, reply)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
@@ -298,3 +299,23 @@ func TestStringFieldAsString(t *testing.T) {
|
||||
t.Errorf("expected %v got error", exp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringString(t *testing.T) {
|
||||
s := StringSet{
|
||||
"key1": struct{}{},
|
||||
"key2": struct{}{},
|
||||
"key3": struct{}{},
|
||||
}
|
||||
exp := `["key1","key2","key3"]`
|
||||
|
||||
rcv := s.String()
|
||||
rcvAsMap := []string{}
|
||||
if err := json.Unmarshal([]byte(rcv), &rcvAsMap); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
rcv = ToJSON(rcvAsMap)
|
||||
if rcv != exp {
|
||||
t.Errorf("expected %v received %v", exp, rcv)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -299,7 +299,9 @@ func TestValueFieldAsInterface(t *testing.T) {
|
||||
fldPath = []string{"test1"}
|
||||
vf = &ValueFormula{
|
||||
Method: "Method",
|
||||
Params: map[string]interface{}{},
|
||||
Params: map[string]interface{}{
|
||||
"key": "val",
|
||||
},
|
||||
Static: 22,
|
||||
}
|
||||
if val, _ := vf.FieldAsInterface(fldPath); val != nil {
|
||||
@@ -330,4 +332,32 @@ func TestValueFieldAsInterface(t *testing.T) {
|
||||
t.Error("expected error")
|
||||
}
|
||||
|
||||
fldPath = []string{"Params[key]"}
|
||||
if _, err := vf.FieldAsInterface(fldPath); err != nil {
|
||||
|
||||
t.Errorf("expected error nil but received %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestValueFieldAsString(t *testing.T) {
|
||||
vf := &ValueFormula{}
|
||||
fldPath := []string{}
|
||||
|
||||
if _, err := vf.FieldAsString(fldPath); err == nil {
|
||||
t.Error("expected error")
|
||||
}
|
||||
|
||||
vf = &ValueFormula{
|
||||
Method: "Method",
|
||||
Params: map[string]interface{}{
|
||||
"Params": "index",
|
||||
},
|
||||
Static: 22,
|
||||
}
|
||||
fldPath = []string{"Params"}
|
||||
if val, err := vf.FieldAsString(fldPath); err != nil {
|
||||
t.Errorf("expected %v", val)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user