mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 16:48:45 +05:00
Added tests for MissingMapFields and IfaceAsSliceString
This commit is contained in:
@@ -19,6 +19,7 @@ package utils
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -28,10 +29,10 @@ func TestMissingStructFieldsCorrect(t *testing.T) {
|
||||
Direction string
|
||||
Account string
|
||||
Type string
|
||||
ActionTimingsId string
|
||||
ActionTimingsID string
|
||||
}{"bevoip.eu", "OUT", "danconns0001", META_PREPAID, "mama"}
|
||||
if missing := MissingStructFields(&attr,
|
||||
[]string{"Tenant", "Direction", "Account", "Type", "ActionTimingsId"}); len(missing) != 0 {
|
||||
[]string{"Tenant", "Direction", "Account", "Type", "ActionTimingsID"}); len(missing) != 0 {
|
||||
t.Error("Found missing field on correct struct", missing)
|
||||
}
|
||||
}
|
||||
@@ -275,3 +276,26 @@ func TestToMapMapStringInterface(t *testing.T) {
|
||||
t.Errorf("expecting: %+v, received: %+v", expMapStruct, mapStruct)
|
||||
}
|
||||
}*/
|
||||
|
||||
func TestMissingMapFields(t *testing.T) {
|
||||
var attr = map[string]interface{}{
|
||||
Tenant: "cgrates.org",
|
||||
Direction: "OUT",
|
||||
Account: "1001",
|
||||
"Type": META_PREPAID,
|
||||
"ActionTimingsID": "*asap",
|
||||
}
|
||||
if missing := MissingMapFields(attr,
|
||||
[]string{"Tenant", "Direction", "Account", "Type", "ActionTimingsID"}); len(missing) != 0 {
|
||||
t.Error("Found missing field on correct struct", missing)
|
||||
}
|
||||
attr["ActionTimingsID"] = ""
|
||||
delete(attr, "Type")
|
||||
expected := []string{"ActionTimingsID", "Type"}
|
||||
missing := MissingMapFields(attr,
|
||||
[]string{"Tenant", "Direction", "Account", "Type", "ActionTimingsID"})
|
||||
sort.Strings(missing)
|
||||
if !reflect.DeepEqual(expected, missing) {
|
||||
t.Errorf("Expected %s ,received: %s", expected, missing)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user