From 65ee8a11310aa943d535fb99a5bc824dc6291b1c Mon Sep 17 00:00:00 2001 From: DanB Date: Thu, 10 Nov 2016 18:30:12 +0100 Subject: [PATCH] Fix Diameter config loading which was doubling processor, thanks @Edwardro22 --- config/config_test.go | 11 +++++------ config/daconfig.go | 6 +++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/config/config_test.go b/config/config_test.go index 7b19d3c49..4ba981604 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -332,12 +332,12 @@ func TestCgrCfgJSONDefaultsCDRS(t *testing.T) { eHaPoolCfg := []*HaPoolConfig{} eCDRReCfg := []*CDRReplicationCfg{} iHaPoolCfg := []*HaPoolConfig{&HaPoolConfig{Address: "*internal"}} - eCdrExtr := []string{} + var eCdrExtr []*utils.RSRField if cgrCfg.CDRSEnabled != false { t.Error(cgrCfg.CDRSEnabled) } - if !reflect.DeepEqual(cgrCfg.CDRSExtraFields, eCdrExtr) { + if !reflect.DeepEqual(eCdrExtr, cgrCfg.CDRSExtraFields) { t.Errorf(" expecting: %+v, received: %+v", eCdrExtr, cgrCfg.CDRSExtraFields) } if cgrCfg.CDRSStoreCdrs != true { @@ -429,7 +429,7 @@ func TestCgrCfgJSONDefaultsSMGenericCfg(t *testing.T) { MinCallDuration: 0 * time.Second, MaxCallDuration: 3 * time.Hour, SessionTTL: 0 * time.Second, - SessionIndexes: []string{}, + SessionIndexes: utils.StringMap{}, } if !reflect.DeepEqual(cgrCfg.SmGenericConfig, eSmGeCfg) { @@ -582,7 +582,7 @@ func TestCgrCfgJSONDefaultsDiameterAgentCfg(t *testing.T) { &CfgCdrField{Tag: "Destination", FieldId: "Destination", Type: "*composed", Value: utils.ParseRSRFieldsMustCompile("Service-Information>IN-Information>Real-Called-Number", utils.INFIELD_SEP), Mandatory: true}, &CfgCdrField{Tag: "SetupTime", FieldId: "SetupTime", Type: "*composed", Value: utils.ParseRSRFieldsMustCompile("Event-Timestamp", utils.INFIELD_SEP), Mandatory: true}, &CfgCdrField{Tag: "AnswerTime", FieldId: "AnswerTime", Type: "*composed", Value: utils.ParseRSRFieldsMustCompile("Event-Timestamp", utils.INFIELD_SEP), Mandatory: true}, - &CfgCdrField{Tag: "Usage", FieldId: "Usage", Type: "*handler", HandlerId: "*ccr_usage"}, + &CfgCdrField{Tag: "Usage", FieldId: "Usage", Type: "*handler", HandlerId: "*ccr_usage", Mandatory: true}, &CfgCdrField{Tag: "SubscriberID", FieldId: "SubscriberId", Type: "*composed", Value: utils.ParseRSRFieldsMustCompile("Subscription-Id>Subscription-Id-Data", utils.INFIELD_SEP), Mandatory: true}, }, CCAFields: []*CfgCdrField{ @@ -642,9 +642,8 @@ func TestCgrCfgJSONDefaultsDiameterAgentCfg(t *testing.T) { if !reflect.DeepEqual(cgrCfg.diameterAgentCfg.ProductName, testDA.ProductName) { t.Errorf("received: %+v, expecting: %+v", cgrCfg.diameterAgentCfg.ProductName, testDA.ProductName) } - if !reflect.DeepEqual(cgrCfg.diameterAgentCfg.RequestProcessors, testDA.RequestProcessors) { - t.Errorf("received: %+v, expecting: %+v", cgrCfg.diameterAgentCfg.RequestProcessors, testDA.RequestProcessors) + t.Errorf("expecting: %+v, received: %+v", testDA.RequestProcessors, cgrCfg.diameterAgentCfg.RequestProcessors) } } diff --git a/config/daconfig.go b/config/daconfig.go index bafaab0f6..329150371 100644 --- a/config/daconfig.go +++ b/config/daconfig.go @@ -97,16 +97,20 @@ func (self *DiameterAgentCfg) loadFromJsonCfg(jsnCfg *DiameterAgentJsonCfg) erro if jsnCfg.Request_processors != nil { for _, reqProcJsn := range *jsnCfg.Request_processors { rp := new(DARequestProcessor) + var haveID bool for _, rpSet := range self.RequestProcessors { if reqProcJsn.Id != nil && rpSet.Id == *reqProcJsn.Id { rp = rpSet // Will load data into the one set + haveID = true break } } if err := rp.loadFromJsonCfg(reqProcJsn); err != nil { return nil } - self.RequestProcessors = append(self.RequestProcessors, rp) + if !haveID { + self.RequestProcessors = append(self.RequestProcessors, rp) + } } } return nil