mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
NavigableMap populating order field
This commit is contained in:
@@ -123,7 +123,7 @@ func TestHAitAuth1001(t *testing.T) {
|
||||
eXml := []byte(`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<response>
|
||||
<Allow>1</Allow>
|
||||
<MaxDuration>10800</MaxDuration>
|
||||
<MaxDuration>6042</MaxDuration>
|
||||
</response>`)
|
||||
if body, err := ioutil.ReadAll(rply.Body); err != nil {
|
||||
t.Error(err)
|
||||
@@ -152,7 +152,7 @@ func TestHAitCDRmtcall(t *testing.T) {
|
||||
t.Errorf("expecting: <%s>, received: <%s>", string(eXml), string(body))
|
||||
}
|
||||
rply.Body.Close()
|
||||
time.Sleep(time.Millisecond)
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
var cdrs []*engine.ExternalCDR
|
||||
req := utils.RPCCDRsFilter{RunIDs: []string{utils.META_DEFAULT}}
|
||||
if err := haRPC.Call("ApierV2.GetCdrs", req, &cdrs); err != nil {
|
||||
@@ -168,3 +168,9 @@ func TestHAitCDRmtcall(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHAitStopEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(*waitRater); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,9 @@ type NavigableMap struct {
|
||||
|
||||
// Add will add items into NavigableMap populating also order
|
||||
func (nM *NavigableMap) Set(path []string, data interface{}, ordered bool) {
|
||||
if ordered {
|
||||
nM.order = append(nM.order, path)
|
||||
}
|
||||
mp := nM.data
|
||||
for i, spath := range path {
|
||||
if i == len(path)-1 { // last path
|
||||
@@ -70,9 +73,6 @@ func (nM *NavigableMap) Set(path []string, data interface{}, ordered bool) {
|
||||
}
|
||||
mp = mp[spath].(map[string]interface{}) // so we can check further down
|
||||
}
|
||||
if ordered {
|
||||
nM.order = append(nM.order, path)
|
||||
}
|
||||
}
|
||||
|
||||
// FieldAsInterface returns the field value as interface{} for the path specified
|
||||
|
||||
@@ -180,6 +180,16 @@ func TestNavMapAdd(t *testing.T) {
|
||||
if !reflect.DeepEqual(nM.data, eNavMap.data) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eNavMap.data, nM.data)
|
||||
}
|
||||
eOrder := [][]string{
|
||||
[]string{"FistLever2", "SecondLevel2", "Field2"},
|
||||
[]string{"FirstLevel", "SecondLevel", "ThirdLevel", "Fld1"},
|
||||
[]string{"FistLever2", "Field3"},
|
||||
[]string{"Field4"},
|
||||
}
|
||||
if !reflect.DeepEqual(eOrder, nM.order) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eOrder, nM.order)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type testStruct struct {
|
||||
|
||||
Reference in New Issue
Block a user