better cgr_rpc and more tests

This commit is contained in:
Radu Ioan Fericean
2016-05-26 15:21:01 +03:00
parent 842019f080
commit 27f835b9e1
10 changed files with 104 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
package utils
import (
"cmd/cgrates/utils"
"reflect"
"testing"
)
@@ -113,3 +114,27 @@ func TestStructFromMapStringInterface(t *testing.T) {
t.Error("Error converting map to struct: ", err)
}
}
func TestStructFromMapStringInterfaceValue(t *testing.T) {
type T struct {
Name string
Disabled *bool
Members []string
}
ts := &T{}
vts := reflect.ValueOf(ts)
x, err := FromMapStringInterfaceValue(map[string]interface{}{
"Name": "test",
"Disabled": true,
"Members": []string{"1", "2", "3"},
}, vts)
rt := x.(T)
if err != nil {
t.Fatalf("error converting structure value: %v", err)
}
if rt.Name != "test" ||
*rt.Disabled != true ||
!reflect.DeepEqual(rt.Members, []string{"1", "2", "3"}) {
t.Errorf("error converting structure value: %s", utils.ToIJSON(rt))
}
}