From dd89c5060de2fcacb768e8fc5f147f17f12e620a Mon Sep 17 00:00:00 2001 From: edwardro22 Date: Tue, 19 Dec 2017 12:47:23 +0200 Subject: [PATCH] Fixed merge conflicts --- engine/attributes_test.go | 111 +++++++++++++++++++------------------- engine/suppliers_test.go | 24 ++++----- 2 files changed, 66 insertions(+), 69 deletions(-) diff --git a/engine/attributes_test.go b/engine/attributes_test.go index f37f74909..e467e711c 100644 --- a/engine/attributes_test.go +++ b/engine/attributes_test.go @@ -1,3 +1,4 @@ + /* Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments Copyright (C) ITsysCOM GmbH @@ -22,14 +23,14 @@ import ( "testing" "time" - "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" + "github.com/cgrates/cgrates/config" ) var ( - atrPs AttributeProfiles - srv AttributeService - dmAtr *DataManager + atrPs AttributeProfiles + srv AttributeService + dmAtr *DataManager ) var sTestsAttributes = []func(t *testing.T){ @@ -37,14 +38,13 @@ var sTestsAttributes = []func(t *testing.T){ testAttributeMatchingAttributeProfilesForEvent, testAttributeProfileForEvent, testAttributeProcessEvent, -} + } func TestAttributes(t *testing.T) { for _, stest := range sTestsAttributes { t.Run("Test Suppliers", stest) } } - //.matchingAttributeProfilesForEvent //.attributeProfileForEvent //.processEvent @@ -55,7 +55,7 @@ func testPopulateAttrService(t *testing.T) { second := 1 * time.Second data, _ := NewMapStorage() dmAtr = NewDataManager(data) - context := utils.MetaRating + context :=utils.MetaRating attrMap := make(map[string]map[string]*Attribute) attrMap["FL1"] = make(map[string]*Attribute) attrMap["FL1"]["In1"] = &Attribute{ @@ -65,33 +65,33 @@ func testPopulateAttrService(t *testing.T) { Append: true, } - atrPs = AttributeProfiles{ - &AttributeProfile{ - Tenant: "cgrates.org", - ID: "attributeprofile1", - Context: context, - FilterIDs: []string{"filter1"}, - ActivationInterval: &utils.ActivationInterval{ + atrPs= AttributeProfiles{ + &AttributeProfile{ + Tenant: "cgrates.org", + ID: "attributeprofile1", + Context: context, + FilterIDs: []string{"filter1"}, + ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC).Local(), ExpiryTime: time.Now().Add(time.Duration(20 * time.Minute)).Local(), }, - Attributes: attrMap, - Weight: 20, + Attributes: attrMap, + Weight: 20, }, - &AttributeProfile{ - Tenant: "cgrates.org", - ID: "attributeprofile2", - Context: context, - FilterIDs: []string{"filter2"}, - ActivationInterval: &utils.ActivationInterval{ + &AttributeProfile{ + Tenant: "cgrates.org", + ID: "attributeprofile2", + Context: context, + FilterIDs: []string{"filter2"}, + ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC).Local(), ExpiryTime: time.Now().Add(time.Duration(20 * time.Minute)).Local(), }, - Attributes: attrMap, - Weight: 20, + Attributes: attrMap, + Weight: 20, }, } - + x, err := NewRequestFilter(MetaString, "attributeprofile1", []string{"Attribute"}) if err != nil { t.Errorf("Error: %+v", err) @@ -117,8 +117,8 @@ func testPopulateAttrService(t *testing.T) { filter2 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "filter2", RequestFilters: filters2} dmAtr.SetFilter(filter1) dmAtr.SetFilter(filter2) - srv = AttributeService{ - dm: dmAtr, + srv= AttributeService{ + dm:dmAtr, filterS: &FilterS{dm: dmAtr}, indexedFields: []string{"attributeprofile1", "attributeprofile2"}, } @@ -130,86 +130,83 @@ func testPopulateAttrService(t *testing.T) { ev["PddInterval"] = "1s" ev["Weight"] = "20.0" sev = &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "attribute_event", - Context: &context, - Event: ev, + Tenant: "cgrates.org", + ID: "attribute_event", + Context:&context, + Event: ev, } for _, atr := range atrPs { - dmAtr.SetAttributeProfile(atr) + dmAtr.SetAttributeProfile(atr) } prefix := utils.ConcatenatedKey(sev.Tenant, *sev.Context) - ref, err := NewReqFilterIndexer(dmAtr, utils.AttributeProfilePrefix, prefix) - if err != nil { - t.Errorf("Error: %+v", err) - } - ref.IndexFilters("attributeprofile1", filters1) - ref.IndexFilters("attributeprofile2", filters2) - err = ref.StoreIndexes() + ref := NewReqFilterIndexer(dmAtr, utils.AttributeProfilePrefix,prefix) + ref.IndexFilters("attributeprofile1", filter1) + ref.IndexFilters("attributeprofile2", filter2) + err = ref.StoreIndexes(true) if err != nil { t.Errorf("Error: %+v", err) } } func testAttributeMatchingAttributeProfilesForEvent(t *testing.T) { - atrpl, err := srv.matchingAttributeProfilesForEvent(sev) + atrpl,err:=srv.matchingAttributeProfilesForEvent(sev) if err != nil { t.Errorf("Error: %+v", err) } - if !reflect.DeepEqual(atrPs[0], atrpl[0]) && !reflect.DeepEqual(atrPs[0], atrpl[1]) { + if !reflect.DeepEqual(atrPs[0], atrpl[0])&&!reflect.DeepEqual(atrPs[0], atrpl[1]) { t.Errorf("Expecting: %+v, received: %+v", atrPs[0], atrpl[0]) - } else if !reflect.DeepEqual(atrPs[1], atrpl[1]) && !reflect.DeepEqual(atrPs[1], atrpl[0]) { + } else if !reflect.DeepEqual(atrPs[1], atrpl[1])&&!reflect.DeepEqual(atrPs[1], atrpl[0]) { t.Errorf("Expecting: %+v, received: %+v", atrPs[1], atrpl[1]) } } func testAttributeProfileForEvent(t *testing.T) { - context := utils.MetaRating + context:=utils.MetaRating ev := make(map[string]interface{}) ev["attributeprofile1"] = "Attribute" ev["UsageInterval"] = "1s" ev["Weight"] = "9.0" sev = &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "attribute_event", + Tenant: "cgrates.org", + ID: "attribute_event", Context: &context, - Event: ev, + Event: ev, } - atrpl, err := srv.attributeProfileForEvent(sev) + atrpl,err:=srv.attributeProfileForEvent(sev) if err != nil { t.Errorf("Error: %+v", err) } - if !reflect.DeepEqual(atrPs[0], atrpl) && !reflect.DeepEqual(atrPs[1], atrpl) { + if !reflect.DeepEqual(atrPs[0], atrpl)&&!reflect.DeepEqual(atrPs[1], atrpl) { t.Errorf("Expecting: %+v, received: %+v", atrPs[0], atrpl) } } func testAttributeProcessEvent(t *testing.T) { - context := utils.MetaRating +context:=utils.MetaRating ev := make(map[string]interface{}) ev["attributeprofile1"] = "Attribute" ev["UsageInterval"] = "1s" ev["Weight"] = "9.0" sev = &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "attribute_event", + Tenant: "cgrates.org", + ID: "attribute_event", Context: &context, - Event: ev, + Event: ev, } eRply := &AttrSProcessEventReply{ MatchedProfile: "attributeprofile1", - CGREvent: sev, + CGREvent: sev, } - atrpl, err := srv.processEvent(sev) + atrpl,err:=srv.processEvent(sev) if err != nil { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfile, atrpl.MatchedProfile) { t.Errorf("Expecting: %+v, received: %+v", eRply.MatchedProfile, atrpl.MatchedProfile) - } else if !reflect.DeepEqual(eRply.AlteredFields, atrpl.AlteredFields) { + }else if !reflect.DeepEqual(eRply.AlteredFields, atrpl.AlteredFields) { t.Errorf("Expecting: %+v, received: %+v", eRply.AlteredFields, atrpl.AlteredFields) - } else if !reflect.DeepEqual(eRply.CGREvent, atrpl.CGREvent) { + }else if !reflect.DeepEqual(eRply.CGREvent, atrpl.CGREvent) { t.Errorf("Expecting: %+v, received: %+v", eRply.CGREvent, atrpl.CGREvent) } -} +} \ No newline at end of file diff --git a/engine/suppliers_test.go b/engine/suppliers_test.go index 7d4ca0fbc..a3aaaf9b1 100644 --- a/engine/suppliers_test.go +++ b/engine/suppliers_test.go @@ -176,10 +176,10 @@ func TestSuppliersPopulateSupplierService(t *testing.T) { t.Errorf("Error: %+v", err) } filters2 = append(filters2, x) - filter1 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "filter1", RequestFilters: filters1} - filter2 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "filter2", RequestFilters: filters2} - dmspl.SetFilter(filter1) - dmspl.SetFilter(filter2) + filter3 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "filter3", RequestFilters: filters1} + filter4 := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "filter4", RequestFilters: filters2} + dmspl.SetFilter(filter3) + dmspl.SetFilter(filter4) ssd := make(map[string]SuppliersSorter) ssd[utils.MetaWeight] = NewWeightSorter() splserv = SupplierService{ @@ -205,7 +205,7 @@ func TestSuppliersPopulateSupplierService(t *testing.T) { &SupplierProfile{ Tenant: "cgrates.org", ID: "supplierprofile1", - FilterIDs: []string{"filter1"}, + FilterIDs: []string{"filter3"}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC).Local(), ExpiryTime: time.Now().Add(time.Duration(20 * time.Minute)).Local(), @@ -215,7 +215,7 @@ func TestSuppliersPopulateSupplierService(t *testing.T) { Suppliers: []*Supplier{ &Supplier{ ID: "supplier1", - FilterIDs: []string{"filter1"}, + FilterIDs: []string{"filter3"}, AccountIDs: []string{}, RatingPlanIDs: []string{}, ResourceIDs: []string{}, @@ -229,7 +229,7 @@ func TestSuppliersPopulateSupplierService(t *testing.T) { &SupplierProfile{ Tenant: "cgrates.org", ID: "supplierprofile2", - FilterIDs: []string{"filter2"}, + FilterIDs: []string{"filter4"}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC).Local(), ExpiryTime: time.Now().Add(time.Duration(20 * time.Minute)).Local(), @@ -239,7 +239,7 @@ func TestSuppliersPopulateSupplierService(t *testing.T) { Suppliers: []*Supplier{ &Supplier{ ID: "supplier2", - FilterIDs: []string{"filter2"}, + FilterIDs: []string{"filter4"}, AccountIDs: []string{}, RatingPlanIDs: []string{}, ResourceIDs: []string{}, @@ -248,7 +248,7 @@ func TestSuppliersPopulateSupplierService(t *testing.T) { }, &Supplier{ ID: "supplier3", - FilterIDs: []string{"filter2"}, + FilterIDs: []string{"filter4"}, AccountIDs: []string{}, RatingPlanIDs: []string{}, ResourceIDs: []string{}, @@ -257,7 +257,7 @@ func TestSuppliersPopulateSupplierService(t *testing.T) { }, &Supplier{ ID: "supplier1", - FilterIDs: []string{"filter2"}, + FilterIDs: []string{"filter4"}, AccountIDs: []string{}, RatingPlanIDs: []string{}, ResourceIDs: []string{}, @@ -273,8 +273,8 @@ func TestSuppliersPopulateSupplierService(t *testing.T) { dmspl.DataDB().SetSupplierProfileDrv(spr) } ref := NewReqFilterIndexer(dmspl, utils.SupplierProfilePrefix, "cgrates.org") - ref.IndexFilters("supplierprofile1", filter1) - ref.IndexFilters("supplierprofile2", filter2) + ref.IndexFilters("supplierprofile1", filter3) + ref.IndexFilters("supplierprofile2", filter4) err = ref.StoreIndexes(false) if err != nil { t.Errorf("Error: %+v", err)