NavigableMap populating order field

This commit is contained in:
DanB
2018-07-13 13:17:47 +02:00
parent 7def6ab928
commit de3fefdd3f
3 changed files with 21 additions and 5 deletions

View File

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

View File

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

View File

@@ -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 {