From 477af9467f049279d5880741a675f901de7e03a2 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 25 Feb 2014 20:28:58 +0200 Subject: [PATCH] added load test for shared groups --- engine/action.go | 1 - engine/loader_csv.go | 2 +- engine/loader_csv_test.go | 72 ++++++++++++++++++++++++++++++++++----- 3 files changed, 65 insertions(+), 10 deletions(-) diff --git a/engine/action.go b/engine/action.go index 7e4fc5b1b..95d54f5cf 100644 --- a/engine/action.go +++ b/engine/action.go @@ -45,7 +45,6 @@ type Action struct { ExpirationString string Weight float64 Balance *Balance - SharedGroup string } const ( diff --git a/engine/loader_csv.go b/engine/loader_csv.go index ec2a3783a..09f488006 100644 --- a/engine/loader_csv.go +++ b/engine/loader_csv.go @@ -537,8 +537,8 @@ func (csvr *CSVReader) LoadActions() (err error) { Weight: balanceWeight, DestinationId: record[6], RateSubject: record[7], + SharedGroup: record[9], }, - SharedGroup: record[9], } if _, err := utils.ParseDate(a.ExpirationString); err != nil { return errors.New(fmt.Sprintf("Could not parse expiration time: %v", err)) diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index cc4ce8a9d..c39536cd5 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -111,14 +111,18 @@ vdf,0,*out,fallback1,2013-11-18T13:47:00Z,G,fallback2 vdf,0,*out,fallback2,2013-11-18T13:45:00Z,R,rif ` sharedGroups = ` +SG1,*any,*lowest_first,, +SG2,*any,*lowest_first,EVENING, ` actions = ` MINI,*topup_reset,*monetary,*out,10,*unlimited,,,10,,,10 MINI,*topup,*minutes,*out,100,*unlimited,NAT,test,10,,,10 +SHARED,*topup,*monetary,*out,100,*unlimited,,,10,SG1,,10 ` actionTimings = ` MORE_MINUTES,MINI,ONE_TIME_RUN,10 +MORE_MINUTES,SHARED,ONE_TIME_RUN,10 ` actionTriggers = ` STANDARD_TRIGGER,*minutes,*out,*min_counter,10,GERMANY_O2,SOME_1,10 @@ -568,13 +572,13 @@ func TestLoadRatingProfiles(t *testing.T) { } func TestLoadActions(t *testing.T) { - if len(csvr.actions) != 1 { + if len(csvr.actions) != 2 { t.Error("Failed to load actions: ", csvr.actions) } - as := csvr.actions["MINI"] + as1 := csvr.actions["MINI"] expected := []*Action{ &Action{ - Id: as[0].Id, + Id: as1[0].Id, ActionType: TOPUP_RESET, BalanceType: CREDIT, Direction: OUTBOUND, @@ -582,13 +586,13 @@ func TestLoadActions(t *testing.T) { ExtraParameters: "", Weight: 10, Balance: &Balance{ - Uuid: as[0].Balance.Uuid, + Uuid: as1[0].Balance.Uuid, Value: 10, Weight: 10, }, }, &Action{ - Id: as[1].Id, + Id: as1[1].Id, ActionType: TOPUP, BalanceType: MINUTES, Direction: OUTBOUND, @@ -596,7 +600,7 @@ func TestLoadActions(t *testing.T) { ExtraParameters: "", Weight: 10, Balance: &Balance{ - Uuid: as[1].Balance.Uuid, + Uuid: as1[1].Balance.Uuid, Value: 100, Weight: 10, RateSubject: "test", @@ -604,8 +608,60 @@ func TestLoadActions(t *testing.T) { }, }, } - if !reflect.DeepEqual(as, expected) { - t.Error("Error loading action: ", as) + if !reflect.DeepEqual(as1, expected) { + t.Error("Error loading action: ", as1) + } + as2 := csvr.actions["SHARED"] + expected = []*Action{ + &Action{ + Id: as2[0].Id, + ActionType: TOPUP, + BalanceType: CREDIT, + Direction: OUTBOUND, + ExpirationString: UNLIMITED, + Weight: 10, + Balance: &Balance{ + Uuid: as2[0].Balance.Uuid, + Value: 100, + Weight: 10, + SharedGroup: "SG1", + }, + }, + } + if !reflect.DeepEqual(as2, expected) { + t.Errorf("Error loading action: %+v", as2[0].Balance) + } +} + +func TestSharedGroups(t *testing.T) { + if len(csvr.sharedGroups) != 2 { + t.Error("Failed to load actions: ", csvr.sharedGroups) + } + sg1 := csvr.sharedGroups["SG1"] + expected := &SharedGroup{ + Id: "SG1", + AccountParameters: map[string]*SharingParameters{ + "*any": &SharingParameters{ + Strategy: "*lowest_first", + RateSubject: "", + }, + }, + } + if !reflect.DeepEqual(sg1, expected) { + t.Error("Error loading shared group: ", sg1.AccountParameters) + } + sg2 := csvr.sharedGroups["SG2"] + expected = &SharedGroup{ + Id: "SG2", + AccountParameters: map[string]*SharingParameters{ + "*any": &SharingParameters{ + Strategy: "*lowest_first", + RateSubject: "EVENING", + }, + }, + } + if !reflect.DeepEqual(sg2, expected) { + t.Error("Error loading shared group: ", sg2.AccountParameters) } }