mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added tests for mapstorage
This commit is contained in:
committed by
Dan Christian Bogos
parent
a3132684c1
commit
43c19e3a14
@@ -34,7 +34,7 @@ func onCacheEvicted(itmID string, value interface{}) {
|
||||
ee.OnEvicted(itmID, value)
|
||||
}
|
||||
|
||||
// NewERService instantiates the EventExporterS
|
||||
// NewEventExporterS instantiates the EventExporterS
|
||||
func NewEventExporterS(cfg *config.CGRConfig, filterS *engine.FilterS,
|
||||
connMgr *engine.ConnManager) (eeS *EventExporterS) {
|
||||
eeS = &EventExporterS{
|
||||
@@ -66,7 +66,7 @@ func (eeS *EventExporterS) ListenAndServe(exitChan chan bool, cfgRld chan struct
|
||||
case e := <-exitChan: // global exit
|
||||
eeS.Shutdown()
|
||||
exitChan <- e // put back for the others listening for shutdown request
|
||||
break
|
||||
return
|
||||
case rld := <-cfgRld: // configuration was reloaded, destroy the cache
|
||||
cfgRld <- rld
|
||||
utils.Logger.Info(fmt.Sprintf("<%s> reloading configuration internals.",
|
||||
@@ -74,7 +74,6 @@ func (eeS *EventExporterS) ListenAndServe(exitChan chan bool, cfgRld chan struct
|
||||
eeS.setupCache(eeS.cfg.EEsCfg().Cache)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Shutdown is called to shutdown the service
|
||||
@@ -127,7 +126,7 @@ func (eeS *EventExporterS) attrSProcessEvent(cgrEv *utils.CGREventWithOpts, attr
|
||||
return
|
||||
}
|
||||
|
||||
// ProcessEvent will be called each time a new event is received from readers
|
||||
// V1ProcessEvent will be called each time a new event is received from readers
|
||||
func (eeS *EventExporterS) V1ProcessEvent(cgrEv *utils.CGREventWithOpts, rply *string) (err error) {
|
||||
eeS.cfg.RLocks(config.EEsJson)
|
||||
defer eeS.cfg.RUnlocks(config.EEsJson)
|
||||
|
||||
@@ -701,3 +701,13 @@ func TestSIPURIConverter(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestNewDataConverterMustCompile2(t *testing.T) {
|
||||
defer func() {
|
||||
expectedMessage := "parsing: <*multiply>, error: mandatory information missing"
|
||||
if r := recover(); r != expectedMessage {
|
||||
t.Errorf("Expected %q, received: %q", expectedMessage, r)
|
||||
}
|
||||
}()
|
||||
NewDataConverterMustCompile(MetaMultiply)
|
||||
}
|
||||
|
||||
@@ -214,7 +214,6 @@ func (ms MapStorage) GetKeys(nesteed bool) (keys []string) {
|
||||
for k := range ms {
|
||||
keys[i] = k
|
||||
i++
|
||||
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -67,19 +67,27 @@ func TestNavMapAdd2(t *testing.T) {
|
||||
nM := MapStorage{}
|
||||
path := []string{"FistLever2", "SecondLevel2", "Field2"}
|
||||
data := 123
|
||||
nM.Set(path, data)
|
||||
if err := nM.Set(path, data); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
path = []string{"FirstLevel", "SecondLevel", "ThirdLevel", "Fld1"}
|
||||
data1 := 123.123
|
||||
nM.Set(path, data1)
|
||||
if err := nM.Set(path, data1); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
path = []string{"FistLever2", "Field3"}
|
||||
data2 := "Value3"
|
||||
nM.Set(path, data2)
|
||||
if err := nM.Set(path, data2); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
path = []string{"Field4"}
|
||||
data3 := &testStruct{
|
||||
Item1: "Ten",
|
||||
Item2: 10,
|
||||
}
|
||||
nM.Set(path, data3)
|
||||
if err := nM.Set(path, data3); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
eNavMap := MapStorage{
|
||||
"FirstLevel": MapStorage{
|
||||
"SecondLevel": MapStorage{
|
||||
@@ -102,6 +110,30 @@ func TestNavMapAdd2(t *testing.T) {
|
||||
if !reflect.DeepEqual(nM, eNavMap) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eNavMap, nM)
|
||||
}
|
||||
|
||||
if err := nM.Set([]string{}, nil); err != ErrWrongPath {
|
||||
t.Errorf("Expected error: %s received: %v", ErrWrongPath, err)
|
||||
}
|
||||
|
||||
if err := nM.Set([]string{"Field4", "Field2"}, nil); err != ErrWrongPath {
|
||||
t.Errorf("Expected error: %s received: %v", ErrWrongPath, err)
|
||||
}
|
||||
|
||||
nM = MapStorage{"Field1": map[string]interface{}{}}
|
||||
path = []string{"Field1", "SecondLevel2", "Field2"}
|
||||
data = 123
|
||||
if err := nM.Set(path, data); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
eNavMap = MapStorage{"Field1": map[string]interface{}{
|
||||
"SecondLevel2": MapStorage{
|
||||
"Field2": 123,
|
||||
},
|
||||
}}
|
||||
if !reflect.DeepEqual(nM, eNavMap) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eNavMap, nM)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNavMapString(t *testing.T) {
|
||||
@@ -293,6 +325,19 @@ func TestNavMapGetKeys(t *testing.T) {
|
||||
if !reflect.DeepEqual(expKeys, keys) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", ToJSON(expKeys), ToJSON(keys))
|
||||
}
|
||||
|
||||
expKeys = []string{
|
||||
"FirstLevel",
|
||||
"FistLever2",
|
||||
"Field5",
|
||||
"Field6",
|
||||
}
|
||||
keys = navMp.GetKeys(false)
|
||||
sort.Strings(expKeys)
|
||||
sort.Strings(keys)
|
||||
if !reflect.DeepEqual(expKeys, keys) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", ToJSON(expKeys), ToJSON(keys))
|
||||
}
|
||||
}
|
||||
|
||||
func TestNavMapFieldAsInterface2(t *testing.T) {
|
||||
@@ -425,3 +470,53 @@ func TestNavMapGetField2(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNavMapRemove(t *testing.T) {
|
||||
nM := MapStorage{
|
||||
"Field4": &testStruct{
|
||||
Item1: "Ten",
|
||||
Item2: 10,
|
||||
},
|
||||
}
|
||||
|
||||
if err := nM.Remove([]string{}); err != ErrWrongPath {
|
||||
t.Errorf("Expected error: %s received: %v", ErrWrongPath, err)
|
||||
}
|
||||
|
||||
if err := nM.Remove([]string{"Field4", "Field2"}); err != ErrWrongPath {
|
||||
t.Errorf("Expected error: %s received: %v", ErrWrongPath, err)
|
||||
}
|
||||
nM = MapStorage{
|
||||
"Field1": map[string]interface{}{
|
||||
"SecondLevel2": 1,
|
||||
},
|
||||
}
|
||||
|
||||
path := []string{"Field1", "SecondLevel2"}
|
||||
if err := nM.Remove(path); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
eNavMap := MapStorage{"Field1": map[string]interface{}{}}
|
||||
if !reflect.DeepEqual(nM, eNavMap) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eNavMap, nM)
|
||||
}
|
||||
nM = MapStorage{"Field1": MapStorage{
|
||||
"SecondLevel2": 1,
|
||||
}}
|
||||
path = []string{"Field1", "SecondLevel2"}
|
||||
if err := nM.Remove(path); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
eNavMap = MapStorage{"Field1": MapStorage{}}
|
||||
if !reflect.DeepEqual(nM, eNavMap) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eNavMap, nM)
|
||||
}
|
||||
path = []string{"Field1", "SecondLevel2"}
|
||||
if err := nM.Remove(path); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
eNavMap = MapStorage{"Field1": MapStorage{}}
|
||||
if !reflect.DeepEqual(nM, eNavMap) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eNavMap, nM)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user