Added tests for MissingMapFields and IfaceAsSliceString

This commit is contained in:
Trial97
2019-12-04 14:36:37 +02:00
parent 2a356792fb
commit 4780f3bbef
4 changed files with 155 additions and 22 deletions

View File

@@ -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)
}
}