From 58e26a46ce3bb3326d507586e1ef2f0b84d536bd Mon Sep 17 00:00:00 2001 From: DanB Date: Mon, 18 Nov 2013 22:13:04 +0100 Subject: [PATCH] Adding RemTPData SQL tests --- engine/storage_interface.go | 2 +- engine/storage_sql_test.go | 68 +++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/engine/storage_interface.go b/engine/storage_interface.go index fc7896599..14089bce6 100644 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -100,11 +100,11 @@ type LogStorage interface { type LoadStorage interface { Storage // Apier functions + RemTPData(string, string, ...string) error GetTPIds() ([]string, error) SetTPTiming(string, *utils.TPTiming) error GetTPTiming(string, string) (*utils.TPTiming, error) GetTPTimingIds(string) ([]string, error) - RemTPData(string, string, ...string) error SetTPDestination(string, *Destination) error GetTPDestination(string, string) (*Destination, error) GetTPDestinationIds(string) ([]string, error) diff --git a/engine/storage_sql_test.go b/engine/storage_sql_test.go index d6187a5e8..b927b5cba 100644 --- a/engine/storage_sql_test.go +++ b/engine/storage_sql_test.go @@ -45,6 +45,7 @@ const ( CREATE_COSTDETAILS_TABLES_SQL = "create_costdetails_tables.sql" CREATE_MEDIATOR_TABLES_SQL = "create_mediator_tables.sql" CREATE_TARIFFPLAN_TABLES_SQL = "create_tariffplan_tables.sql" + TEST_SQL = "TEST_SQL" ) var db *MySQLStorage @@ -75,6 +76,73 @@ func TestCreateTables(t *testing.T) { } } } + +func TestRemoveData(t *testing.T) { + if !*testLocal { + return + } + // Create Timings + tm := &utils.TPTiming{Id:"ALWAYS", StartTime:"00:00:00"} + if err := db.SetTPTiming(TEST_SQL,tm); err != nil { + t.Error(err.Error()) + } + if tmgs, err := db.GetTpTimings(TEST_SQL, tm.Id); err != nil { + t.Error(err.Error()) + } else if len(tmgs) == 0 { + t.Error("Could not store TPTiming") + } + // Remove Timings + if err := db.RemTPData(utils.TBL_TP_TIMINGS, TEST_SQL, tm.Id); err != nil { + t.Error(err.Error()) + } + if tmgs, err := db.GetTpTimings(TEST_SQL, tm.Id); err != nil { + t.Error(err.Error()) + } else if len(tmgs) != 0 { + t.Error("Did not remove TPTiming") + } + // Create RatingProfile + ras := []*utils.TPRatingActivation{&utils.TPRatingActivation{ActivationTime: "2012-01-01T00:00:00Z", RatingPlanId:"RETAIL1"}} + rp := &utils.TPRatingProfile{TPid:TEST_SQL, LoadId:TEST_SQL, Tenant:"cgrates.org", TOR:"call", Direction:"*out", Subject:"*any", RatingPlanActivations:ras} + if err := db.SetTPRatingProfiles(TEST_SQL, map[string]*utils.TPRatingProfile{rp.KeyId():rp}); err != nil { + t.Error(err.Error()) + } + if rps, err := db.GetTpRatingProfiles(rp); err != nil { + t.Error(err.Error()) + } else if len(rps) == 0{ + t.Error("Could not store TPRatingProfile") + } + // Remove RatingProfile + if err := db.RemTPData(utils.TBL_TP_RATE_PROFILES, rp.TPid, rp.LoadId, rp.Tenant, rp.TOR, rp.Direction, rp.Subject); err != nil { + t.Error(err.Error()) + } + if rps, err := db.GetTpRatingProfiles(rp); err != nil { + t.Error(err.Error()) + } else if len(rps) != 0{ + t.Error("Did not remove TPRatingProfile") + } + + // Create AccountActions + aa := &utils.TPAccountActions{TPid:TEST_SQL, LoadId:TEST_SQL, Tenant:"cgrates.org", Account:"1001", + Direction:"*out", ActionTimingsId:"PREPAID_10", ActionTriggersId:"STANDARD_TRIGGERS"} + if err := db.SetTPAccountActions(aa.TPid, map[string]*utils.TPAccountActions{aa.KeyId(): aa}); err != nil { + t.Error(err.Error()) + } + if aas, err := db.GetTpAccountActions(aa); err != nil { + t.Error(err.Error()) + } else if len(aas) == 0 { + t.Error("Could not create TPAccountActions") + } + // Remove AccountActions + if err := db.RemTPData(utils.TBL_TP_ACCOUNT_ACTIONS, aa.TPid, aa.LoadId, aa.Tenant, aa.Account, aa.Direction); err != nil { + t.Error(err.Error()) + } + if aas, err := db.GetTpAccountActions(aa); err != nil { + t.Error(err.Error()) + } else if len(aas) != 0 { + t.Error("Did not remove TPAccountActions") + } +} +