diff --git a/data/storage/mysql/create_cdrs_tables.sql b/data/storage/mysql/create_cdrs_tables.sql index 6a77260b1..54346c2a4 100644 --- a/data/storage/mysql/create_cdrs_tables.sql +++ b/data/storage/mysql/create_cdrs_tables.sql @@ -50,7 +50,7 @@ CREATE TABLE sm_costs ( created_at TIMESTAMP NULL, deleted_at TIMESTAMP NULL, PRIMARY KEY (`id`), - UNIQUE KEY costid (cgrid,run_id), + UNIQUE KEY costid (cgrid, run_id), KEY origin_idx (origin_host, origin_id), KEY deleted_at_idx (deleted_at) ); diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index b4cff66dd..8b12c4e60 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -402,7 +402,7 @@ CREATE TABLE tp_resource_limits ( `activation_time` varchar(24) NOT NULL, `weight` decimal(8,2) NOT NULL, `limit` varchar(64) NOT NULL, - `action_triggers` varchar(64) NOT NULL, + `action_trigger_ids` varchar(64) NOT NULL, `created_at` TIMESTAMP, PRIMARY KEY (`id`), KEY `tpid` (`tpid`), diff --git a/data/storage/postgres/create_cdrs_tables.sql b/data/storage/postgres/create_cdrs_tables.sql index 4ced7df21..264ed84fd 100644 --- a/data/storage/postgres/create_cdrs_tables.sql +++ b/data/storage/postgres/create_cdrs_tables.sql @@ -18,21 +18,21 @@ CREATE TABLE cdrs ( account VARCHAR(128) NOT NULL, subject VARCHAR(128) NOT NULL, destination VARCHAR(128) NOT NULL, - setup_time TIMESTAMP NOT NULL, + setup_time TIMESTAMP WITH TIME ZONE NOT NULL, pdd NUMERIC(12,9) NOT NULL, - answer_time TIMESTAMP NOT NULL, + answer_time TIMESTAMP WITH TIME ZONE NOT NULL, usage NUMERIC(30,9) NOT NULL, supplier VARCHAR(128) NOT NULL, disconnect_cause VARCHAR(64) NOT NULL, - extra_fields jsonb, + extra_fields jsonb NOT NULL, cost_source VARCHAR(64) NOT NULL, cost NUMERIC(20,4) DEFAULT NULL, cost_details jsonb, account_summary jsonb, extra_info text, - created_at TIMESTAMP, - updated_at TIMESTAMP NULL, - deleted_at TIMESTAMP NULL, + created_at TIMESTAMP WITH TIME ZONE, + updated_at TIMESTAMP WITH TIME ZONE NULL, + deleted_at TIMESTAMP WITH TIME ZONE NULL, UNIQUE (cgrid, run_id, origin_id) ); ; @@ -50,8 +50,8 @@ CREATE TABLE sm_costs ( cost_source VARCHAR(64) NOT NULL, usage NUMERIC(30,9) NOT NULL, cost_details jsonb, - created_at TIMESTAMP, - deleted_at TIMESTAMP NULL, + created_at TIMESTAMP WITH TIME ZONE, + deleted_at TIMESTAMP WITH TIME ZONE NULL, UNIQUE (cgrid, run_id) ); DROP INDEX IF EXISTS cgrid_smcost_idx; diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index 04ea57b87..b4192d1cc 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -11,7 +11,7 @@ CREATE TABLE tp_timings ( month_days VARCHAR(255) NOT NULL, week_days VARCHAR(255) NOT NULL, time VARCHAR(32) NOT NULL, - created_at TIMESTAMP, + created_at TIMESTAMP WITH TIME ZONE, UNIQUE (tpid, tag) ); CREATE INDEX tptimings_tpid_idx ON tp_timings (tpid); @@ -27,7 +27,7 @@ CREATE TABLE tp_destinations ( tpid VARCHAR(64) NOT NULL, tag VARCHAR(64) NOT NULL, prefix VARCHAR(24) NOT NULL, - created_at TIMESTAMP, + created_at TIMESTAMP WITH TIME ZONE, UNIQUE (tpid, tag, prefix) ); CREATE INDEX tpdests_tpid_idx ON tp_destinations (tpid); @@ -47,7 +47,7 @@ CREATE TABLE tp_rates ( rate_unit VARCHAR(16) NOT NULL, rate_increment VARCHAR(16) NOT NULL, group_interval_start VARCHAR(16) NOT NULL, - created_at TIMESTAMP, + created_at TIMESTAMP WITH TIME ZONE, UNIQUE (tpid, tag, group_interval_start) ); CREATE INDEX tprates_tpid_idx ON tp_rates (tpid); @@ -68,7 +68,7 @@ CREATE TABLE tp_destination_rates ( rounding_decimals SMALLINT NOT NULL, max_cost NUMERIC(7,4) NOT NULL, max_cost_strategy VARCHAR(16) NOT NULL, - created_at TIMESTAMP, + created_at TIMESTAMP WITH TIME ZONE, UNIQUE (tpid, tag , destinations_tag) ); CREATE INDEX tpdestrates_tpid_idx ON tp_destination_rates (tpid); @@ -86,7 +86,7 @@ CREATE TABLE tp_rating_plans ( destrates_tag VARCHAR(64) NOT NULL, timing_tag VARCHAR(64) NOT NULL, weight NUMERIC(8,2) NOT NULL, - created_at TIMESTAMP, + created_at TIMESTAMP WITH TIME ZONE, UNIQUE (tpid, tag, destrates_tag, timing_tag) ); CREATE INDEX tpratingplans_tpid_idx ON tp_rating_plans (tpid); @@ -110,7 +110,7 @@ CREATE TABLE tp_rating_profiles ( rating_plan_tag VARCHAR(64) NOT NULL, fallback_subjects VARCHAR(64), cdr_stat_queue_ids VARCHAR(64), - created_at TIMESTAMP, + created_at TIMESTAMP WITH TIME ZONE, UNIQUE (tpid, loadid, tenant, category, direction, subject, activation_time) ); CREATE INDEX tpratingprofiles_tpid_idx ON tp_rating_profiles (tpid); @@ -128,7 +128,7 @@ CREATE TABLE tp_shared_groups ( account VARCHAR(64) NOT NULL, strategy VARCHAR(24) NOT NULL, rating_subject VARCHAR(24) NOT NULL, - created_at TIMESTAMP, + created_at TIMESTAMP WITH TIME ZONE, UNIQUE (tpid, tag, account , strategy , rating_subject) ); CREATE INDEX tpsharedgroups_tpid_idx ON tp_shared_groups (tpid); @@ -160,7 +160,7 @@ CREATE TABLE tp_actions ( extra_parameters VARCHAR(256) NOT NULL, filter VARCHAR(256) NOT NULL, weight NUMERIC(8,2) NOT NULL, - created_at TIMESTAMP, + created_at TIMESTAMP WITH TIME ZONE, UNIQUE (tpid, tag, action, balance_tag, balance_type, directions, expiry_time, timing_tags, destination_tags, shared_groups, balance_weight, weight) ); CREATE INDEX tpactions_tpid_idx ON tp_actions (tpid); @@ -178,7 +178,7 @@ CREATE TABLE tp_action_plans ( actions_tag VARCHAR(64) NOT NULL, timing_tag VARCHAR(64) NOT NULL, weight NUMERIC(8,2) NOT NULL, - created_at TIMESTAMP, + created_at TIMESTAMP WITH TIME ZONE, UNIQUE (tpid, tag, actions_tag) ); CREATE INDEX tpactionplans_tpid_idx ON tp_action_plans (tpid); @@ -215,7 +215,7 @@ CREATE TABLE tp_action_triggers ( min_queued_items INTEGER NOT NULL, actions_tag VARCHAR(64) NOT NULL, weight NUMERIC(8,2) NOT NULL, - created_at TIMESTAMP, + created_at TIMESTAMP WITH TIME ZONE, UNIQUE (tpid, tag, balance_tag, balance_type, balance_directions, threshold_type, threshold_value, balance_destination_tags, actions_tag) ); CREATE INDEX tpactiontrigers_tpid_idx ON tp_action_triggers (tpid); @@ -236,7 +236,7 @@ CREATE TABLE tp_account_actions ( action_triggers_tag VARCHAR(64), allow_negative BOOLEAN NOT NULL, disabled BOOLEAN NOT NULL, - created_at TIMESTAMP, + created_at TIMESTAMP WITH TIME ZONE, UNIQUE (tpid, loadid, tenant, account) ); CREATE INDEX tpaccountactions_tpid_idx ON tp_account_actions (tpid); @@ -261,7 +261,7 @@ CREATE TABLE tp_lcr_rules ( strategy_params VARCHAR(256) NOT NULL, activation_time VARCHAR(24) NOT NULL, weight NUMERIC(8,2) NOT NULL, - created_at TIMESTAMP + created_at TIMESTAMP WITH TIME ZONE ); CREATE INDEX tplcr_tpid_idx ON tp_lcr_rules (tpid); CREATE INDEX tplcr_idx ON tp_lcr_rules (tpid,tenant,category,direction,account,subject,destination_tag); @@ -298,7 +298,7 @@ CREATE TABLE tp_derived_chargers ( disconnect_cause_field VARCHAR(64) NOT NULL, rated_field VARCHAR(64) NOT NULL, cost_field VARCHAR(64) NOT NULL, - created_at TIMESTAMP + created_at TIMESTAMP WITH TIME ZONE ); CREATE INDEX tpderivedchargers_tpid_idx ON tp_derived_chargers (tpid); CREATE INDEX tpderivedchargers_idx ON tp_derived_chargers (tpid,loadid,direction,tenant,category,account,subject); @@ -337,7 +337,7 @@ CREATE TABLE tp_cdr_stats ( rated_subjects VARCHAR(64) NOT NULL, cost_interval VARCHAR(24) NOT NULL, action_triggers VARCHAR(64) NOT NULL, - created_at TIMESTAMP + created_at TIMESTAMP WITH TIME ZONE ); CREATE INDEX tpcdrstats_tpid_idx ON tp_cdr_stats (tpid); CREATE INDEX tpcdrstats_idx ON tp_cdr_stats (tpid,tag); @@ -356,7 +356,7 @@ CREATE TABLE tp_users ( attribute_name VARCHAR(64) NOT NULL, attribute_value VARCHAR(64) NOT NULL, weight NUMERIC(8,2) NOT NULL, - created_at TIMESTAMP + created_at TIMESTAMP WITH TIME ZONE ); CREATE INDEX tpusers_tpid_idx ON tp_users (tpid); CREATE INDEX tpusers_idx ON tp_users (tpid,tenant,user_name); @@ -381,7 +381,7 @@ CREATE TABLE tp_aliases ( "original" varchar(64) NOT NULL, "alias" varchar(64) NOT NULL, "weight" NUMERIC(8,2) NOT NULL, - "created_at" TIMESTAMP + "created_at" TIMESTAMP WITH TIME ZONE ); CREATE INDEX tpaliases_tpid_idx ON tp_aliases (tpid); CREATE INDEX tpaliases_idx ON tp_aliases ("tpid","direction","tenant","category","account","subject","context","target"); @@ -397,9 +397,19 @@ CREATE TABLE tp_resource_limits ( "activation_time" varchar(24) NOT NULL, "weight" decimal(8,2) NOT NULL, "limit" varchar(64) NOT NULL, - "action_triggers" varchar(64) NOT NULL, - "created_at" TIMESTAMP + "action_trigger_ids" varchar(64) NOT NULL, + "created_at" TIMESTAMP WITH TIME ZONE ); CREATE INDEX tp_resource_limits_idx ON tp_resource_limits (tpid); CREATE INDEX tp_resource_limits_unique ON tp_resource_limits ("tpid", "tag"); +DROP TABLE IF EXISTS versions; +CREATE TABLE versions ( + "id" SERIAL PRIMARY KEY, + "item" varchar(64) NOT NULL, + "version" INTEGER NOT NULL, + UNIQUE (item) +); + + + diff --git a/data/tariffplans/tutorial/ResourceLimits.csv b/data/tariffplans/tutorial/ResourceLimits.csv index 3fa5dfcd8..b09181721 100644 --- a/data/tariffplans/tutorial/ResourceLimits.csv +++ b/data/tariffplans/tutorial/ResourceLimits.csv @@ -1,4 +1,4 @@ -#Id,FilterType,FilterFieldName,FilterValues,ActivationTime,Weight,Limit,ActionTriggers +#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationTime,Weight,Limit,ActionTriggers ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,10,2, ResGroup1,*string_prefix,Destination,10;20,2014-07-29T15:00:00Z,10,, ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,, diff --git a/docs/tariff_plans.rst b/docs/tariff_plans.rst index 96d9a0573..909c05bae 100644 --- a/docs/tariff_plans.rst +++ b/docs/tariff_plans.rst @@ -1,12 +1,12 @@ 4.2. Tariff Plans ================= -Major concept within CGRateS architecture, implement mechanisms to load rating as well as account data into CGRateS. -For importing the data into CGRateS database(s) we are using **csv** *files*. +Major concept within CGRateS architecture, implement mechanisms to load rating as well as account data into CGRateS. +For importing the data into CGRateS database(s) we are using **csv** *files*. The import process can be started as many times it is desired with one ore more csv files and the existing values are overwritten. -.. important:: If **-flushdb** option is used when importing data with cgr-loader, - then the database **is cleaned** before importing. +.. important:: If **-flushdb** option is used when importing data with cgr-loader, + then the database **is cleaned** before importing. For more details see the **cgr-loader** tool from the tutorial chapter. @@ -52,7 +52,7 @@ Describes the time periods that have different rates attached to them. [1] - Years: Integers separated by semicolons (;) specifying the years for this time period. - + **\*any** in case of always. [2] - Months: @@ -72,7 +72,7 @@ Describes the time periods that have different rates attached to them. [5] - Time: The start time for this time period. - + If you set it to **\*asap** (was **\*now**) it will be replaced with the time of the data importing. 4.2.3. Rates @@ -119,12 +119,12 @@ various timings. 4.2.4. Destination Rates ~~~~~~~~~~~~~~~~~~~~~~~ -Attach rates to destinations. +Attach rates to destinations. :: "DestinationRates.csv" - csv - "tp_destination_rates" - stor_db + "tp_destination_rates" - stor_db .. csv-table:: :file: ../data/tariffplans/tutorial/DestinationRates.csv @@ -340,7 +340,7 @@ trigger resetting. TBD [8] - BalanceTag: - Specifies the balance counter by which this action will be triggered. + Specifies the balance counter by which this action will be triggered. Can be: + **MONETARY** @@ -495,7 +495,7 @@ TBD TBD [8] - DestinationIds: - The destination id/tag described in the **Destinations** file. (*Destinations.csv* - Id) + The destination id/tag described in the **Destinations** file. (*Destinations.csv* - Id) This field is used only if the BalanceId is MINUTES. Specifies the destination of the minutes to be operated. @@ -866,7 +866,7 @@ TBD [2] - FilterFieldName TBD -[3] - FilterValues +[3] - FilterFieldValues TBD [4] - ActivationTime diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 2e68dec00..7cf6fe27b 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -268,7 +268,7 @@ cgrates.org,mas,true,another,value,10 ` resLimits = ` -#Id,FilterType,FilterFieldName,FilterValues,ActivationTime,Weight,Limit,ActionTriggers +#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationTime,Weight,Limit,ActionTriggers ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,10,2, ResGroup1,*string_prefix,Destination,10;20,2014-07-29T15:00:00Z,10,, ResGroup1,*cdr_stats,,CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20,,,, diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 9d794d2c9..337117da2 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -867,7 +867,7 @@ func (tps TpResourceLimits) AsTPResourceLimits() map[string]*utils.TPResourceLim resLimit.Filters = append(resLimit.Filters, &utils.TPRequestFilter{ Type: tp.FilterType, FieldName: tp.FilterFieldName, - Values: strings.Split(tp.FilterValues, utils.INFIELD_SEP)}) + Values: strings.Split(tp.FilterFieldValues, utils.INFIELD_SEP)}) } if tp.ActionTriggerIds != "" { resLimit.ActionTriggerIDs = append(resLimit.ActionTriggerIDs, strings.Split(tp.ActionTriggerIds, utils.INFIELD_SEP)...) diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index 1557c0a58..afc55af39 100644 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -670,31 +670,31 @@ func TestTPAccountActionsAsExportSlice(t *testing.T) { func TestTpResourceLimitsAsTPResourceLimits(t *testing.T) { tps := []*TpResourceLimit{ &TpResourceLimit{ - Tpid: "TEST_TPID", - Tag: "ResGroup1", - FilterType: MetaStringPrefix, - FilterFieldName: "Destination", - FilterValues: "+49151;+49161", - ActivationTime: "2014-07-29T15:00:00Z", - Weight: 10.0, - Limit: "45", - ActionTriggerIds: "WARN_RES1;WARN_RES2"}, + Tpid: "TEST_TPID", + Tag: "ResGroup1", + FilterType: MetaStringPrefix, + FilterFieldName: "Destination", + FilterFieldValues: "+49151;+49161", + ActivationTime: "2014-07-29T15:00:00Z", + Weight: 10.0, + Limit: "45", + ActionTriggerIds: "WARN_RES1;WARN_RES2"}, &TpResourceLimit{ - Tpid: "TEST_TPID", - Tag: "ResGroup1", - FilterType: MetaStringPrefix, - FilterFieldName: "Category", - FilterValues: "call;inbound_call", - ActionTriggerIds: "WARN3"}, + Tpid: "TEST_TPID", + Tag: "ResGroup1", + FilterType: MetaStringPrefix, + FilterFieldName: "Category", + FilterFieldValues: "call;inbound_call", + ActionTriggerIds: "WARN3"}, &TpResourceLimit{ - Tpid: "TEST_TPID", - Tag: "ResGroup2", - FilterType: MetaStringPrefix, - FilterFieldName: "Destination", - FilterValues: "+40", - ActivationTime: "2014-07-29T15:00:00Z", - Weight: 10.0, - Limit: "20"}, + Tpid: "TEST_TPID", + Tag: "ResGroup2", + FilterType: MetaStringPrefix, + FilterFieldName: "Destination", + FilterFieldValues: "+40", + ActivationTime: "2014-07-29T15:00:00Z", + Weight: 10.0, + Limit: "20"}, } eTPs := map[string]*utils.TPResourceLimit{ tps[0].Tag: &utils.TPResourceLimit{ diff --git a/engine/models.go b/engine/models.go index d87e24729..3b9e7243f 100644 --- a/engine/models.go +++ b/engine/models.go @@ -451,17 +451,17 @@ func (t TBLSMCosts) TableName() string { } type TpResourceLimit struct { - ID int64 - Tpid string - Tag string `index:"0" re:""` - FilterType string `index:"1" re:"^\*[A-Za-z].*"` - FilterFieldName string `index:"2" re:""` - FilterValues string `index:"3" re:""` - ActivationTime string `index:"4" re:""` - Weight float64 `index:"5" re:"\d+\.?\d*"` - Limit string `index:"6" re:""` - ActionTriggerIds string `index:"7" re:""` - CreatedAt time.Time + ID int64 + Tpid string + Tag string `index:"0" re:""` + FilterType string `index:"1" re:"^\*[A-Za-z].*"` + FilterFieldName string `index:"2" re:""` + FilterFieldValues string `index:"3" re:""` + ActivationTime string `index:"4" re:""` + Weight float64 `index:"5" re:"\d+\.?\d*"` + Limit string `index:"6" re:""` + ActionTriggerIds string `index:"7" re:""` + CreatedAt time.Time } type TBLVersion struct { diff --git a/engine/storage_interface.go b/engine/storage_interface.go index 4aab3a610..cf2d0fa74 100644 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -34,7 +34,7 @@ type Storage interface { GetKeysForPrefix(string) ([]string, error) RebuildReverseForPrefix(string) error GetVersions(itm string) (vrs Versions, err error) - SetVersions(vrs Versions) (err error) + SetVersions(vrs Versions, overwrite bool) (err error) RemoveVersions(vrs Versions) (err error) SelectDatabase(dbName string) (err error) } @@ -196,6 +196,7 @@ type CdrStorage interface { SetCDR(*CDR, bool) error SetSMCost(smc *SMCost) error GetSMCosts(cgrid, runid, originHost, originIDPrfx string) ([]*SMCost, error) + RemoveSMCost(*SMCost) error GetCDRs(*utils.CDRsFilter, bool) ([]*CDR, int64, error) } @@ -246,6 +247,7 @@ type LoadWriter interface { SetTpActionPlans([]TpActionPlan) error SetTpActionTriggers([]TpActionTrigger) error SetTpAccountActions([]TpAccountAction) error + SetTpResourceLimits(TpResourceLimits) error } type Marshaler interface { diff --git a/engine/storage_map.go b/engine/storage_map.go index 722572cf7..424539450 100644 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -1340,7 +1340,7 @@ func (ms *MapStorage) GetVersions(itm string) (vrs Versions, err error) { return } -func (ms *MapStorage) SetVersions(vrs Versions) (err error) { +func (ms *MapStorage) SetVersions(vrs Versions, overwrite bool) (err error) { return } diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go index cd90eb7b1..4516e1993 100644 --- a/engine/storage_mongo_stordb.go +++ b/engine/storage_mongo_stordb.go @@ -53,6 +53,7 @@ func (ms *MongoStorage) GetTpIds() ([]string, error) { } return tpids, nil } + func (ms *MongoStorage) GetTpTableIds(tpid, table string, distinct utils.TPDistinctIds, filter map[string]string, pag *utils.Paginator) ([]string, error) { selectors := bson.M{} for _, d := range distinct { @@ -124,6 +125,9 @@ func (ms *MongoStorage) GetTpTimings(tpid, tag string) ([]TpTiming, error) { session, col := ms.conn(utils.TBL_TP_TIMINGS) defer session.Close() err := col.Find(filter).All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } return results, err } @@ -138,6 +142,9 @@ func (ms *MongoStorage) GetTPDestinations(tpid, tag string) ([]*utils.TPDestinat session, col := ms.conn(utils.TBL_TP_DESTINATIONS) defer session.Close() err := col.Find(filter).All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } return results, err } @@ -152,6 +159,9 @@ func (ms *MongoStorage) GetTpRates(tpid, tag string) ([]TpRate, error) { session, col := ms.conn(utils.TBL_TP_RATES) defer session.Close() err := col.Find(filter).All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } return results, err } @@ -175,6 +185,9 @@ func (ms *MongoStorage) GetTpDestinationRates(tpid, tag string, pag *utils.Pagin } } err := q.All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } return results, err } @@ -198,6 +211,9 @@ func (ms *MongoStorage) GetTpRatingPlans(tpid, tag string, pag *utils.Paginator) } } err := q.All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } return results, err } @@ -222,6 +238,9 @@ func (ms *MongoStorage) GetTpRatingProfiles(tp *TpRatingProfile) ([]TpRatingProf session, col := ms.conn(utils.TBL_TP_RATE_PROFILES) defer session.Close() err := col.Find(filter).All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } return results, err } @@ -236,6 +255,9 @@ func (ms *MongoStorage) GetTpSharedGroups(tpid, tag string) ([]TpSharedGroup, er session, col := ms.conn(utils.TBL_TP_SHARED_GROUPS) defer session.Close() err := col.Find(filter).All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } return results, err } @@ -250,8 +272,12 @@ func (ms *MongoStorage) GetTpCdrStats(tpid, tag string) ([]TpCdrstat, error) { session, col := ms.conn(utils.TBL_TP_CDR_STATS) defer session.Close() err := col.Find(filter).All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } return results, err } + func (ms *MongoStorage) GetTpLCRs(tp *TpLcrRule) ([]TpLcrRule, error) { filter := bson.M{"tpid": tp.Tpid} if tp.Direction != "" { @@ -273,6 +299,9 @@ func (ms *MongoStorage) GetTpLCRs(tp *TpLcrRule) ([]TpLcrRule, error) { session, col := ms.conn(utils.TBL_TP_LCRS) defer session.Close() err := col.Find(filter).All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } return results, err } @@ -288,6 +317,9 @@ func (ms *MongoStorage) GetTpUsers(tp *TpUser) ([]TpUser, error) { session, col := ms.conn(utils.TBL_TP_USERS) defer session.Close() err := col.Find(filter).All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } return results, err } @@ -315,11 +347,27 @@ func (ms *MongoStorage) GetTpAliases(tp *TpAlias) ([]TpAlias, error) { session, col := ms.conn(utils.TBL_TP_ALIASES) defer session.Close() err := col.Find(filter).All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } return results, err } func (ms *MongoStorage) GetTpResourceLimits(tpid, tag string) (TpResourceLimits, error) { - return nil, nil + filter := bson.M{ + "tpid": tpid, + } + if tag != "" { + filter["tag"] = tag + } + var results TpResourceLimits + session, col := ms.conn(utils.TBLTPResourceLimits) + defer session.Close() + err := col.Find(filter).All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } + return results, err } func (ms *MongoStorage) GetTpDerivedChargers(tp *TpDerivedCharger) ([]TpDerivedCharger, error) { @@ -346,6 +394,9 @@ func (ms *MongoStorage) GetTpDerivedChargers(tp *TpDerivedCharger) ([]TpDerivedC session, col := ms.conn(utils.TBL_TP_DERIVED_CHARGERS) defer session.Close() err := col.Find(filter).All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } return results, err } @@ -360,6 +411,9 @@ func (ms *MongoStorage) GetTpActions(tpid, tag string) ([]TpAction, error) { session, col := ms.conn(utils.TBL_TP_ACTIONS) defer session.Close() err := col.Find(filter).All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } return results, err } @@ -374,6 +428,9 @@ func (ms *MongoStorage) GetTpActionPlans(tpid, tag string) ([]TpActionPlan, erro session, col := ms.conn(utils.TBL_TP_ACTION_PLANS) defer session.Close() err := col.Find(filter).All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } return results, err } @@ -388,6 +445,9 @@ func (ms *MongoStorage) GetTpActionTriggers(tpid, tag string) ([]TpActionTrigger session, col := ms.conn(utils.TBL_TP_ACTION_TRIGGERS) defer session.Close() err := col.Find(filter).All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } return results, err } @@ -406,6 +466,9 @@ func (ms *MongoStorage) GetTpAccountActions(tp *TpAccountAction) ([]TpAccountAct session, col := ms.conn(utils.TBL_TP_ACCOUNT_ACTIONS) defer session.Close() err := col.Find(filter).All(&results) + if len(results) == 0 { + return results, utils.ErrNotFound + } return results, err } @@ -439,15 +502,11 @@ func (ms *MongoStorage) SetTpTimings(tps []TpTiming) error { if len(tps) == 0 { return nil } - m := make(map[string]bool) session, col := ms.conn(utils.TBL_TP_TIMINGS) defer session.Close() tx := col.Bulk() for _, tp := range tps { - if found, _ := m[tp.Tag]; !found { - m[tp.Tag] = true - tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp) - } + tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp) } _, err := tx.Run() return err @@ -478,8 +537,9 @@ func (ms *MongoStorage) SetTpRates(tps []TpRate) error { for _, tp := range tps { if found, _ := m[tp.Tag]; !found { m[tp.Tag] = true - tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp) + tx.RemoveAll(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}) } + tx.Insert(tp) } _, err := tx.Run() return err @@ -496,8 +556,9 @@ func (ms *MongoStorage) SetTpDestinationRates(tps []TpDestinationRate) error { for _, tp := range tps { if found, _ := m[tp.Tag]; !found { m[tp.Tag] = true - tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp) + tx.RemoveAll(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}) } + tx.Insert(tp) } _, err := tx.Run() return err @@ -514,8 +575,9 @@ func (ms *MongoStorage) SetTpRatingPlans(tps []TpRatingPlan) error { for _, tp := range tps { if found, _ := m[tp.Tag]; !found { m[tp.Tag] = true - tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp) + tx.RemoveAll(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}) } + tx.Insert(tp) } _, err := tx.Run() return err @@ -525,22 +587,18 @@ func (ms *MongoStorage) SetTpRatingProfiles(tps []TpRatingProfile) error { if len(tps) == 0 { return nil } - m := make(map[string]bool) session, col := ms.conn(utils.TBL_TP_RATE_PROFILES) defer session.Close() tx := col.Bulk() for _, tp := range tps { - if found, _ := m[tp.GetRatingProfileId()]; !found { - m[tp.GetRatingProfileId()] = true - tx.Upsert(bson.M{ - "tpid": tp.Tpid, - "loadid": tp.Loadid, - "direction": tp.Direction, - "tenant": tp.Tenant, - "category": tp.Category, - "subject": tp.Subject, - }, tp) - } + tx.Upsert(bson.M{ + "tpid": tp.Tpid, + "loadid": tp.Loadid, + "direction": tp.Direction, + "tenant": tp.Tenant, + "category": tp.Category, + "subject": tp.Subject, + }, tp) } _, err := tx.Run() return err @@ -557,8 +615,9 @@ func (ms *MongoStorage) SetTpSharedGroups(tps []TpSharedGroup) error { for _, tp := range tps { if found, _ := m[tp.Tag]; !found { m[tp.Tag] = true - tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp) + tx.RemoveAll(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}) } + tx.Insert(tp) } _, err := tx.Run() return err @@ -575,8 +634,9 @@ func (ms *MongoStorage) SetTpCdrStats(tps []TpCdrstat) error { for _, tp := range tps { if found, _ := m[tp.Tag]; !found { m[tp.Tag] = true - tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp) + tx.RemoveAll(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}) } + tx.Insert(tp) } _, err := tx.Run() return err @@ -593,12 +653,13 @@ func (ms *MongoStorage) SetTpUsers(tps []TpUser) error { for _, tp := range tps { if found, _ := m[tp.GetId()]; !found { m[tp.GetId()] = true - tx.Upsert(bson.M{ + tx.RemoveAll(bson.M{ "tpid": tp.Tpid, "tenant": tp.Tenant, "username": tp.UserName, - }, tp) + }) } + tx.Insert(tp) } _, err := tx.Run() return err @@ -615,15 +676,16 @@ func (ms *MongoStorage) SetTpAliases(tps []TpAlias) error { for _, tp := range tps { if found, _ := m[tp.GetId()]; !found { m[tp.GetId()] = true - tx.Upsert(bson.M{ + tx.RemoveAll(bson.M{ "tpid": tp.Tpid, "direction": tp.Direction, "tenant": tp.Tenant, "category": tp.Category, "account": tp.Account, "subject": tp.Subject, - "context": tp.Context}, tp) + "context": tp.Context}) } + tx.Insert(tp) } _, err := tx.Run() return err @@ -640,14 +702,15 @@ func (ms *MongoStorage) SetTpDerivedChargers(tps []TpDerivedCharger) error { for _, tp := range tps { if found, _ := m[tp.GetDerivedChargersId()]; !found { m[tp.GetDerivedChargersId()] = true - tx.Upsert(bson.M{ + tx.RemoveAll(bson.M{ "tpid": tp.Tpid, "direction": tp.Direction, "tenant": tp.Tenant, "category": tp.Category, "account": tp.Account, - "subject": tp.Subject}, tp) + "subject": tp.Subject}) } + tx.Insert(tp) } _, err := tx.Run() return err @@ -657,21 +720,18 @@ func (ms *MongoStorage) SetTpLCRs(tps []TpLcrRule) error { if len(tps) == 0 { return nil } - m := make(map[string]bool) session, col := ms.conn(utils.TBL_TP_LCRS) defer session.Close() tx := col.Bulk() for _, tp := range tps { - if found, _ := m[tp.GetLcrRuleId()]; !found { - m[tp.GetLcrRuleId()] = true - tx.Upsert(bson.M{ - "tpid": tp.Tpid, - "direction": tp.Direction, - "tenant": tp.Tenant, - "category": tp.Category, - "account": tp.Account, - "subject": tp.Subject}, tp) - } + tx.Upsert(bson.M{ + "tpid": tp.Tpid, + "direction": tp.Direction, + "tenant": tp.Tenant, + "category": tp.Category, + "account": tp.Account, + "subject": tp.Subject}, tp) + } _, err := tx.Run() return err @@ -688,8 +748,9 @@ func (ms *MongoStorage) SetTpActions(tps []TpAction) error { for _, tp := range tps { if found, _ := m[tp.Tag]; !found { m[tp.Tag] = true - tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp) + tx.RemoveAll(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}) } + tx.Insert(tp) } _, err := tx.Run() return err @@ -706,8 +767,9 @@ func (ms *MongoStorage) SetTpActionPlans(tps []TpActionPlan) error { for _, tp := range tps { if found, _ := m[tp.Tag]; !found { m[tp.Tag] = true - tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp) + tx.RemoveAll(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}) } + tx.Insert(tp) } _, err := tx.Run() return err @@ -724,8 +786,9 @@ func (ms *MongoStorage) SetTpActionTriggers(tps []TpActionTrigger) error { for _, tp := range tps { if found, _ := m[tp.Tag]; !found { m[tp.Tag] = true - tx.Upsert(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}, tp) + tx.RemoveAll(bson.M{"tpid": tp.Tpid, "tag": tp.Tag}) } + tx.Insert(tp) } _, err := tx.Run() return err @@ -735,34 +798,70 @@ func (ms *MongoStorage) SetTpAccountActions(tps []TpAccountAction) error { if len(tps) == 0 { return nil } - m := make(map[string]bool) session, col := ms.conn(utils.TBL_TP_ACCOUNT_ACTIONS) defer session.Close() tx := col.Bulk() for _, tp := range tps { - if found, _ := m[tp.GetAccountActionId()]; !found { - m[tp.GetAccountActionId()] = true - tx.Upsert(bson.M{ - "tpid": tp.Tpid, - "loadid": tp.Loadid, - "tenant": tp.Tenant, - "account": tp.Account}, tp) + tx.Upsert(bson.M{ + "tpid": tp.Tpid, + "loadid": tp.Loadid, + "tenant": tp.Tenant, + "account": tp.Account}, tp) + } + _, err := tx.Run() + return err +} + +func (ms *MongoStorage) SetTpResourceLimits(rls TpResourceLimits) error { + if len(rls) == 0 { + return nil + } + m := make(map[string]bool) + session, col := ms.conn(utils.TBLTPResourceLimits) + defer session.Close() + tx := col.Bulk() + for _, rl := range rls { + if found, _ := m[rl.Tag]; !found { + m[rl.Tag] = true + tx.RemoveAll(bson.M{"tpid": rl.Tpid, "tag": rl.Tag}) } + tx.Insert(rl) } _, err := tx.Run() return err } func (ms *MongoStorage) SetSMCost(smc *SMCost) error { + if smc.CostDetails == nil { + return nil + } session, col := ms.conn(utils.TBLSMCosts) defer session.Close() return col.Insert(smc) } +func (ms *MongoStorage) RemoveSMCost(smc *SMCost) error { + session, col := ms.conn(utils.TBLSMCosts) + defer session.Close() + tx := col.Bulk() + tx.Remove(bson.M{"cgrid": smc.CGRID, "runid": smc.RunID}, smc) + _, err = tx.Run() + return err +} + func (ms *MongoStorage) GetSMCosts(cgrid, runid, originHost, originIDPrefix string) (smcs []*SMCost, err error) { - filter := bson.M{CGRIDLow: cgrid, RunIDLow: runid} + filter := bson.M{} + if cgrid != "" { + filter[CGRIDLow] = cgrid + } + if runid != "" { + filter[RunIDLow] = runid + } + if originHost != "" { + filter[OriginHostLow] = originHost + } if originIDPrefix != "" { - filter = bson.M{OriginIDLow: bson.M{"$regex": bson.RegEx{Pattern: fmt.Sprintf("^%s", originIDPrefix)}}, OriginHostLow: originHost, RunIDLow: runid} + filter["$regex"] = bson.RegEx{Pattern: fmt.Sprintf("^%s", originIDPrefix)} } // Execute query session, col := ms.conn(utils.TBLSMCosts) @@ -770,11 +869,15 @@ func (ms *MongoStorage) GetSMCosts(cgrid, runid, originHost, originIDPrefix stri iter := col.Find(filter).Iter() var smCost SMCost for iter.Next(&smCost) { - smcs = append(smcs, &smCost) + clone := smCost + smcs = append(smcs, &clone) } if err := iter.Err(); err != nil { return nil, err } + if len(smcs) == 0 { + return smcs, utils.ErrNotFound + } return smcs, nil } @@ -977,6 +1080,9 @@ func (ms *MongoStorage) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*CDR, clone := cdr cdrs = append(cdrs, &clone) } + if len(cdrs) == 0 { + return cdrs, 0, utils.ErrNotFound + } return cdrs, 0, nil } @@ -984,7 +1090,7 @@ func (ms *MongoStorage) GetVersions(itm string) (vrs Versions, err error) { return } -func (ms *MongoStorage) SetVersions(vrs Versions) (err error) { +func (ms *MongoStorage) SetVersions(vrs Versions, overwrite bool) (err error) { return } diff --git a/engine/storage_postgres.go b/engine/storage_postgres.go index a87debb91..c5a238ebd 100644 --- a/engine/storage_postgres.go +++ b/engine/storage_postgres.go @@ -20,14 +20,12 @@ package engine import ( "fmt" + "github.com/cgrates/cgrates/utils" + "github.com/jinzhu/gorm" _ "github.com/lib/pq" ) -type PostgresStorage struct { - *SQLStorage -} - func NewPostgresStorage(host, port, name, user, password string, maxConn, maxIdleConn int) (*PostgresStorage, error) { connectString := fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s sslmode=disable", host, port, name, user, password) db, err := gorm.Open("postgres", connectString) @@ -44,3 +42,30 @@ func NewPostgresStorage(host, port, name, user, password string, maxConn, maxIdl return &PostgresStorage{&SQLStorage{Db: db.DB(), db: db}}, nil } + +type PostgresStorage struct { + *SQLStorage +} + +func (self *PostgresStorage) SetVersions(vrs Versions, overwrite bool) (err error) { + tx := self.db.Begin() + if overwrite { + tx.Table(utils.TBLVersions).Delete(nil) + } + for key, val := range vrs { + vrModel := &TBLVersion{Item: key, Version: val} + if !overwrite { + if err = tx.Model(&TBLVersion{}).Where( + TBLVersion{Item: vrModel.Item}).Delete(TBLVersion{Version: val}).Error; err != nil { + tx.Rollback() + return + } + } + if err = tx.Save(vrModel).Error; err != nil { + tx.Rollback() + return + } + } + tx.Commit() + return +} diff --git a/engine/storage_redis.go b/engine/storage_redis.go index 2dd9188cc..58e2c363a 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -1506,7 +1506,7 @@ func (rs *RedisStorage) GetVersions(itm string) (vrs Versions, err error) { return } -func (rs *RedisStorage) SetVersions(vrs Versions) (err error) { +func (rs *RedisStorage) SetVersions(vrs Versions, overwrite bool) (err error) { return } diff --git a/engine/storage_sql.go b/engine/storage_sql.go index 2c4f86d1e..573ff6b55 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -181,7 +181,7 @@ func (self *SQLStorage) RemTpData(table, tpid string, args map[string]string) er if len(table) == 0 { // Remove tpid out of all tables for _, tblName := range []string{utils.TBL_TP_TIMINGS, utils.TBL_TP_DESTINATIONS, utils.TBL_TP_RATES, utils.TBL_TP_DESTINATION_RATES, utils.TBL_TP_RATING_PLANS, utils.TBL_TP_RATE_PROFILES, utils.TBL_TP_SHARED_GROUPS, utils.TBL_TP_CDR_STATS, utils.TBL_TP_LCRS, utils.TBL_TP_ACTIONS, utils.TBL_TP_ACTION_PLANS, utils.TBL_TP_ACTION_TRIGGERS, utils.TBL_TP_ACCOUNT_ACTIONS, - utils.TBL_TP_DERIVED_CHARGERS, utils.TBL_TP_ALIASES, utils.TBLTPResourceLimits} { + utils.TBL_TP_DERIVED_CHARGERS, utils.TBL_TP_ALIASES, utils.TBL_TP_USERS, utils.TBLTPResourceLimits} { if err := tx.Table(tblName).Where("tpid = ?", tpid).Delete(nil).Error; err != nil { tx.Rollback() return err @@ -208,16 +208,11 @@ func (self *SQLStorage) SetTpTimings(timings []TpTiming) error { if len(timings) == 0 { return nil } - m := make(map[string]bool) - tx := self.db.Begin() for _, timing := range timings { - if found, _ := m[timing.Tag]; !found { - m[timing.Tag] = true - if err := tx.Where(&TpTiming{Tpid: timing.Tpid, Tag: timing.Tag}).Delete(TpTiming{}).Error; err != nil { - tx.Rollback() - return err - } + if err := tx.Where(&TpTiming{Tpid: timing.Tpid, Tag: timing.Tag}).Delete(TpTiming{}).Error; err != nil { + tx.Rollback() + return err } save := tx.Save(&timing) if save.Error != nil { @@ -292,13 +287,11 @@ func (self *SQLStorage) SetTpDestinationRates(drs []TpDestinationRate) error { return err } } - saved := tx.Save(&dRate) if saved.Error != nil { tx.Rollback() return saved.Error } - } tx.Commit() return nil @@ -333,16 +326,12 @@ func (self *SQLStorage) SetTpRatingProfiles(rpfs []TpRatingProfile) error { if len(rpfs) == 0 { return nil //Nothing to set } - m := make(map[string]bool) tx := self.db.Begin() for _, rpf := range rpfs { - if found, _ := m[rpf.GetRatingProfileId()]; !found { - m[rpf.GetRatingProfileId()] = true - if err := tx.Where(&TpRatingProfile{Tpid: rpf.Tpid, Loadid: rpf.Loadid, Direction: rpf.Direction, Tenant: rpf.Tenant, Category: rpf.Category, Subject: rpf.Subject}).Delete(TpRatingProfile{}).Error; err != nil { - tx.Rollback() - return err - } + if err := tx.Where(&TpRatingProfile{Tpid: rpf.Tpid, Loadid: rpf.Loadid, Direction: rpf.Direction, Tenant: rpf.Tenant, Category: rpf.Category, Subject: rpf.Subject}).Delete(TpRatingProfile{}).Error; err != nil { + tx.Rollback() + return err } saved := tx.Save(&rpf) if saved.Error != nil { @@ -446,24 +435,19 @@ func (self *SQLStorage) SetTpLCRs(lcrs []TpLcrRule) error { if len(lcrs) == 0 { return nil //Nothing to set } - m := make(map[string]bool) tx := self.db.Begin() for _, lcr := range lcrs { - if found, _ := m[lcr.GetLcrRuleId()]; !found { - m[lcr.GetLcrRuleId()] = true - - if err := tx.Where(&TpLcrRule{ - Tpid: lcr.Tpid, - Direction: lcr.Direction, - Tenant: lcr.Tenant, - Category: lcr.Category, - Account: lcr.Account, - Subject: lcr.Subject, - }).Delete(TpLcrRule{}).Error; err != nil { - tx.Rollback() - return err - } + if err := tx.Where(&TpLcrRule{ + Tpid: lcr.Tpid, + Direction: lcr.Direction, + Tenant: lcr.Tenant, + Category: lcr.Category, + Account: lcr.Account, + Subject: lcr.Subject, + }).Delete(TpLcrRule{}).Error; err != nil { + tx.Rollback() + return err } if err := tx.Save(&lcr).Error; err != nil { tx.Rollback() @@ -545,7 +529,6 @@ func (self *SQLStorage) SetTpActionTriggers(ats []TpActionTrigger) error { tx.Rollback() return saved.Error } - } tx.Commit() return nil @@ -577,6 +560,33 @@ func (self *SQLStorage) SetTpAccountActions(aas []TpAccountAction) error { return nil } + +func (self *SQLStorage) SetTpResourceLimits(rls TpResourceLimits) error { + if len(rls) == 0 { + return nil + } + m := make(map[string]bool) + + tx := self.db.Begin() + for _, rl := range rls { + if found, _ := m[rl.Tag]; !found { + m[rl.Tag] = true + if err := tx.Where(&TpResourceLimit{Tpid: rl.Tpid, Tag: rl.Tag}).Delete(TpResourceLimit{}).Error; err != nil { + tx.Rollback() + return err + } + } + save := tx.Save(&rl) + if save.Error != nil { + fmt.Println(save.Error) + tx.Rollback() + return save.Error + } + } + tx.Commit() + return nil +} + func (self *SQLStorage) SetSMCost(smc *SMCost) error { if smc.CostDetails == nil { return nil @@ -605,12 +615,33 @@ func (self *SQLStorage) SetSMCost(smc *SMCost) error { return nil } +func (self *SQLStorage) RemoveSMCost(smc *SMCost) error { + tx := self.db.Begin() + + if err := tx.Where(&TBLSMCosts{Cgrid: smc.CGRID, RunID: smc.RunID}).Delete(SMCost{}).Error; err != nil { + tx.Rollback() + return err + } + tx.Commit() + return nil +} + // GetSMCosts is used to retrieve one or multiple SMCosts based on filter func (self *SQLStorage) GetSMCosts(cgrid, runid, originHost, originIDPrefix string) ([]*SMCost, error) { var smCosts []*SMCost - q := self.db.Where(&TBLSMCosts{Cgrid: cgrid, RunID: runid}) + filter := &TBLSMCosts{} + if cgrid != "" { + filter.Cgrid = cgrid + } + if runid != "" { + filter.RunID = runid + } + if originHost != "" { + filter.OriginHost = originHost + } + q := self.db.Where(filter) if originIDPrefix != "" { - q = self.db.Where(&TBLSMCosts{OriginHost: originHost, RunID: runid}).Where(fmt.Sprintf("origin_id LIKE '%s%%'", originIDPrefix)) + q = self.db.Where(filter).Where(fmt.Sprintf("origin_id LIKE '%s%%'", originIDPrefix)) } results := make([]*TBLSMCosts, 0) if err := q.Find(&results).Error; err != nil { @@ -634,7 +665,9 @@ func (self *SQLStorage) GetSMCosts(cgrid, runid, originHost, originIDPrefix stri } smCosts = append(smCosts, smc) } - + if len(smCosts) == 0 { + return smCosts, utils.ErrNotFound + } return smCosts, nil } @@ -1020,6 +1053,9 @@ func (self *SQLStorage) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*CDR, } cdrs = append(cdrs, storCdr) } + if len(cdrs) == 0 && !remove { + return cdrs, 0, utils.ErrNotFound + } return cdrs, 0, nil } @@ -1032,6 +1068,9 @@ func (self *SQLStorage) GetTPDestinations(tpid, tag string) (uTPDsts []*utils.TP if err := q.Find(&tpDests).Error; err != nil { return nil, err } + if len(tpDests.AsTPDestinations()) == 0 { + return tpDests.AsTPDestinations(), utils.ErrNotFound + } return tpDests.AsTPDestinations(), nil } @@ -1044,6 +1083,9 @@ func (self *SQLStorage) GetTpRates(tpid, tag string) ([]TpRate, error) { if err := q.Find(&tpRates).Error; err != nil { return nil, err } + if len(tpRates) == 0 { + return tpRates, utils.ErrNotFound + } return tpRates, nil } @@ -1064,7 +1106,9 @@ func (self *SQLStorage) GetTpDestinationRates(tpid, tag string, pagination *util if err := q.Find(&tpDestinationRates).Error; err != nil { return nil, err } - + if len(tpDestinationRates) == 0 { + return tpDestinationRates, utils.ErrNotFound + } return tpDestinationRates, nil } @@ -1077,6 +1121,9 @@ func (self *SQLStorage) GetTpTimings(tpid, tag string) ([]TpTiming, error) { if err := q.Find(&tpTimings).Error; err != nil { return nil, err } + if len(tpTimings) == 0 { + return tpTimings, utils.ErrNotFound + } return tpTimings, nil } @@ -1097,7 +1144,9 @@ func (self *SQLStorage) GetTpRatingPlans(tpid, tag string, pagination *utils.Pag q = q.Offset(*pagination.Offset) } } - + if len(tpRatingPlans) == 0 { + return tpRatingPlans, utils.ErrNotFound + } return tpRatingPlans, nil } @@ -1122,7 +1171,9 @@ func (self *SQLStorage) GetTpRatingProfiles(filter *TpRatingProfile) ([]TpRating if err := q.Find(&tpRpfs).Error; err != nil { return nil, err } - + if len(tpRpfs) == 0 { + return tpRpfs, utils.ErrNotFound + } return tpRpfs, nil } @@ -1135,8 +1186,10 @@ func (self *SQLStorage) GetTpSharedGroups(tpid, tag string) ([]TpSharedGroup, er if err := q.Find(&tpShareGroups).Error; err != nil { return nil, err } + if len(tpShareGroups) == 0 { + return tpShareGroups, utils.ErrNotFound + } return tpShareGroups, nil - } func (self *SQLStorage) GetTpLCRs(filter *TpLcrRule) ([]TpLcrRule, error) { @@ -1161,7 +1214,9 @@ func (self *SQLStorage) GetTpLCRs(filter *TpLcrRule) ([]TpLcrRule, error) { if err := q.Find(&tpLcrRule).Error; err != nil { return nil, err } - + if len(tpLcrRule) == 0 { + return tpLcrRule, utils.ErrNotFound + } return tpLcrRule, nil } @@ -1174,7 +1229,9 @@ func (self *SQLStorage) GetTpActions(tpid, tag string) ([]TpAction, error) { if err := q.Find(&tpActions).Error; err != nil { return nil, err } - + if len(tpActions) == 0 { + return tpActions, utils.ErrNotFound + } return tpActions, nil } @@ -1187,7 +1244,9 @@ func (self *SQLStorage) GetTpActionTriggers(tpid, tag string) ([]TpActionTrigger if err := q.Find(&tpActionTriggers).Error; err != nil { return nil, err } - + if len(tpActionTriggers) == 0 { + return tpActionTriggers, utils.ErrNotFound + } return tpActionTriggers, nil } @@ -1200,7 +1259,9 @@ func (self *SQLStorage) GetTpActionPlans(tpid, tag string) ([]TpActionPlan, erro if err := q.Find(&tpActionPlans).Error; err != nil { return nil, err } - + if len(tpActionPlans) == 0 { + return tpActionPlans, utils.ErrNotFound + } return tpActionPlans, nil } @@ -1220,6 +1281,9 @@ func (self *SQLStorage) GetTpAccountActions(filter *TpAccountAction) ([]TpAccoun if err := q.Find(&tpAccActs).Error; err != nil { return nil, err } + if len(tpAccActs) == 0 { + return tpAccActs, utils.ErrNotFound + } return tpAccActs, nil } @@ -1247,6 +1311,9 @@ func (self *SQLStorage) GetTpDerivedChargers(filter *TpDerivedCharger) ([]TpDeri if err := q.Find(&tpDerivedChargers).Error; err != nil { return nil, err } + if len(tpDerivedChargers) == 0 { + return tpDerivedChargers, utils.ErrNotFound + } return tpDerivedChargers, nil } @@ -1259,7 +1326,9 @@ func (self *SQLStorage) GetTpCdrStats(tpid, tag string) ([]TpCdrstat, error) { if err := q.Find(&tpCdrStats).Error; err != nil { return nil, err } - + if len(tpCdrStats) == 0 { + return tpCdrStats, utils.ErrNotFound + } return tpCdrStats, nil } @@ -1300,7 +1369,9 @@ func (self *SQLStorage) GetTpUsers(filter *TpUser) ([]TpUser, error) { if err := q.Find(&tpUsers).Error; err != nil { return nil, err } - + if len(tpUsers) == 0 { + return tpUsers, utils.ErrNotFound + } return tpUsers, nil } @@ -1374,6 +1445,9 @@ func (self *SQLStorage) GetTpResourceLimits(tpid, tag string) (TpResourceLimits, if err := q.Find(&tpResourceLimits).Error; err != nil { return nil, err } + if len(tpResourceLimits) == 0 { + return tpResourceLimits, utils.ErrNotFound + } return tpResourceLimits, nil } @@ -1395,8 +1469,11 @@ func (self *SQLStorage) GetVersions(itm string) (vrs Versions, err error) { } // SetVersions will set a slice of versions, updating existing -func (self *SQLStorage) SetVersions(vrs Versions) (err error) { +func (self *SQLStorage) SetVersions(vrs Versions, overwrite bool) (err error) { tx := self.db.Begin() + if overwrite { + tx.Table(utils.TBLVersions).Delete(nil) + } for key, val := range vrs { vrModel := &TBLVersion{Item: key, Version: val} if err = tx.Save(vrModel).Error; err != nil { diff --git a/engine/stordb_it_test.go b/engine/stordb_it_test.go index 4a14701c4..03c5a2a7c 100644 --- a/engine/stordb_it_test.go +++ b/engine/stordb_it_test.go @@ -25,14 +25,16 @@ import ( "runtime" "strings" "testing" + "time" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) var ( - cfg *config.CGRConfig - storDB StorDB + cfg *config.CGRConfig + storDB StorDB + storDB2ndDBname string ) // subtests to be executed for each confDIR @@ -54,6 +56,9 @@ var sTestsStorDBit = []func(t *testing.T){ testStorDBitCRUDTpDerivedChargers, testStorDBitCRUDTpCdrStats, testStorDBitCRUDTpUsers, + testStorDBitCRUDTpResourceLimits, + testStorDBitCRUDCDRs, + testStorDBitCRUDSMCosts, } func TestStorDBitMySQL(t *testing.T) { @@ -64,6 +69,7 @@ func TestStorDBitMySQL(t *testing.T) { cfg.StorDBUser, cfg.StorDBPass, cfg.StorDBMaxOpenConns, cfg.StorDBMaxIdleConns); err != nil { t.Fatal(err) } + storDB2ndDBname = "mysql" for _, stest := range sTestsStorDBit { stestFullName := runtime.FuncForPC(reflect.ValueOf(stest).Pointer()).Name() split := strings.Split(stestFullName, ".") @@ -72,12 +78,49 @@ func TestStorDBitMySQL(t *testing.T) { } } +func TestStorDBitPostgresSQL(t *testing.T) { + if cfg, err = config.NewCGRConfigFromFolder(path.Join(*dataDir, "conf", "samples", "storage", "postgres")); err != nil { + t.Fatal(err) + } + if storDB, err = NewPostgresStorage(cfg.StorDBHost, cfg.StorDBPort, cfg.StorDBName, + cfg.StorDBUser, cfg.StorDBPass, cfg.StorDBMaxOpenConns, cfg.StorDBMaxIdleConns); err != nil { + t.Fatal(err) + } + storDB2ndDBname = "postgres" + for _, stest := range sTestsStorDBit { + stestFullName := runtime.FuncForPC(reflect.ValueOf(stest).Pointer()).Name() + split := strings.Split(stestFullName, ".") + stestName := split[len(split)-1] + t.Run(stestName, stest) + } +} + +func TestStorDBitMongo(t *testing.T) { + if cfg, err = config.NewCGRConfigFromFolder(path.Join(*dataDir, "conf", "samples", "storage", "mongo")); err != nil { + t.Fatal(err) + } + if storDB, err = NewMongoStorage(cfg.StorDBHost, cfg.StorDBPort, cfg.StorDBName, + cfg.StorDBUser, cfg.StorDBPass, utils.StorDB, cfg.StorDBCDRSIndexes, nil, cfg.LoadHistorySize); err != nil { + t.Fatal(err) + } + storDB2ndDBname = "todo" + for _, stest := range sTestsStorDBit { + stestFullName := runtime.FuncForPC(reflect.ValueOf(stest).Pointer()).Name() + split := strings.Split(stestFullName, ".") + stestName := split[len(split)-1] + // Fixme: Implement mongo needed versions methods + if stestName != "testStorDBitCRUDVersions" { + stestName := split[len(split)-1] + t.Run(stestName, stest) + } + } +} + func testStorDBitCRUDTpTimings(t *testing.T) { // READ - // Fixme: Implement ErrNotfound in called method - // if rcv, err := storDB.GetTpTimings("testTPid", ""); err != utils.ErrNotFound { - // t.Error(err, rcv) - // } + if _, err := storDB.GetTpTimings("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } // WRITE var snd = []TpTiming{ TpTiming{ @@ -106,12 +149,12 @@ func testStorDBitCRUDTpTimings(t *testing.T) { if rcv, err := storDB.GetTpTimings("testTPid", ""); err != nil { t.Error(err) } else { - snd[0].Id = rcv[0].Id - snd[1].Id = rcv[1].Id - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // UPDATE @@ -124,10 +167,12 @@ func testStorDBitCRUDTpTimings(t *testing.T) { if rcv, err := storDB.GetTpTimings("testTPid", ""); err != nil { t.Error(err) } else { - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // REMOVE @@ -135,18 +180,16 @@ func testStorDBitCRUDTpTimings(t *testing.T) { t.Error(err) } // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpTimings("testTPid", ""); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpTimings("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } } func testStorDBitCRUDTpDestinations(t *testing.T) { // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTPDestinations("testTPid", ""); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTPDestinations("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } // WRITE snd := []*utils.TPDestination{ &utils.TPDestination{ @@ -167,8 +210,24 @@ func testStorDBitCRUDTpDestinations(t *testing.T) { if rcv, err := storDB.GetTPDestinations("testTPid", ""); err != nil { t.Error(err) } else { + prfs := make(map[string]bool) + for _, prf := range snd[0].Prefixes { + prfs[prf] = true + } + pfrOk := true + for i, _ := range rcv[0].Prefixes { + found1, _ := prfs[rcv[0].Prefixes[i]] + found2, _ := prfs[rcv[1].Prefixes[i]] + if !found1 && !found2 { + pfrOk = false + } + } + if pfrOk { + rcv[0].Prefixes = snd[0].Prefixes + rcv[1].Prefixes = snd[0].Prefixes + } if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { - t.Errorf("Expecting: %+v, received: %+v", snd[0], rcv[0]) + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // UPDATE @@ -181,8 +240,24 @@ func testStorDBitCRUDTpDestinations(t *testing.T) { if rcv, err := storDB.GetTPDestinations("testTPid", ""); err != nil { t.Error(err) } else { + prfs := make(map[string]bool) + for _, prf := range snd[0].Prefixes { + prfs[prf] = true + } + pfrOk := true + for i, _ := range rcv[0].Prefixes { + found1, _ := prfs[rcv[0].Prefixes[i]] + found2, _ := prfs[rcv[1].Prefixes[i]] + if !found1 && !found2 { + pfrOk = false + } + } + if pfrOk { + rcv[0].Prefixes = snd[0].Prefixes + rcv[1].Prefixes = snd[0].Prefixes + } if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { - t.Errorf("Expecting: %+v, received: %+v", snd[0], rcv[0]) + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // REMOVE @@ -190,18 +265,16 @@ func testStorDBitCRUDTpDestinations(t *testing.T) { t.Error(err) } // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTPDestinations("testTPid", ""); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTPDestinations("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } } func testStorDBitCRUDTpRates(t *testing.T) { // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpRates("testTPid", ""); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpRates("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } // WRITE var snd = []TpRate{ TpRate{ @@ -216,10 +289,10 @@ func testStorDBitCRUDTpRates(t *testing.T) { TpRate{ Tpid: "testTPid", Tag: "testTag2", - ConnectFee: 0.0, - Rate: 0.0, - RateUnit: "60s", - RateIncrement: "60s", + ConnectFee: 1.0, + Rate: 1.0, + RateUnit: "70s", + RateIncrement: "70s", GroupIntervalStart: "0s", }, } @@ -230,12 +303,12 @@ func testStorDBitCRUDTpRates(t *testing.T) { if rcv, err := storDB.GetTpRates("testTPid", ""); err != nil { t.Error(err) } else { - snd[0].Id = rcv[0].Id - snd[1].Id = rcv[1].Id - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // UPDATE @@ -248,10 +321,12 @@ func testStorDBitCRUDTpRates(t *testing.T) { if rcv, err := storDB.GetTpRates("testTPid", ""); err != nil { t.Error(err) } else { - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // REMOVE @@ -259,18 +334,16 @@ func testStorDBitCRUDTpRates(t *testing.T) { t.Error(err) } // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpRates("testTPid", ""); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpRates("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } } func testStorDBitCRUDTpDestinationRates(t *testing.T) { // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpDestinationRates("testTPid", "", nil); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpDestinationRates("testTPid", "", nil); err != utils.ErrNotFound { + t.Error(err) + } // WRITE var snd = []TpDestinationRate{ TpDestinationRate{ @@ -285,10 +358,10 @@ func testStorDBitCRUDTpDestinationRates(t *testing.T) { }, TpDestinationRate{ Tpid: "testTPid", - Tag: "testTag2", - DestinationsTag: "GERMANY", - RatesTag: "RT_1CENT", - RoundingMethod: "*up", + Tag: "testTag1", + DestinationsTag: "FRANCE", + RatesTag: "RT_2CENT", + RoundingMethod: "*down", RoundingDecimals: 0, MaxCost: 0.0, MaxCostStrategy: "", @@ -301,12 +374,12 @@ func testStorDBitCRUDTpDestinationRates(t *testing.T) { if rcv, err := storDB.GetTpDestinationRates("testTPid", "", nil); err != nil { t.Error(err) } else { - snd[0].Id = rcv[0].Id - snd[1].Id = rcv[1].Id - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // UPDATE @@ -319,10 +392,12 @@ func testStorDBitCRUDTpDestinationRates(t *testing.T) { if rcv, err := storDB.GetTpDestinationRates("testTPid", "", nil); err != nil { t.Error(err) } else { - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // REMOVE @@ -330,33 +405,31 @@ func testStorDBitCRUDTpDestinationRates(t *testing.T) { t.Error(err) } // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpDestinationRates("testTPid", "", nil); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpDestinationRates("testTPid", "", nil); err != utils.ErrNotFound { + t.Error(err) + } } func testStorDBitCRUDTpRatingPlans(t *testing.T) { // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpRatingPlans("testTPid", "", nil); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpRatingPlans("testTPid", "", nil); err != utils.ErrNotFound { + t.Error(err) + } // WRITE var snd = []TpRatingPlan{ TpRatingPlan{ Tpid: "testTPid", Tag: "testTag1", - DestratesTag: "", + DestratesTag: "1", TimingTag: "ALWAYS", Weight: 0.0, }, TpRatingPlan{ Tpid: "testTPid", - Tag: "testTag2", - DestratesTag: "", + Tag: "testTag1", + DestratesTag: "2", TimingTag: "ALWAYS", - Weight: 0.0, + Weight: 1.0, }, } if err := storDB.SetTpRatingPlans(snd); err != nil { @@ -366,12 +439,12 @@ func testStorDBitCRUDTpRatingPlans(t *testing.T) { if rcv, err := storDB.GetTpRatingPlans("testTPid", "", nil); err != nil { t.Error(err) } else { - snd[0].Id = rcv[0].Id - snd[1].Id = rcv[1].Id - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // UPDATE @@ -384,10 +457,12 @@ func testStorDBitCRUDTpRatingPlans(t *testing.T) { if rcv, err := storDB.GetTpRatingPlans("testTPid", "", nil); err != nil { t.Error(err) } else { - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // REMOVE @@ -395,30 +470,19 @@ func testStorDBitCRUDTpRatingPlans(t *testing.T) { t.Error(err) } // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpRatingPlans("testTPid", "", nil); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpRatingPlans("testTPid", "", nil); err != utils.ErrNotFound { + t.Error(err) + } } func testStorDBitCRUDTpRatingProfiles(t *testing.T) { // READ var filter = TpRatingProfile{ - Tpid: "testTPid", - Loadid: "", - Direction: "", - Tenant: "", - Category: "", - Subject: "", - ActivationTime: "", - RatingPlanTag: "", - FallbackSubjects: "", - CdrStatQueueIds: "", + Tpid: "testTPid", + } + if _, err := storDB.GetTpRatingProfiles(&filter); err != utils.ErrNotFound { + t.Error(err) } - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpRatingProfiles(&filter); err != utils.ErrNotFound { - // t.Error(err) - // } // WRITE var snd = []TpRatingProfile{ TpRatingProfile{ @@ -453,12 +517,12 @@ func testStorDBitCRUDTpRatingProfiles(t *testing.T) { if rcv, err := storDB.GetTpRatingProfiles(&filter); err != nil { t.Error(err) } else { - snd[0].Id = rcv[0].Id - snd[1].Id = rcv[1].Id - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // UPDATE @@ -471,10 +535,12 @@ func testStorDBitCRUDTpRatingProfiles(t *testing.T) { if rcv, err := storDB.GetTpRatingProfiles(&filter); err != nil { t.Error(err) } else { - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // REMOVE @@ -482,31 +548,29 @@ func testStorDBitCRUDTpRatingProfiles(t *testing.T) { t.Error(err) } // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpRatingProfiles(&filter); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpRatingProfiles(&filter); err != utils.ErrNotFound { + t.Error(err) + } } func testStorDBitCRUDTpSharedGroups(t *testing.T) { // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpSharedGroups("testTPid", ""); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpSharedGroups("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } // WRITE var snd = []TpSharedGroup{ TpSharedGroup{ Tpid: "testTPid", Tag: "testTag1", - Account: "test", + Account: "test1", Strategy: "*lowest_cost", RatingSubject: "test", }, TpSharedGroup{ Tpid: "testTPid", - Tag: "testTag2", - Account: "test", + Tag: "testTag1", + Account: "test2", Strategy: "*lowest_cost", RatingSubject: "test", }, @@ -518,12 +582,12 @@ func testStorDBitCRUDTpSharedGroups(t *testing.T) { if rcv, err := storDB.GetTpSharedGroups("testTPid", ""); err != nil { t.Error(err) } else { - snd[0].Id = rcv[0].Id - snd[1].Id = rcv[1].Id - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // UPDATE @@ -536,10 +600,12 @@ func testStorDBitCRUDTpSharedGroups(t *testing.T) { if rcv, err := storDB.GetTpSharedGroups("testTPid", ""); err != nil { t.Error(err) } else { - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // REMOVE @@ -547,18 +613,16 @@ func testStorDBitCRUDTpSharedGroups(t *testing.T) { t.Error(err) } // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpSharedGroups("testTPid", ""); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpSharedGroups("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } } func testStorDBitCRUDTpActions(t *testing.T) { // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpActions("testTPid", ""); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpActions("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } // WRITE var snd = []TpAction{ TpAction{ @@ -584,8 +648,8 @@ func testStorDBitCRUDTpActions(t *testing.T) { }, TpAction{ Tpid: "testTPid", - Tag: "testTag2", - Action: "*topup_reset", + Tag: "testTag1", + Action: "*topup_reset2", ExtraParameters: "", Filter: "", BalanceTag: "", @@ -611,12 +675,12 @@ func testStorDBitCRUDTpActions(t *testing.T) { if rcv, err := storDB.GetTpActions("testTPid", ""); err != nil { t.Error(err) } else { - snd[0].Id = rcv[0].Id - snd[1].Id = rcv[1].Id - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // UPDATE @@ -629,10 +693,12 @@ func testStorDBitCRUDTpActions(t *testing.T) { if rcv, err := storDB.GetTpActions("testTPid", ""); err != nil { t.Error(err) } else { - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // REMOVE @@ -640,18 +706,16 @@ func testStorDBitCRUDTpActions(t *testing.T) { t.Error(err) } // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpActions("testTPid", ""); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpActions("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } } func testStorDBitCRUDTpActionPlans(t *testing.T) { // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpActionPlans("testTPid", ""); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpActionPlans("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } // WRITE var snd = []TpActionPlan{ TpActionPlan{ @@ -664,7 +728,7 @@ func testStorDBitCRUDTpActionPlans(t *testing.T) { TpActionPlan{ Tpid: "testTPid", Tag: "testTag2", - ActionsTag: "test", + ActionsTag: "test2", TimingTag: "", Weight: 0.0, }, @@ -676,17 +740,17 @@ func testStorDBitCRUDTpActionPlans(t *testing.T) { if rcv, err := storDB.GetTpActionPlans("testTPid", ""); err != nil { t.Error(err) } else { - snd[0].Id = rcv[0].Id - snd[1].Id = rcv[1].Id - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // UPDATE - snd[0].Tag = "testTag1b" - snd[1].Tag = "testTag2b" + snd[0].TimingTag = "test" + snd[1].TimingTag = "test" if err := storDB.SetTpActionPlans(snd); err != nil { t.Error(err) } @@ -694,10 +758,12 @@ func testStorDBitCRUDTpActionPlans(t *testing.T) { if rcv, err := storDB.GetTpActionPlans("testTPid", ""); err != nil { t.Error(err) } else { - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // REMOVE @@ -705,18 +771,16 @@ func testStorDBitCRUDTpActionPlans(t *testing.T) { t.Error(err) } // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpActionPlans("testTPid", ""); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpActionPlans("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } } func testStorDBitCRUDTpActionTriggers(t *testing.T) { // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpActionTriggers("testTPid", ""); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpActionTriggers("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } // WRITE var snd = []TpActionTrigger{ TpActionTrigger{ @@ -747,7 +811,7 @@ func testStorDBitCRUDTpActionTriggers(t *testing.T) { }, TpActionTrigger{ Tpid: "testTPid", - Tag: "testTag2", + Tag: "testTag1", UniqueId: "", ThresholdType: "", ThresholdValue: 0.0, @@ -755,7 +819,7 @@ func testStorDBitCRUDTpActionTriggers(t *testing.T) { MinSleep: "0", ExpiryTime: "2014-07-29T15:00:00Z", ActivationTime: "2014-07-29T15:00:00Z", - BalanceTag: "test", + BalanceTag: "test2", BalanceType: "*monetary", BalanceDirections: "*out", BalanceCategories: "call", @@ -779,12 +843,12 @@ func testStorDBitCRUDTpActionTriggers(t *testing.T) { if rcv, err := storDB.GetTpActionTriggers("testTPid", ""); err != nil { t.Error(err) } else { - snd[0].Id = rcv[0].Id - snd[1].Id = rcv[1].Id - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // UPDATE @@ -797,10 +861,12 @@ func testStorDBitCRUDTpActionTriggers(t *testing.T) { if rcv, err := storDB.GetTpActionTriggers("testTPid", ""); err != nil { t.Error(err) } else { - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // REMOVE @@ -808,10 +874,9 @@ func testStorDBitCRUDTpActionTriggers(t *testing.T) { t.Error(err) } // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpActionTriggers("testTPid", ""); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpActionTriggers("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } } func testStorDBitCRUDTpAccountActions(t *testing.T) { @@ -826,10 +891,9 @@ func testStorDBitCRUDTpAccountActions(t *testing.T) { AllowNegative: true, Disabled: true, } - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpAccountActions(&filter); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpAccountActions(&filter); err != utils.ErrNotFound { + t.Error(err) + } // WRITE var snd = []TpAccountAction{ TpAccountAction{ @@ -860,12 +924,12 @@ func testStorDBitCRUDTpAccountActions(t *testing.T) { if rcv, err := storDB.GetTpAccountActions(&filter); err != nil { t.Error(err) } else { - snd[0].Id = rcv[0].Id - snd[1].Id = rcv[1].Id - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // UPDATE @@ -878,10 +942,12 @@ func testStorDBitCRUDTpAccountActions(t *testing.T) { if rcv, err := storDB.GetTpAccountActions(&filter); err != nil { t.Error(err) } else { - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // REMOVE @@ -889,10 +955,9 @@ func testStorDBitCRUDTpAccountActions(t *testing.T) { t.Error(err) } // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpAccountActions(&filter); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpAccountActions(&filter); err != utils.ErrNotFound { + t.Error(err) + } } func testStorDBitCRUDTpLCRs(t *testing.T) { @@ -911,10 +976,9 @@ func testStorDBitCRUDTpLCRs(t *testing.T) { ActivationTime: "", Weight: 0.0, } - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpLCRs(&filter); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpLCRs(&filter); err != utils.ErrNotFound { + t.Error(err) + } // WRITE var snd = []TpLcrRule{ TpLcrRule{ @@ -933,11 +997,11 @@ func testStorDBitCRUDTpLCRs(t *testing.T) { }, TpLcrRule{ Tpid: "testTPid", - Direction: "*in", + Direction: "*out", Tenant: "cgrates.org", Category: "LCR_STANDARD", Account: "1000", - Subject: "test", + Subject: "test2", DestinationTag: "", RpCategory: "LCR_STANDARD", Strategy: "*lowest_cost", @@ -953,12 +1017,12 @@ func testStorDBitCRUDTpLCRs(t *testing.T) { if rcv, err := storDB.GetTpLCRs(&filter); err != nil { t.Error(err) } else { - snd[0].Id = rcv[0].Id - snd[1].Id = rcv[1].Id - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // UPDATE @@ -971,10 +1035,12 @@ func testStorDBitCRUDTpLCRs(t *testing.T) { if rcv, err := storDB.GetTpLCRs(&filter); err != nil { t.Error(err) } else { - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // REMOVE @@ -982,45 +1048,19 @@ func testStorDBitCRUDTpLCRs(t *testing.T) { t.Error(err) } // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpLCRs(&filter); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpLCRs(&filter); err != utils.ErrNotFound { + t.Error(err) + } } func testStorDBitCRUDTpDerivedChargers(t *testing.T) { // READ var filter = TpDerivedCharger{ - Tpid: "testTPid", - Loadid: "", - Direction: "", - Tenant: "", - Category: "", - Account: "", - Subject: "", - DestinationIds: "", - Runid: "", - RunFilters: "", - ReqTypeField: "", - DirectionField: "", - TenantField: "", - CategoryField: "", - AccountField: "", - SubjectField: "", - DestinationField: "", - SetupTimeField: "", - PddField: "", - AnswerTimeField: "", - UsageField: "", - SupplierField: "", - DisconnectCauseField: "", - RatedField: "", - CostField: "", + Tpid: "testTPid", + } + if _, err := storDB.GetTpDerivedChargers(&filter); err != utils.ErrNotFound { + t.Error(err) } - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpDerivedChargers(&filter); err != utils.ErrNotFound { - // t.Error(err) - // } // WRITE var snd = []TpDerivedCharger{ TpDerivedCharger{ @@ -1052,11 +1092,11 @@ func testStorDBitCRUDTpDerivedChargers(t *testing.T) { }, TpDerivedCharger{ Tpid: "testTPid", - Loadid: "TEST_LOADID2", + Loadid: "TEST_LOADID", Direction: "*out", Tenant: "cgrates.org", Category: "call", - Account: "1000", + Account: "1001", Subject: "test", DestinationIds: "", Runid: "default", @@ -1085,12 +1125,12 @@ func testStorDBitCRUDTpDerivedChargers(t *testing.T) { if rcv, err := storDB.GetTpDerivedChargers(&filter); err != nil { t.Error(err) } else { - snd[0].Id = rcv[0].Id - snd[1].Id = rcv[1].Id - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // UPDATE @@ -1103,10 +1143,12 @@ func testStorDBitCRUDTpDerivedChargers(t *testing.T) { if rcv, err := storDB.GetTpDerivedChargers(&filter); err != nil { t.Error(err) } else { - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // REMOVE @@ -1114,23 +1156,21 @@ func testStorDBitCRUDTpDerivedChargers(t *testing.T) { t.Error(err) } // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpDerivedChargers(&filter); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpDerivedChargers(&filter); err != utils.ErrNotFound { + t.Error(err) + } } func testStorDBitCRUDTpCdrStats(t *testing.T) { - // Fixme: Implement ErrNotfound in called method // READ - // if _, err := storDB.GetTpCdrStats("testTPid", ""); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpCdrStats("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } // WRITE var snd = []TpCdrstat{ TpCdrstat{ Tpid: "testTPid", - Tag: "testTag1", + Tag: "testTag", QueueLength: 0, TimeWindow: "10m", SaveInterval: "10s", @@ -1158,7 +1198,7 @@ func testStorDBitCRUDTpCdrStats(t *testing.T) { }, TpCdrstat{ Tpid: "testTPid", - Tag: "testTag2", + Tag: "testTag", QueueLength: 0, TimeWindow: "10m", SaveInterval: "10s", @@ -1192,12 +1232,12 @@ func testStorDBitCRUDTpCdrStats(t *testing.T) { if rcv, err := storDB.GetTpCdrStats("testTPid", ""); err != nil { t.Error(err) } else { - snd[0].Id = rcv[0].Id - snd[1].Id = rcv[1].Id - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // UPDATE @@ -1210,10 +1250,12 @@ func testStorDBitCRUDTpCdrStats(t *testing.T) { if rcv, err := storDB.GetTpCdrStats("testTPid", ""); err != nil { t.Error(err) } else { - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // REMOVE @@ -1221,10 +1263,9 @@ func testStorDBitCRUDTpCdrStats(t *testing.T) { t.Error(err) } // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpCdrStats("testTPid", ""); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpCdrStats("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } } func testStorDBitCRUDTpUsers(t *testing.T) { @@ -1238,10 +1279,9 @@ func testStorDBitCRUDTpUsers(t *testing.T) { AttributeValue: "", Weight: 0.0, } - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpUsers(&filter); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpUsers(&filter); err != utils.ErrNotFound { + t.Error(err) + } // WRITE var snd = []TpUser{ TpUser{ @@ -1255,11 +1295,11 @@ func testStorDBitCRUDTpUsers(t *testing.T) { }, TpUser{ Tpid: "testTPid", - Tenant: "cgrates2.org", + Tenant: "cgrates.org", UserName: "1001", Masked: true, AttributeName: "Account", - AttributeValue: "1001", + AttributeValue: "1002", Weight: 0.0, }, } @@ -1270,12 +1310,12 @@ func testStorDBitCRUDTpUsers(t *testing.T) { if rcv, err := storDB.GetTpUsers(&filter); err != nil { t.Error(err) } else { - snd[0].Id = rcv[0].Id - snd[1].Id = rcv[1].Id - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // UPDATE @@ -1288,10 +1328,12 @@ func testStorDBitCRUDTpUsers(t *testing.T) { if rcv, err := storDB.GetTpUsers(&filter); err != nil { t.Error(err) } else { - snd[0].CreatedAt = rcv[0].CreatedAt - snd[1].CreatedAt = rcv[1].CreatedAt - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // REMOVE @@ -1299,10 +1341,9 @@ func testStorDBitCRUDTpUsers(t *testing.T) { t.Error(err) } // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpUsers(&filter); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpUsers(&filter); err != utils.ErrNotFound { + t.Error(err) + } } func testStorDBitCRUDTpAliases(t *testing.T) { @@ -1321,10 +1362,9 @@ func testStorDBitCRUDTpAliases(t *testing.T) { Alias: "", Weight: 0.0, } - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpAliases(&filter); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpAliases(&filter); err != utils.ErrNotFound { + t.Error(err) + } // WRITE var snd = []TpAlias{ TpAlias{ @@ -1362,9 +1402,12 @@ func testStorDBitCRUDTpAliases(t *testing.T) { // READ if rcv, err := storDB.GetTpAliases(&filter); err != nil { t.Error(err) - } else if !reflect.DeepEqual(snd, rcv) { - // Fixme: TpAlias missing CreatedAt field - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + } else { + rcv[0].Id = 0 + rcv[1].Id = 0 + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) + } } // UPDATE snd[0].Target = "test" @@ -1376,8 +1419,10 @@ func testStorDBitCRUDTpAliases(t *testing.T) { if rcv, err := storDB.GetTpAliases(&filter); err != nil { t.Error(err) } else { - if !reflect.DeepEqual(snd, rcv) { - t.Errorf("Expecting: %+v, received: %+v", snd, rcv) + rcv[0].Id = 0 + rcv[1].Id = 0 + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) } } // REMOVE @@ -1385,10 +1430,289 @@ func testStorDBitCRUDTpAliases(t *testing.T) { t.Error(err) } // READ - // Fixme: Implement ErrNotfound in called method - // if _, err := storDB.GetTpAliases(&filter); err != utils.ErrNotFound { - // t.Error(err) - // } + if _, err := storDB.GetTpAliases(&filter); err != utils.ErrNotFound { + t.Error(err) + } +} + +func testStorDBitCRUDTpResourceLimits(t *testing.T) { + // READ + if _, err := storDB.GetTpResourceLimits("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } + //WRITE + var snd = TpResourceLimits{ + &TpResourceLimit{ + Tpid: "testTPid", + Tag: "testTag1", + FilterType: "test", + FilterFieldName: "test", + FilterFieldValues: "test", + ActivationTime: "test", + Weight: 0.0, + Limit: "test", + ActionTriggerIds: "test", + }, + &TpResourceLimit{ + Tpid: "testTPid", + Tag: "testTag2", + FilterType: "test", + FilterFieldName: "test", + FilterFieldValues: "test", + ActivationTime: "test", + Weight: 0.0, + Limit: "test", + ActionTriggerIds: "test", + }, + } + if err := storDB.SetTpResourceLimits(snd); err != nil { + t.Error(err) + } + // READ + if rcv, err := storDB.GetTpResourceLimits("testTPid", ""); err != nil { + t.Error(err) + } else { + snd[0].CreatedAt = time.Time{} + snd[1].CreatedAt = time.Time{} + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) + } + } + // UPDATE + snd[0].Weight = 2.1 + snd[1].Weight = 2.1 + if err := storDB.SetTpResourceLimits(snd); err != nil { + t.Error(err) + } + // READ + if rcv, err := storDB.GetTpResourceLimits("testTPid", ""); err != nil { + t.Error(err) + } else { + snd[0].CreatedAt = time.Time{} + snd[1].CreatedAt = time.Time{} + rcv[0].CreatedAt = time.Time{} + rcv[1].CreatedAt = time.Time{} + if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0], rcv[0], rcv[1]) + } + } + // REMOVE + if err := storDB.RemTpData("", "testTPid", nil); err != nil { + t.Error(err) + } + // READ + if _, err := storDB.GetTpResourceLimits("testTPid", ""); err != utils.ErrNotFound { + t.Error(err) + } +} + +func testStorDBitCRUDCDRs(t *testing.T) { + // READ + var filter = utils.CDRsFilter{} + if _, _, err := storDB.GetCDRs(&filter, false); err != utils.ErrNotFound { + t.Error(err) + } + // WRITE + var snd = []*CDR{ + &CDR{ + CGRID: "88ed9c38005f07576a1e1af293063833b60edcc6", + RunID: "1", + OrderID: 1, + OriginHost: "host1", + OriginID: "1", + CostDetails: &CallCost{Timespans: TimeSpans{}}, + ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"}, + }, + &CDR{ + CGRID: "88ed9c38005f07576a1e1af293063833b60edcc2", + RunID: "2", + OrderID: 2, + OriginHost: "host2", + OriginID: "2", + CostDetails: &CallCost{Timespans: TimeSpans{}}, + ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"}, + }, + } + for _, cdr := range snd { + if err := storDB.SetCDR(cdr, false); err != nil { + t.Error(err) + } + } + + // READ + if rcv, _, err := storDB.GetCDRs(&filter, false); err != nil { + t.Error(err) + } else { + if !(reflect.DeepEqual(snd[0].CGRID, rcv[0].CGRID) || reflect.DeepEqual(snd[0].CGRID, rcv[1].CGRID)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].CGRID, rcv[0].CGRID, rcv[1].CGRID) + } + if !(reflect.DeepEqual(snd[0].RunID, rcv[0].RunID) || reflect.DeepEqual(snd[0].RunID, rcv[1].RunID)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].RunID, rcv[0].RunID, rcv[1].RunID) + } + if !(reflect.DeepEqual(snd[0].OrderID, rcv[0].OrderID) || reflect.DeepEqual(snd[0].OrderID, rcv[1].OrderID)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].OrderID, rcv[0].OrderID, rcv[1].OrderID) + } + if !(reflect.DeepEqual(snd[0].OriginHost, rcv[0].OriginHost) || reflect.DeepEqual(snd[0].OriginHost, rcv[1].OriginHost)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].OriginHost, rcv[0].OriginHost, rcv[1].OriginHost) + } + if !(reflect.DeepEqual(snd[0].Source, rcv[0].Source) || reflect.DeepEqual(snd[0].Source, rcv[1].Source)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Source, rcv[0].Source, rcv[1].Source) + } + if !(reflect.DeepEqual(snd[0].OriginID, rcv[0].OriginID) || reflect.DeepEqual(snd[0].OriginID, rcv[1].OriginID)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].OriginID, rcv[0].OriginID, rcv[1].OriginID) + } + if !(reflect.DeepEqual(snd[0].ToR, rcv[0].ToR) || reflect.DeepEqual(snd[0].ToR, rcv[1].ToR)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].ToR, rcv[0].ToR, rcv[1].ToR) + } + if !(reflect.DeepEqual(snd[0].RequestType, rcv[0].RequestType) || reflect.DeepEqual(snd[0].RequestType, rcv[1].RequestType)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].RequestType, rcv[0].RequestType, rcv[1].RequestType) + } + if !(reflect.DeepEqual(snd[0].Direction, rcv[0].Direction) || reflect.DeepEqual(snd[0].Direction, rcv[1].Direction)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Direction, rcv[0].Direction, rcv[1].Direction) + } + if !(reflect.DeepEqual(snd[0].Tenant, rcv[0].Tenant) || reflect.DeepEqual(snd[0].Tenant, rcv[1].Tenant)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Tenant, rcv[0].Tenant, rcv[1].Tenant) + } + if !(reflect.DeepEqual(snd[0].Category, rcv[0].Category) || reflect.DeepEqual(snd[0].Category, rcv[1].Category)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Category, rcv[0].Category, rcv[1].Category) + } + if !(reflect.DeepEqual(snd[0].Account, rcv[0].Account) || reflect.DeepEqual(snd[0].Account, rcv[1].Account)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Account, rcv[0].Account, rcv[1].Account) + } + if !(reflect.DeepEqual(snd[0].Subject, rcv[0].Subject) || reflect.DeepEqual(snd[0].Subject, rcv[1].Subject)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Subject, rcv[0].Subject, rcv[1].Subject) + } + if !(reflect.DeepEqual(snd[0].Destination, rcv[0].Destination) || reflect.DeepEqual(snd[0].Destination, rcv[1].Destination)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Destination, rcv[0].Destination, rcv[1].Destination) + } + if !(snd[0].SetupTime.Equal(rcv[0].SetupTime) || snd[0].SetupTime.Equal(rcv[1].SetupTime)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].SetupTime, rcv[0].SetupTime, rcv[1].SetupTime) + } + if !(reflect.DeepEqual(snd[0].PDD, rcv[0].PDD) || reflect.DeepEqual(snd[0].PDD, rcv[1].PDD)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].PDD, rcv[0].PDD, rcv[1].PDD) + } + if !(snd[0].AnswerTime.Equal(rcv[0].AnswerTime) || snd[0].AnswerTime.Equal(rcv[1].AnswerTime)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].AnswerTime, rcv[0].AnswerTime, rcv[1].AnswerTime) + } + if !(reflect.DeepEqual(snd[0].Usage, rcv[0].Usage) || reflect.DeepEqual(snd[0].Usage, rcv[1].Usage)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Usage, rcv[0].Usage, rcv[1].Usage) + } + if !(reflect.DeepEqual(snd[0].Supplier, rcv[0].Supplier) || reflect.DeepEqual(snd[0].Supplier, rcv[1].Supplier)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Supplier, rcv[0].Supplier, rcv[1].Supplier) + } + if !(reflect.DeepEqual(snd[0].DisconnectCause, rcv[0].DisconnectCause) || reflect.DeepEqual(snd[0].DisconnectCause, rcv[1].DisconnectCause)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].DisconnectCause, rcv[0].DisconnectCause, rcv[1].DisconnectCause) + } + if !(reflect.DeepEqual(snd[0].ExtraFields, rcv[0].ExtraFields) || reflect.DeepEqual(snd[0].ExtraFields, rcv[1].ExtraFields)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].ExtraFields, rcv[0].ExtraFields, rcv[1].ExtraFields) + } + if !(reflect.DeepEqual(snd[0].CostSource, rcv[0].CostSource) || reflect.DeepEqual(snd[0].CostSource, rcv[1].CostSource)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].CostSource, rcv[0].CostSource, rcv[1].CostSource) + } + if !(reflect.DeepEqual(snd[0].Cost, rcv[0].Cost) || reflect.DeepEqual(snd[0].Cost, rcv[1].Cost)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Cost, rcv[0].Cost, rcv[1].Cost) + } + if !(reflect.DeepEqual(snd[0].CostDetails, rcv[0].CostDetails) || reflect.DeepEqual(snd[0].CostDetails, rcv[1].CostDetails)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].CostDetails, rcv[0].CostDetails, rcv[1].CostDetails) + } + if !(reflect.DeepEqual(snd[0].AccountSummary, rcv[0].AccountSummary) || reflect.DeepEqual(snd[0].AccountSummary, rcv[1].AccountSummary)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].AccountSummary, rcv[0].AccountSummary, rcv[1].AccountSummary) + } + if !(reflect.DeepEqual(snd[0].ExtraInfo, rcv[0].ExtraInfo) || reflect.DeepEqual(snd[0].ExtraInfo, rcv[1].ExtraInfo)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].ExtraInfo, rcv[0].ExtraInfo, rcv[1].ExtraInfo) + } + if !(reflect.DeepEqual(snd[0].Rated, rcv[0].Rated) || reflect.DeepEqual(snd[0].Rated, rcv[1].Rated)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Rated, rcv[0].Rated, rcv[1].Rated) + } + if !(reflect.DeepEqual(snd[0].Partial, rcv[0].Partial) || reflect.DeepEqual(snd[0].Partial, rcv[1].Partial)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Partial, rcv[0].Partial, rcv[1].Partial) + } + } + // UPDATE + snd[0].OriginHost = "host3" + snd[1].OriginHost = "host3" + for _, cdr := range snd { + if err := storDB.SetCDR(cdr, true); err != nil { + t.Error(err) + } + } + // READ + if rcv, _, err := storDB.GetCDRs(&filter, false); err != nil { + t.Error(err) + } else { + if !(reflect.DeepEqual(snd[0].OriginHost, rcv[0].OriginHost) || reflect.DeepEqual(snd[0].OriginHost, rcv[1].OriginHost)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].OriginHost, rcv[0].OriginHost, rcv[1].OriginHost) + } + } + // REMOVE + if _, _, err := storDB.GetCDRs(&filter, true); err != nil { + t.Error(err) + } + // READ + if _, _, err := storDB.GetCDRs(&filter, false); err != utils.ErrNotFound { + t.Error(err) + } +} + +func testStorDBitCRUDSMCosts(t *testing.T) { + // READ + if _, err := storDB.GetSMCosts("", "", "", ""); err != utils.ErrNotFound { + t.Error(err) + } + // WRITE + var snd = []*SMCost{ + &SMCost{ + CGRID: "88ed9c38005f07576a1e1af293063833b60edcc6", + RunID: "1", + OriginHost: "host2", + OriginID: "2", + CostDetails: &CallCost{Timespans: TimeSpans{}}, + }, + &SMCost{ + CGRID: "88ed9c38005f07576a1e1af293063833b60edcc2", + RunID: "2", + OriginHost: "host2", + OriginID: "2", + CostDetails: &CallCost{Timespans: TimeSpans{}}, + }, + } + for _, smc := range snd { + if err := storDB.SetSMCost(smc); err != nil { + t.Error(err) + } + } + // READ + if rcv, err := storDB.GetSMCosts("", "", "host2", ""); err != nil { + t.Error(err) + } else { + if !(reflect.DeepEqual(snd[0].CGRID, rcv[0].CGRID) || reflect.DeepEqual(snd[0].CGRID, rcv[1].CGRID)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].CGRID, rcv[0].CGRID, rcv[1].CGRID) + } + if !(reflect.DeepEqual(snd[0].RunID, rcv[0].RunID) || reflect.DeepEqual(snd[0].RunID, rcv[1].RunID)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].RunID, rcv[0].RunID, rcv[1].RunID) + } + if !(reflect.DeepEqual(snd[0].OriginHost, rcv[0].OriginHost) || reflect.DeepEqual(snd[0].OriginHost, rcv[1].OriginHost)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].OriginHost, rcv[0].OriginHost, rcv[1].OriginHost) + } + if !(reflect.DeepEqual(snd[0].OriginID, rcv[0].OriginID) || reflect.DeepEqual(snd[0].OriginID, rcv[1].OriginID)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].OriginID, rcv[0].OriginID, rcv[1].OriginID) + } + if !(reflect.DeepEqual(snd[0].CostDetails, rcv[0].CostDetails) || reflect.DeepEqual(snd[0].CostDetails, rcv[1].CostDetails)) { + t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].CostDetails, rcv[0].CostDetails, rcv[1].CostDetails) + } + } + // REMOVE + for _, smc := range snd { + if err := storDB.RemoveSMCost(smc); err != nil { + t.Error(err) + } + } + // READ + if _, err := storDB.GetSMCosts("", "", "", ""); err != utils.ErrNotFound { + t.Error(err) + } } func testStorDBitFlush(t *testing.T) { @@ -1400,7 +1724,7 @@ func testStorDBitFlush(t *testing.T) { func testStorDBitCRUDVersions(t *testing.T) { // CREATE vrs := Versions{utils.COST_DETAILS: 1} - if err := storDB.SetVersions(vrs); err != nil { + if err := storDB.SetVersions(vrs, true); err != nil { t.Error(err) } if rcv, err := storDB.GetVersions(""); err != nil { @@ -1408,9 +1732,10 @@ func testStorDBitCRUDVersions(t *testing.T) { } else if !reflect.DeepEqual(vrs, rcv) { t.Errorf("Expecting: %+v, received: %+v", vrs, rcv) } + // UPDATE vrs = Versions{utils.COST_DETAILS: 2, "OTHER_KEY": 1} - if err := storDB.SetVersions(vrs); err != nil { + if err := storDB.SetVersions(vrs, false); err != nil { t.Error(err) } if rcv, err := storDB.GetVersions(""); err != nil { @@ -1418,6 +1743,7 @@ func testStorDBitCRUDVersions(t *testing.T) { } else if !reflect.DeepEqual(vrs, rcv) { t.Errorf("Expecting: %+v, received: %+v", vrs, rcv) } + // REMOVE vrs = Versions{"OTHER_KEY": 1} if err := storDB.RemoveVersions(vrs); err != nil { @@ -1443,4 +1769,5 @@ func testStorDBitCRUDVersions(t *testing.T) { } else if len(rcv) != 0 { t.Errorf("Received: %+v", rcv) } + } diff --git a/utils/consts.go b/utils/consts.go index c0012be2b..849596b96 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -71,8 +71,8 @@ const ( TBL_TP_DERIVED_CHARGERS = "tp_derived_chargers" TBL_TP_USERS = "tp_users" TBL_TP_ALIASES = "tp_aliases" - TBLSMCosts = "sm_costs" TBLTPResourceLimits = "tp_resource_limits" + TBLSMCosts = "sm_costs" TBL_CDRS = "cdrs" TBLVersions = "versions" TIMINGS_CSV = "Timings.csv"