diff --git a/apier/v1/preload_it_test.go b/apier/v1/preload_it_test.go index 4639eafc4..49f796f32 100644 --- a/apier/v1/preload_it_test.go +++ b/apier/v1/preload_it_test.go @@ -74,7 +74,12 @@ func testCreateDirs(t *testing.T) { t.Fatal("Error creating folder: ", dir, err) } } - if err := os.WriteFile(path.Join("/tmp/In", utils.AttributesCsv), []byte(engine.AttributesCSVContent), 0644); err != nil { + + if err := os.WriteFile(path.Join("/tmp/In", utils.AttributesCsv), []byte(` +#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight +cgrates.org,ALS1,con1,*string:~*req.Account:1001,2014-07-29T15:00:00Z,*string:~*req.Field1:Initial,*req.Field1,*variable,Sub1,true,20 +cgrates.org,ALS1,con2;con3,,,,*req.Field2,*variable,Sub2,true,20 +`), 0644); err != nil { t.Fatal(err.Error()) } } diff --git a/engine/libtest.go b/engine/libtest.go index d1f5a95cb..d9adc2e05 100644 --- a/engine/libtest.go +++ b/engine/libtest.go @@ -20,16 +20,20 @@ package engine import ( "bytes" - "context" + "errors" "fmt" "io" "os" "os/exec" "path" + "path/filepath" "slices" "strings" + "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" @@ -37,261 +41,6 @@ import ( "github.com/creack/pty" ) -var ( - DestinationsCSVContent = ` -#Tag,Prefix -GERMANY,49 -GERMANY_O2,41 -GERMANY_PREMIUM,43 -ALL,49 -ALL,41 -ALL,43 -NAT,0256 -NAT,0257 -NAT,0723 -NAT,+49 -RET,0723 -RET,0724 -SPEC,0723045 -PSTN_71,+4971 -PSTN_72,+4972 -PSTN_70,+4970 -DST_UK_Mobile_BIG5,447956 -URG,112 -EU_LANDLINE,444 -EXOTIC,999 -` - TimingsCSVContent = ` -WORKDAYS_00,*any,*any,*any,1;2;3;4;5,00:00:00 -WORKDAYS_18,*any,*any,*any,1;2;3;4;5,18:00:00 -WEEKENDS,*any,*any,*any,6;7,00:00:00 -ONE_TIME_RUN,2012,,,,*asap -` - RatesCSVContent = ` -R1,0,0.2,60s,1s,0s -R2,0,0.1,60s,1s,0s -R3,0,0.05,60s,1s,0s -R4,1,1,1s,1s,0s -R5,0,0.5,1s,1s,0s -LANDLINE_OFFPEAK,0,1,1s,60s,0s -LANDLINE_OFFPEAK,0,1,1s,1s,60s -GBP_71,0.000000,5.55555,1s,1s,0s -GBP_72,0.000000,7.77777,1s,1s,0s -GBP_70,0.000000,1,1s,1s,0s -RT_UK_Mobile_BIG5_PKG,0.01,0,20s,20s,0s -RT_UK_Mobile_BIG5,0.01,0.10,1s,1s,0s -R_URG,0,0,1s,1s,0s -MX,0,1,1s,1s,0s -DY,0.15,0.05,60s,1s,0s -CF,1.12,0,1s,1s,0s -` - DestinationRatesCSVContent = ` -RT_STANDARD,GERMANY,R1,*middle,4,0, -RT_STANDARD,GERMANY_O2,R2,*middle,4,0, -RT_STANDARD,GERMANY_PREMIUM,R2,*middle,4,0, -RT_DEFAULT,ALL,R2,*middle,4,0, -RT_STD_WEEKEND,GERMANY,R2,*middle,4,0, -RT_STD_WEEKEND,GERMANY_O2,R3,*middle,4,0, -P1,NAT,R4,*middle,4,0, -P2,NAT,R5,*middle,4,0, -T1,NAT,LANDLINE_OFFPEAK,*middle,4,0, -T2,GERMANY,GBP_72,*middle,4,0, -T2,GERMANY_O2,GBP_70,*middle,4,0, -T2,GERMANY_PREMIUM,GBP_71,*middle,4,0, -GER,GERMANY,R4,*middle,4,0, -DR_UK_Mobile_BIG5_PKG,DST_UK_Mobile_BIG5,RT_UK_Mobile_BIG5_PKG,*middle,4,, -DR_UK_Mobile_BIG5,DST_UK_Mobile_BIG5,RT_UK_Mobile_BIG5,*middle,4,, -DATA_RATE,*any,LANDLINE_OFFPEAK,*middle,4,0, -RT_URG,URG,R_URG,*middle,4,0, -MX_FREE,RET,MX,*middle,4,10,*free -MX_DISC,RET,MX,*middle,4,10,*disconnect -RT_DY,RET,DY,*up,2,0, -RT_DY,EU_LANDLINE,CF,*middle,4,0, -` - RatingPlansCSVContent = ` -STANDARD,RT_STANDARD,WORKDAYS_00,10 -STANDARD,RT_STD_WEEKEND,WORKDAYS_18,10 -STANDARD,RT_STD_WEEKEND,WEEKENDS,10 -STANDARD,RT_URG,*any,20 -PREMIUM,RT_STANDARD,WORKDAYS_00,10 -PREMIUM,RT_STD_WEEKEND,WORKDAYS_18,10 -PREMIUM,RT_STD_WEEKEND,WEEKENDS,10 -DEFAULT,RT_DEFAULT,WORKDAYS_00,10 -EVENING,P1,WORKDAYS_00,10 -EVENING,P2,WORKDAYS_18,10 -EVENING,P2,WEEKENDS,10 -TDRT,T1,WORKDAYS_00,10 -TDRT,T2,WORKDAYS_00,10 -G,RT_STANDARD,WORKDAYS_00,10 -R,P1,WORKDAYS_00,10 -RP_UK_Mobile_BIG5_PKG,DR_UK_Mobile_BIG5_PKG,*any,10 -RP_UK,DR_UK_Mobile_BIG5,*any,10 -RP_DATA,DATA_RATE,*any,10 -RP_MX,MX_DISC,WORKDAYS_00,10 -RP_MX,MX_FREE,WORKDAYS_18,10 -GER_ONLY,GER,*any,10 -ANY_PLAN,DATA_RATE,*any,10 -DY_PLAN,RT_DY,*any,10 -` - RatingProfilesCSVContent = ` -CUSTOMER_1,0,rif:from:tm,2012-01-01T00:00:00Z,PREMIUM,danb -CUSTOMER_1,0,rif:from:tm,2012-02-28T00:00:00Z,STANDARD,danb -CUSTOMER_2,0,danb:87.139.12.167,2012-01-01T00:00:00Z,STANDARD,danb -CUSTOMER_1,0,danb,2012-01-01T00:00:00Z,PREMIUM, -vdf,0,rif,2012-01-01T00:00:00Z,EVENING, -vdf,call,rif,2012-02-28T00:00:00Z,EVENING, -vdf,call,dan,2012-01-01T00:00:00Z,EVENING, -vdf,0,minu,2012-01-01T00:00:00Z,EVENING, -vdf,0,*any,2012-02-28T00:00:00Z,EVENING, -vdf,0,one,2012-02-28T00:00:00Z,STANDARD, -vdf,0,inf,2012-02-28T00:00:00Z,STANDARD,inf -vdf,0,fall,2012-02-28T00:00:00Z,PREMIUM,rif -test,0,trp,2013-10-01T00:00:00Z,TDRT,rif;danb -vdf,0,fallback1,2013-11-18T13:45:00Z,G,fallback2 -vdf,0,fallback1,2013-11-18T13:46:00Z,G,fallback2 -vdf,0,fallback1,2013-11-18T13:47:00Z,G,fallback2 -vdf,0,fallback2,2013-11-18T13:45:00Z,R,rif -cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_UK, -cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG, -cgrates.org,data,rif,2013-01-06T00:00:00Z,RP_DATA, -cgrates.org,call,max,2013-03-23T00:00:00Z,RP_MX, -cgrates.org,call,nt,2012-02-28T00:00:00Z,GER_ONLY, -cgrates.org,LCR_STANDARD,max,2013-03-23T00:00:00Z,RP_MX, -cgrates.org,call,money,2015-02-28T00:00:00Z,EVENING, -cgrates.org,call,dy,2015-02-28T00:00:00Z,DY_PLAN, -cgrates.org,call,block,2015-02-28T00:00:00Z,DY_PLAN, -cgrates.org,call,round,2016-06-30T00:00:00Z,DEFAULT, -` - SharedGroupsCSVContent = ` -SG1,*any,*lowest, -SG2,*any,*lowest,one -SG3,*any,*lowest, -` - ActionsCSVContent = ` -MINI,*topup_reset,,,,*monetary,,,,,*unlimited,,10,10,false,false,10 -MINI,*topup,,,,*voice,,NAT,test,,*unlimited,,100s,10,false,false,10 -SHARED,*topup,,,,*monetary,,,,SG1,*unlimited,,100,10,false,false,10 -TOPUP10_AC,*topup_reset,,,,*monetary,,*any,,,*unlimited,,1,10,false,false,10 -TOPUP10_AC1,*topup_reset,,,,*voice,,DST_UK_Mobile_BIG5,discounted_minutes,,*unlimited,,40s,10,false,false,10 -SE0,*topup_reset,,,,*monetary,,,,SG2,*unlimited,,0,10,false,false,10 -SE10,*topup_reset,,,,*monetary,,,,SG2,*unlimited,,10,5,false,false,10 -SE10,*topup,,,,*monetary,,,,,*unlimited,,10,10,false,false,10 -EE0,*topup_reset,,,,*monetary,,,,SG3,*unlimited,,0,10,false,false,10 -EE0,*allow_negative,,,,*monetary,,,,,*unlimited,,0,10,false,false,10 -DEFEE,*cdrlog,"{""Category"":""^ddi"",""MediationRunId"":""^did_run""}",,,,,,,,,,,,false,false,10 -NEG,*allow_negative,,,,*monetary,,,,,*unlimited,,0,10,false,false,10 -BLOCK,*topup,,,bblocker,*monetary,,NAT,,,*unlimited,,1,20,true,false,20 -BLOCK,*topup,,,bfree,*monetary,,,,,*unlimited,,20,10,false,false,10 -BLOCK_EMPTY,*topup,,,bblocker,*monetary,,NAT,,,*unlimited,,0,20,true,false,20 -BLOCK_EMPTY,*topup,,,bfree,*monetary,,,,,*unlimited,,20,10,false,false,10 -FILTER,*topup,,*string:~*req.BalanceMap.*monetary[0].ID:*default;*lt:~*req.BalanceMap.*monetary[0].Value:0,bfree,*monetary,,,,,*unlimited,,20,10,false,false,10 -EXP,*topup,,,,*voice,,,,,*monthly,*any,300s,10,false,false,10 -NOEXP,*topup,,,,*voice,,,,,*unlimited,*any,50s,10,false,false,10 -VF,*debit,,,,*monetary,,,,,*unlimited,*any,"{""Method"":""*incremental"",""Params"":{""Units"":10, ""Interval"":""month"", ""Increment"":""day""}}",10,false,false,10 -TOPUP_RST_GNR_1000,*topup_reset,"{""*voice"": 60.0,""*data"":1024.0,""*sms"":1.0}",,,*generic,,*any,,,*unlimited,,1000,20,false,false,10 -` - ActionPlansCSVContent = ` -MORE_MINUTES,MINI,ONE_TIME_RUN,10 -MORE_MINUTES,SHARED,ONE_TIME_RUN,10 -TOPUP10_AT,TOPUP10_AC,*asap,10 -TOPUP10_AT,TOPUP10_AC1,*asap,10 -TOPUP_SHARED0_AT,SE0,*asap,10 -TOPUP_SHARED10_AT,SE10,*asap,10 -TOPUP_EMPTY_AT,EE0,*asap,10 -POST_AT,NEG,*asap,10 -BLOCK_AT,BLOCK,*asap,10 -BLOCK_EMPTY_AT,BLOCK_EMPTY,*asap,10 -EXP_AT,EXP,*asap,10 -` - - ActionTriggersCSVContent = ` -STANDARD_TRIGGER,st0,*min_event_counter,10,false,0,,,,*voice,,GERMANY_O2,,,,,,,,SOME_1,10 -STANDARD_TRIGGER,st1,*max_balance,200,false,0,,,,*voice,,GERMANY,,,,,,,,SOME_2,10 -STANDARD_TRIGGERS,,*min_balance,2,false,0,,,,*monetary,,,,,,,,,,LOG_WARNING,10 -STANDARD_TRIGGERS,,*max_balance,20,false,0,,,,*monetary,,,,,,,,,,LOG_WARNING,10 -STANDARD_TRIGGERS,,*max_event_counter,5,false,0,,,,*monetary,,FS_USERS,,,,,,,,LOG_WARNING,10 -` - AccountActionsCSVContent = ` -vdf,minitsboy,MORE_MINUTES,STANDARD_TRIGGER,, -cgrates.org,12345,TOPUP10_AT,STANDARD_TRIGGERS,, -cgrates.org,123456,TOPUP10_AT,STANDARD_TRIGGERS,, -cgrates.org,dy,TOPUP10_AT,STANDARD_TRIGGERS,, -cgrates.org,remo,TOPUP10_AT,,, -vdf,empty0,TOPUP_SHARED0_AT,,, -vdf,empty10,TOPUP_SHARED10_AT,,, -vdf,emptyX,TOPUP_EMPTY_AT,,, -vdf,emptyY,TOPUP_EMPTY_AT,,, -vdf,post,POST_AT,,, -cgrates.org,alodis,TOPUP_EMPTY_AT,,true,true -cgrates.org,block,BLOCK_AT,,false,false -cgrates.org,block_empty,BLOCK_EMPTY_AT,,false,false -cgrates.org,expo,EXP_AT,,false,false -cgrates.org,expnoexp,,,false,false -cgrates.org,vf,,,false,false -cgrates.org,round,TOPUP10_AT,,false,false -` - ResourcesCSVContent = ` -#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],TTL[4],Limit[5],AllocationMessage[6],Blocker[7],Stored[8],Weight[9],Thresholds[10] -cgrates.org,ResGroup21,*string:~*req.Account:1001,2014-07-29T15:00:00Z,1s,2,call,true,true,10, -cgrates.org,ResGroup22,*string:~*req.Account:dan,2014-07-29T15:00:00Z,3600s,2,premium_call,true,true,10, -` - StatsCSVContent = ` -#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],QueueLength[4],TTL[5],MinItems[6],Metrics[7],MetricFilterIDs[8],Stored[9],Blocker[10],Weight[11],ThresholdIDs[12] -cgrates.org,TestStats,*string:~*req.Account:1001,2014-07-29T15:00:00Z,100,1s,2,*sum#~*req.Value;*average#~*req.Value,,true,true,20,Th1;Th2 -cgrates.org,TestStats,,,,,2,*sum#~*req.Usage,,true,true,20, -cgrates.org,TestStats2,FLTR_1,2014-07-29T15:00:00Z,100,1s,2,*sum#~*req.Value;*sum#~*req.Usage;*average#~*req.Value;*average#~*req.Usage,,true,true,20,Th -cgrates.org,TestStats2,,,,,2,*sum#~*req.Cost;*average#~*req.Cost,,true,true,20, -` - RankingsCSVContent = ` -#Tenant[0],Id[1],QueryInterval[2],StatIDs[2],MetricIDs[3],Sorting[4],SortingParameters[5],ThresholdIDs[6] -cgrates.org,Ranking1,15m,Stats2;Stats3;Stats4,Metric1;Metric3,*asc,,THD1;THD2 -` - TrendsCSVContent = ` -#Tenant[0],Id[1],Schedule[2],StatID[3],Metrics[4],TTL[5],QueueLength[6],MinItems[7],CorrelationType[8],Tolerance[9],Stored[10],ThresholdIDs[11] -cgrates.org,TREND1,0 12 * * *,Stats2,*acc;*tcc,-1,-1,1,*average,2.1,true,TD1;TD2 -` - ThresholdsCSVContent = ` -#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],MaxHits[4],MinHits[5],MinSleep[6],Blocker[7],Weight[8],ActionIDs[9],Async[10] -cgrates.org,Threshold1,*string:~*req.Account:1001;*string:~*req.RunID:*default,2014-07-29T15:00:00Z,12,10,1s,true,10,THRESH1,true -` - - FiltersCSVContent = ` -#Tenant[0],ID[1],Type[2],Element[3],Values[4],ActivationInterval[5] -cgrates.org,FLTR_1,*string,~*req.Account,1001;1002,2014-07-29T15:00:00Z -cgrates.org,FLTR_1,*prefix,~*req.Destination,10;20,2014-07-29T15:00:00Z -cgrates.org,FLTR_1,*rsr,~*req.Subject,~^1.*1$, -cgrates.org,FLTR_1,*rsr,~*req.Destination,1002, -cgrates.org,FLTR_ACNT_dan,*string,~*req.Account,dan,2014-07-29T15:00:00Z -cgrates.org,FLTR_DST_DE,*destinations,~*req.Destination,DST_DE,2014-07-29T15:00:00Z -cgrates.org,FLTR_DST_NL,*destinations,~*req.Destination,DST_NL,2014-07-29T15:00:00Z -` - RoutesCSVContent = ` -#Tenant[0],ID[1],FilterIDs[2],ActivationInterval[3],Sorting[4],SortingParameters[5],RouteID[6],RouteFilterIDs[7],RouteAccountIDs[8],RouteRatingPlanIDs[9],RouteResourceIDs[10],RouteStatIDs[11],RouteWeight[12],RouteBlocker[13],RouteParameters[14],Weight[15] -cgrates.org,RoutePrf1,*string:~*req.Account:dan,2014-07-29T15:00:00Z,*lc,,route1,FLTR_ACNT_dan,Account1;Account1_1,RPL_1,ResGroup1,Stat1,10,true,param1,20 -cgrates.org,RoutePrf1,,,,,route1,,,RPL_2,ResGroup2,,10,,, -cgrates.org,RoutePrf1,,,,,route1,FLTR_DST_DE,Account2,RPL_3,ResGroup3,Stat2,10,,, -cgrates.org,RoutePrf1,,,,,route1,,,,ResGroup4,Stat3,10,,, -` - AttributesCSVContent = ` -#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight -cgrates.org,ALS1,con1,*string:~*req.Account:1001,2014-07-29T15:00:00Z,*string:~*req.Field1:Initial,*req.Field1,*variable,Sub1,true,20 -cgrates.org,ALS1,con2;con3,,,,*req.Field2,*variable,Sub2,true,20 -` - ChargersCSVContent = ` -#Tenant,ID,FilterIDs,ActivationInterval,RunID,AttributeIDs,Weight -cgrates.org,Charger1,*string:~*req.Account:1001,2014-07-29T15:00:00Z,*rated,ATTR_1001_SIMPLEAUTH,20 -` - DispatcherCSVContent = ` -#Tenant,ID,FilterIDs,ActivationInterval,Strategy,Hosts,Weight -cgrates.org,D1,*any,*string:~*req.Account:1001,2014-07-29T15:00:00Z,*first,,C1,*gt:~*req.Usage:10,10,false,192.168.56.203,20 -cgrates.org,D1,,,,*first,,C2,*lt:~*req.Usage:10,10,false,192.168.56.204, -` - DispatcherHostCSVContent = ` -#Tenant[0],ID[1],Address[2],Transport[3],ConnectAttempts[4],Reconnects[5],MaxReconnectInterval[6],ConnectTimeout[7],ReplyTimeout[8],Tls[9],ClientKey[10],ClientCertificate[11],CaCertificate[12] -cgrates.org,ALL,127.0.0.1:6012,*json,1,3,5m,1m,2m,false,,, -` -) - func InitDataDb(cfg *config.CGRConfig) error { d, err := NewDataDBConn(cfg.DataDbCfg().Type, cfg.DataDbCfg().Host, cfg.DataDbCfg().Port, @@ -599,3 +348,182 @@ func LoadAllDataDBToCache(dm *DataManager) (err error) { } return } + +func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { + switch *utils.Encoding { + case utils.MetaJSON: + return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) + case utils.MetaGOB: + return birpc.Dial(utils.TCP, cfg.RPCGOBListen) + default: + return nil, errors.New("UNSUPPORTED_RPC") + } +} + +// TestEngine holds the setup parameters and configurations +// required for running integration tests. +type TestEngine struct { + ConfigPath string // path to the main configuration file + ConfigJSON string // configuration JSON content (used if ConfigPath is empty) + LogBuffer io.Writer // captures log output of the test environment + PreserveDataDB bool // prevents automatic data_db flush when set + PreserveStorDB bool // prevents automatic stor_db flush when set + TpPath string // path to the tariff plans + TpFiles map[string]string // CSV data for tariff plans: filename -> content + + // PreStartHook executes custom logic relying on CGRConfig + // before starting cgr-engine. + PreStartHook func(*testing.T, *config.CGRConfig) +} + +// Run initializes a cgr-engine instance for testing, loads tariff plans (if available) and returns +// an RPC client and the CGRConfig object. It calls t.Fatal on any setup failure. +func (ng TestEngine) Run(t *testing.T) (*birpc.Client, *config.CGRConfig) { + t.Helper() + + // Parse config files. + var cfgPath string + switch { + case ng.ConfigJSON != "": + cfgPath = t.TempDir() + filePath := filepath.Join(cfgPath, "cgrates.json") + if err := os.WriteFile(filePath, []byte(ng.ConfigJSON), 0644); err != nil { + t.Fatal(err) + } + case ng.ConfigPath != "": + cfgPath = ng.ConfigPath + default: + t.Fatal("missing config source") + } + cfg, err := config.NewCGRConfigFromPath(cfgPath) + if err != nil { + t.Fatalf("could not init config from path %s: %v", cfgPath, err) + } + + flushDBs(t, cfg, !ng.PreserveDataDB, !ng.PreserveStorDB) + + if ng.PreStartHook != nil { + ng.PreStartHook(t, cfg) + } + + startEngine(t, cfg, ng.LogBuffer) + + client, err := newRPCClient(cfg.ListenCfg()) + if err != nil { + t.Fatalf("could not connect to cgr-engine: %v", err) + } + + var customTpPath string + if len(ng.TpFiles) != 0 { + customTpPath = t.TempDir() + } + LoadCSVs(t, client, ng.TpPath, customTpPath, ng.TpFiles) + + return client, cfg +} + +// LoadCSVs loads tariff plan data from CSV files into the service. It handles directory creation and file +// writing for custom paths, and loads data from the specified paths using the provided RPC client. +func LoadCSVs(t *testing.T, client *birpc.Client, tpPath, customTpPath string, csvFiles map[string]string) { + t.Helper() + paths := make([]string, 0, 2) + if customTpPath != "" { + for fileName, content := range csvFiles { + filePath := path.Join(customTpPath, fileName) + if err := os.WriteFile(filePath, []byte(content), 0644); err != nil { + t.Fatalf("could not write to file %s: %v", filePath, err) + } + } + paths = append(paths, customTpPath) + } + if tpPath != "" { + paths = append(paths, tpPath) + } + if len(paths) == 0 { + return + } + + ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond) + defer cancel() + WaitForService(t, ctx, client, utils.APIerSv1) + + var reply string + for _, path := range paths { + args := &utils.AttrLoadTpFromFolder{FolderPath: path} + err := client.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, args, &reply) + if err != nil { + t.Fatalf("%s call failed for path %s: %v", utils.APIerSv1LoadTariffPlanFromFolder, path, err) + } + } +} + +// flushDBs resets the databases specified in the configuration if the corresponding flags are true. +func flushDBs(t *testing.T, cfg *config.CGRConfig, flushDataDB, flushStorDB bool) { + t.Helper() + if flushDataDB { + if err := InitDataDb(cfg); err != nil { + t.Fatalf("failed to flush %s dataDB: %v", cfg.DataDbCfg().Type, err) + } + } + if flushStorDB { + if err := InitStorDb(cfg); err != nil { + t.Fatalf("failed to flush %s storDB: %v", cfg.StorDbCfg().Type, err) + } + } +} + +// startEngine starts the CGR engine process with the provided configuration. It writes engine logs to the +// provided logBuffer (if any). +func startEngine(t *testing.T, cfg *config.CGRConfig, logBuffer io.Writer) { + t.Helper() + binPath, err := exec.LookPath("cgr-engine") + if err != nil { + t.Fatal(err) + } + engine := exec.Command( + binPath, + "-config_path", cfg.ConfigPath, + "-logger", utils.MetaStdLog, + ) + if logBuffer != nil { + engine.Stdout = logBuffer + engine.Stderr = logBuffer + } + if err := engine.Start(); err != nil { + t.Fatalf("cgr-engine command failed: %v", err) + } + t.Cleanup(func() { + if err := engine.Process.Kill(); err != nil { + t.Errorf("failed to kill cgr-engine process (%d): %v", engine.Process.Pid, err) + } + }) + fib := utils.FibDuration(time.Millisecond, 0) + for i := 0; i < 16; i++ { + time.Sleep(fib()) + if _, err := jsonrpc.Dial(utils.TCP, cfg.ListenCfg().RPCJSONListen); err == nil { + break + } + } + if err != nil { + t.Fatalf("starting cgr-engine on port %s failed: %v", cfg.ListenCfg().RPCJSONListen, err) + } +} + +func WaitForService(t *testing.T, ctx *context.Context, client *birpc.Client, service string) { + t.Helper() + method := service + ".Ping" + backoff := utils.FibDuration(time.Millisecond, 0) + var reply any + for { + select { + case <-ctx.Done(): + t.Fatalf("%s service did not become available: %v", service, ctx.Err()) + default: + err := client.Call(context.Background(), method, nil, &reply) + if err == nil && reply == utils.Pong { + return + } + time.Sleep(backoff()) + } + } +} diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 5fab48f05..46031ca9f 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -30,8 +30,260 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" ) -var ( - testTPID = "LoaderCSVTests" +const ( + testTPID = "LoaderCSVTests" + DestinationsCSVContent = ` +#Tag,Prefix +GERMANY,49 +GERMANY_O2,41 +GERMANY_PREMIUM,43 +ALL,49 +ALL,41 +ALL,43 +NAT,0256 +NAT,0257 +NAT,0723 +NAT,+49 +RET,0723 +RET,0724 +SPEC,0723045 +PSTN_71,+4971 +PSTN_72,+4972 +PSTN_70,+4970 +DST_UK_Mobile_BIG5,447956 +URG,112 +EU_LANDLINE,444 +EXOTIC,999 +` + TimingsCSVContent = ` +WORKDAYS_00,*any,*any,*any,1;2;3;4;5,00:00:00 +WORKDAYS_18,*any,*any,*any,1;2;3;4;5,18:00:00 +WEEKENDS,*any,*any,*any,6;7,00:00:00 +ONE_TIME_RUN,2012,,,,*asap +` + RatesCSVContent = ` +R1,0,0.2,60s,1s,0s +R2,0,0.1,60s,1s,0s +R3,0,0.05,60s,1s,0s +R4,1,1,1s,1s,0s +R5,0,0.5,1s,1s,0s +LANDLINE_OFFPEAK,0,1,1s,60s,0s +LANDLINE_OFFPEAK,0,1,1s,1s,60s +GBP_71,0.000000,5.55555,1s,1s,0s +GBP_72,0.000000,7.77777,1s,1s,0s +GBP_70,0.000000,1,1s,1s,0s +RT_UK_Mobile_BIG5_PKG,0.01,0,20s,20s,0s +RT_UK_Mobile_BIG5,0.01,0.10,1s,1s,0s +R_URG,0,0,1s,1s,0s +MX,0,1,1s,1s,0s +DY,0.15,0.05,60s,1s,0s +CF,1.12,0,1s,1s,0s +` + DestinationRatesCSVContent = ` +RT_STANDARD,GERMANY,R1,*middle,4,0, +RT_STANDARD,GERMANY_O2,R2,*middle,4,0, +RT_STANDARD,GERMANY_PREMIUM,R2,*middle,4,0, +RT_DEFAULT,ALL,R2,*middle,4,0, +RT_STD_WEEKEND,GERMANY,R2,*middle,4,0, +RT_STD_WEEKEND,GERMANY_O2,R3,*middle,4,0, +P1,NAT,R4,*middle,4,0, +P2,NAT,R5,*middle,4,0, +T1,NAT,LANDLINE_OFFPEAK,*middle,4,0, +T2,GERMANY,GBP_72,*middle,4,0, +T2,GERMANY_O2,GBP_70,*middle,4,0, +T2,GERMANY_PREMIUM,GBP_71,*middle,4,0, +GER,GERMANY,R4,*middle,4,0, +DR_UK_Mobile_BIG5_PKG,DST_UK_Mobile_BIG5,RT_UK_Mobile_BIG5_PKG,*middle,4,, +DR_UK_Mobile_BIG5,DST_UK_Mobile_BIG5,RT_UK_Mobile_BIG5,*middle,4,, +DATA_RATE,*any,LANDLINE_OFFPEAK,*middle,4,0, +RT_URG,URG,R_URG,*middle,4,0, +MX_FREE,RET,MX,*middle,4,10,*free +MX_DISC,RET,MX,*middle,4,10,*disconnect +RT_DY,RET,DY,*up,2,0, +RT_DY,EU_LANDLINE,CF,*middle,4,0, +` + RatingPlansCSVContent = ` +STANDARD,RT_STANDARD,WORKDAYS_00,10 +STANDARD,RT_STD_WEEKEND,WORKDAYS_18,10 +STANDARD,RT_STD_WEEKEND,WEEKENDS,10 +STANDARD,RT_URG,*any,20 +PREMIUM,RT_STANDARD,WORKDAYS_00,10 +PREMIUM,RT_STD_WEEKEND,WORKDAYS_18,10 +PREMIUM,RT_STD_WEEKEND,WEEKENDS,10 +DEFAULT,RT_DEFAULT,WORKDAYS_00,10 +EVENING,P1,WORKDAYS_00,10 +EVENING,P2,WORKDAYS_18,10 +EVENING,P2,WEEKENDS,10 +TDRT,T1,WORKDAYS_00,10 +TDRT,T2,WORKDAYS_00,10 +G,RT_STANDARD,WORKDAYS_00,10 +R,P1,WORKDAYS_00,10 +RP_UK_Mobile_BIG5_PKG,DR_UK_Mobile_BIG5_PKG,*any,10 +RP_UK,DR_UK_Mobile_BIG5,*any,10 +RP_DATA,DATA_RATE,*any,10 +RP_MX,MX_DISC,WORKDAYS_00,10 +RP_MX,MX_FREE,WORKDAYS_18,10 +GER_ONLY,GER,*any,10 +ANY_PLAN,DATA_RATE,*any,10 +DY_PLAN,RT_DY,*any,10 +` + RatingProfilesCSVContent = ` +CUSTOMER_1,0,rif:from:tm,2012-01-01T00:00:00Z,PREMIUM,danb +CUSTOMER_1,0,rif:from:tm,2012-02-28T00:00:00Z,STANDARD,danb +CUSTOMER_2,0,danb:87.139.12.167,2012-01-01T00:00:00Z,STANDARD,danb +CUSTOMER_1,0,danb,2012-01-01T00:00:00Z,PREMIUM, +vdf,0,rif,2012-01-01T00:00:00Z,EVENING, +vdf,call,rif,2012-02-28T00:00:00Z,EVENING, +vdf,call,dan,2012-01-01T00:00:00Z,EVENING, +vdf,0,minu,2012-01-01T00:00:00Z,EVENING, +vdf,0,*any,2012-02-28T00:00:00Z,EVENING, +vdf,0,one,2012-02-28T00:00:00Z,STANDARD, +vdf,0,inf,2012-02-28T00:00:00Z,STANDARD,inf +vdf,0,fall,2012-02-28T00:00:00Z,PREMIUM,rif +test,0,trp,2013-10-01T00:00:00Z,TDRT,rif;danb +vdf,0,fallback1,2013-11-18T13:45:00Z,G,fallback2 +vdf,0,fallback1,2013-11-18T13:46:00Z,G,fallback2 +vdf,0,fallback1,2013-11-18T13:47:00Z,G,fallback2 +vdf,0,fallback2,2013-11-18T13:45:00Z,R,rif +cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_UK, +cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG, +cgrates.org,data,rif,2013-01-06T00:00:00Z,RP_DATA, +cgrates.org,call,max,2013-03-23T00:00:00Z,RP_MX, +cgrates.org,call,nt,2012-02-28T00:00:00Z,GER_ONLY, +cgrates.org,LCR_STANDARD,max,2013-03-23T00:00:00Z,RP_MX, +cgrates.org,call,money,2015-02-28T00:00:00Z,EVENING, +cgrates.org,call,dy,2015-02-28T00:00:00Z,DY_PLAN, +cgrates.org,call,block,2015-02-28T00:00:00Z,DY_PLAN, +cgrates.org,call,round,2016-06-30T00:00:00Z,DEFAULT, +` + SharedGroupsCSVContent = ` +SG1,*any,*lowest, +SG2,*any,*lowest,one +SG3,*any,*lowest, +` + ActionsCSVContent = ` +MINI,*topup_reset,,,,*monetary,,,,,*unlimited,,10,10,false,false,10 +MINI,*topup,,,,*voice,,NAT,test,,*unlimited,,100s,10,false,false,10 +SHARED,*topup,,,,*monetary,,,,SG1,*unlimited,,100,10,false,false,10 +TOPUP10_AC,*topup_reset,,,,*monetary,,*any,,,*unlimited,,1,10,false,false,10 +TOPUP10_AC1,*topup_reset,,,,*voice,,DST_UK_Mobile_BIG5,discounted_minutes,,*unlimited,,40s,10,false,false,10 +SE0,*topup_reset,,,,*monetary,,,,SG2,*unlimited,,0,10,false,false,10 +SE10,*topup_reset,,,,*monetary,,,,SG2,*unlimited,,10,5,false,false,10 +SE10,*topup,,,,*monetary,,,,,*unlimited,,10,10,false,false,10 +EE0,*topup_reset,,,,*monetary,,,,SG3,*unlimited,,0,10,false,false,10 +EE0,*allow_negative,,,,*monetary,,,,,*unlimited,,0,10,false,false,10 +DEFEE,*cdrlog,"{""Category"":""^ddi"",""MediationRunId"":""^did_run""}",,,,,,,,,,,,false,false,10 +NEG,*allow_negative,,,,*monetary,,,,,*unlimited,,0,10,false,false,10 +BLOCK,*topup,,,bblocker,*monetary,,NAT,,,*unlimited,,1,20,true,false,20 +BLOCK,*topup,,,bfree,*monetary,,,,,*unlimited,,20,10,false,false,10 +BLOCK_EMPTY,*topup,,,bblocker,*monetary,,NAT,,,*unlimited,,0,20,true,false,20 +BLOCK_EMPTY,*topup,,,bfree,*monetary,,,,,*unlimited,,20,10,false,false,10 +FILTER,*topup,,*string:~*req.BalanceMap.*monetary[0].ID:*default;*lt:~*req.BalanceMap.*monetary[0].Value:0,bfree,*monetary,,,,,*unlimited,,20,10,false,false,10 +EXP,*topup,,,,*voice,,,,,*monthly,*any,300s,10,false,false,10 +NOEXP,*topup,,,,*voice,,,,,*unlimited,*any,50s,10,false,false,10 +VF,*debit,,,,*monetary,,,,,*unlimited,*any,"{""Method"":""*incremental"",""Params"":{""Units"":10, ""Interval"":""month"", ""Increment"":""day""}}",10,false,false,10 +TOPUP_RST_GNR_1000,*topup_reset,"{""*voice"": 60.0,""*data"":1024.0,""*sms"":1.0}",,,*generic,,*any,,,*unlimited,,1000,20,false,false,10 +` + ActionPlansCSVContent = ` +MORE_MINUTES,MINI,ONE_TIME_RUN,10 +MORE_MINUTES,SHARED,ONE_TIME_RUN,10 +TOPUP10_AT,TOPUP10_AC,*asap,10 +TOPUP10_AT,TOPUP10_AC1,*asap,10 +TOPUP_SHARED0_AT,SE0,*asap,10 +TOPUP_SHARED10_AT,SE10,*asap,10 +TOPUP_EMPTY_AT,EE0,*asap,10 +POST_AT,NEG,*asap,10 +BLOCK_AT,BLOCK,*asap,10 +BLOCK_EMPTY_AT,BLOCK_EMPTY,*asap,10 +EXP_AT,EXP,*asap,10 +` + + ActionTriggersCSVContent = ` +STANDARD_TRIGGER,st0,*min_event_counter,10,false,0,,,,*voice,,GERMANY_O2,,,,,,,,SOME_1,10 +STANDARD_TRIGGER,st1,*max_balance,200,false,0,,,,*voice,,GERMANY,,,,,,,,SOME_2,10 +STANDARD_TRIGGERS,,*min_balance,2,false,0,,,,*monetary,,,,,,,,,,LOG_WARNING,10 +STANDARD_TRIGGERS,,*max_balance,20,false,0,,,,*monetary,,,,,,,,,,LOG_WARNING,10 +STANDARD_TRIGGERS,,*max_event_counter,5,false,0,,,,*monetary,,FS_USERS,,,,,,,,LOG_WARNING,10 +` + AccountActionsCSVContent = ` +vdf,minitsboy,MORE_MINUTES,STANDARD_TRIGGER,, +cgrates.org,12345,TOPUP10_AT,STANDARD_TRIGGERS,, +cgrates.org,123456,TOPUP10_AT,STANDARD_TRIGGERS,, +cgrates.org,dy,TOPUP10_AT,STANDARD_TRIGGERS,, +cgrates.org,remo,TOPUP10_AT,,, +vdf,empty0,TOPUP_SHARED0_AT,,, +vdf,empty10,TOPUP_SHARED10_AT,,, +vdf,emptyX,TOPUP_EMPTY_AT,,, +vdf,emptyY,TOPUP_EMPTY_AT,,, +vdf,post,POST_AT,,, +cgrates.org,alodis,TOPUP_EMPTY_AT,,true,true +cgrates.org,block,BLOCK_AT,,false,false +cgrates.org,block_empty,BLOCK_EMPTY_AT,,false,false +cgrates.org,expo,EXP_AT,,false,false +cgrates.org,expnoexp,,,false,false +cgrates.org,vf,,,false,false +cgrates.org,round,TOPUP10_AT,,false,false +` + ResourcesCSVContent = ` +#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],TTL[4],Limit[5],AllocationMessage[6],Blocker[7],Stored[8],Weight[9],Thresholds[10] +cgrates.org,ResGroup21,*string:~*req.Account:1001,2014-07-29T15:00:00Z,1s,2,call,true,true,10, +cgrates.org,ResGroup22,*string:~*req.Account:dan,2014-07-29T15:00:00Z,3600s,2,premium_call,true,true,10, +` + StatsCSVContent = ` +#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],QueueLength[4],TTL[5],MinItems[6],Metrics[7],MetricFilterIDs[8],Stored[9],Blocker[10],Weight[11],ThresholdIDs[12] +cgrates.org,TestStats,*string:~*req.Account:1001,2014-07-29T15:00:00Z,100,1s,2,*sum#~*req.Value;*average#~*req.Value,,true,true,20,Th1;Th2 +cgrates.org,TestStats,,,,,2,*sum#~*req.Usage,,true,true,20, +cgrates.org,TestStats2,FLTR_1,2014-07-29T15:00:00Z,100,1s,2,*sum#~*req.Value;*sum#~*req.Usage;*average#~*req.Value;*average#~*req.Usage,,true,true,20,Th +cgrates.org,TestStats2,,,,,2,*sum#~*req.Cost;*average#~*req.Cost,,true,true,20, +` + RankingsCSVContent = ` +#Tenant[0],Id[1],QueryInterval[2],StatIDs[2],MetricIDs[3],Sorting[4],SortingParameters[5],ThresholdIDs[6] +cgrates.org,Ranking1,15m,Stats2;Stats3;Stats4,Metric1;Metric3,*asc,,THD1;THD2 +` + TrendsCSVContent = ` +#Tenant[0],Id[1],Schedule[2],StatID[3],Metrics[4],TTL[5],QueueLength[6],MinItems[7],CorrelationType[8],Tolerance[9],Stored[10],ThresholdIDs[11] +cgrates.org,TREND1,0 12 * * *,Stats2,*acc;*tcc,-1,-1,1,*average,2.1,true,TD1;TD2 +` + ThresholdsCSVContent = ` +#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],MaxHits[4],MinHits[5],MinSleep[6],Blocker[7],Weight[8],ActionIDs[9],Async[10] +cgrates.org,Threshold1,*string:~*req.Account:1001;*string:~*req.RunID:*default,2014-07-29T15:00:00Z,12,10,1s,true,10,THRESH1,true +` + + FiltersCSVContent = ` +#Tenant[0],ID[1],Type[2],Element[3],Values[4],ActivationInterval[5] +cgrates.org,FLTR_1,*string,~*req.Account,1001;1002,2014-07-29T15:00:00Z +cgrates.org,FLTR_1,*prefix,~*req.Destination,10;20,2014-07-29T15:00:00Z +cgrates.org,FLTR_1,*rsr,~*req.Subject,~^1.*1$, +cgrates.org,FLTR_1,*rsr,~*req.Destination,1002, +cgrates.org,FLTR_ACNT_dan,*string,~*req.Account,dan,2014-07-29T15:00:00Z +cgrates.org,FLTR_DST_DE,*destinations,~*req.Destination,DST_DE,2014-07-29T15:00:00Z +cgrates.org,FLTR_DST_NL,*destinations,~*req.Destination,DST_NL,2014-07-29T15:00:00Z +` + RoutesCSVContent = ` +#Tenant[0],ID[1],FilterIDs[2],ActivationInterval[3],Sorting[4],SortingParameters[5],RouteID[6],RouteFilterIDs[7],RouteAccountIDs[8],RouteRatingPlanIDs[9],RouteResourceIDs[10],RouteStatIDs[11],RouteWeight[12],RouteBlocker[13],RouteParameters[14],Weight[15] +cgrates.org,RoutePrf1,*string:~*req.Account:dan,2014-07-29T15:00:00Z,*lc,,route1,FLTR_ACNT_dan,Account1;Account1_1,RPL_1,ResGroup1,Stat1,10,true,param1,20 +cgrates.org,RoutePrf1,,,,,route1,,,RPL_2,ResGroup2,,10,,, +cgrates.org,RoutePrf1,,,,,route1,FLTR_DST_DE,Account2,RPL_3,ResGroup3,Stat2,10,,, +cgrates.org,RoutePrf1,,,,,route1,,,,ResGroup4,Stat3,10,,, +` + AttributesCSVContent = ` +#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight +cgrates.org,ALS1,con1,*string:~*req.Account:1001,2014-07-29T15:00:00Z,*string:~*req.Field1:Initial,*req.Field1,*variable,Sub1,true,20 +cgrates.org,ALS1,con2;con3,,,,*req.Field2,*variable,Sub2,true,20 +` + ChargersCSVContent = ` +#Tenant,ID,FilterIDs,ActivationInterval,RunID,AttributeIDs,Weight +cgrates.org,Charger1,*string:~*req.Account:1001,2014-07-29T15:00:00Z,*rated,ATTR_1001_SIMPLEAUTH,20 +` + DispatcherCSVContent = ` +#Tenant,ID,FilterIDs,ActivationInterval,Strategy,Hosts,Weight +cgrates.org,D1,*any,*string:~*req.Account:1001,2014-07-29T15:00:00Z,*first,,C1,*gt:~*req.Usage:10,10,false,192.168.56.203,20 +cgrates.org,D1,,,,*first,,C2,*lt:~*req.Usage:10,10,false,192.168.56.204, +` + DispatcherHostCSVContent = ` +#Tenant[0],ID[1],Address[2],Transport[3],ConnectAttempts[4],Reconnects[5],MaxReconnectInterval[6],ConnectTimeout[7],ReplyTimeout[8],Tls[9],ClientKey[10],ClientCertificate[11],CaCertificate[12] +cgrates.org,ALL,127.0.0.1:6012,*json,1,3,5m,1m,2m,false,,, +` ) var csvr *TpReader diff --git a/engine/z_actions_it_test.go b/engine/z_actions_it_test.go index 24dfd4d30..b37f13654 100644 --- a/engine/z_actions_it_test.go +++ b/engine/z_actions_it_test.go @@ -21,7 +21,6 @@ along with this program. If not, see package engine import ( - "errors" "io" "net/http" "net/http/httptest" @@ -34,7 +33,6 @@ import ( "github.com/cgrates/birpc" "github.com/cgrates/birpc/context" - "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -980,14 +978,3 @@ func testActionsitremoteSetAccount(t *testing.T) { t.Errorf("Expected: %s,received: %s", utils.ToJSON(exp), utils.ToJSON(acc2)) } } - -func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { - switch *utils.Encoding { - case utils.MetaJSON: - return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) - case utils.MetaGOB: - return birpc.Dial(utils.TCP, cfg.RPCGOBListen) - default: - return nil, errors.New("UNSUPPORTED_RPC") - } -} diff --git a/general_tests/api_escape_char_it_test.go b/general_tests/api_escape_char_it_test.go index a837ab0a5..3d213f5f0 100644 --- a/general_tests/api_escape_char_it_test.go +++ b/general_tests/api_escape_char_it_test.go @@ -55,7 +55,7 @@ func TestEscapeCharacters(t *testing.T) { }` - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, } client, _ := ng.Run(t) diff --git a/general_tests/at_topup_it_test.go b/general_tests/at_topup_it_test.go index 348a96583..133e2b8f1 100644 --- a/general_tests/at_topup_it_test.go +++ b/general_tests/at_topup_it_test.go @@ -111,7 +111,7 @@ TRIGGER_1001,,*min_balance,0,false,0,,,main,*data,,,,,,,,,,ACT_USAGE_1GB, TRIGGER_1001,,*balance_expired,,true,0,,,main,*data,,,,,,,,,,ACT_TOPUP_INITIAL,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } diff --git a/general_tests/attributes_it_test.go b/general_tests/attributes_it_test.go index e476dcd9d..c66aadc44 100644 --- a/general_tests/attributes_it_test.go +++ b/general_tests/attributes_it_test.go @@ -1116,7 +1116,7 @@ cgrates.org,FLTR_OR_DESTINATION_MATCH,*destinations,~*req.Destination,DST_20;DST cgrates.org,FLTR_DESTINATION_MATCH,*destinations,~*req.Destination,DST_10,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -1300,7 +1300,7 @@ cgrates.org,ATTR_ARITH,,,,,*req.3-4,*difference,3;4,, cgrates.org,ATTR_ARITH,,,,,*req.MultiplyBetweenVariables,*multiply,~*req.Elem1;~*req.Elem2,,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } diff --git a/general_tests/authorize_event_sms_data_it_test.go b/general_tests/authorize_event_sms_data_it_test.go index f0aff62db..9fc85ecbf 100644 --- a/general_tests/authorize_event_sms_data_it_test.go +++ b/general_tests/authorize_event_sms_data_it_test.go @@ -26,6 +26,7 @@ import ( "time" "github.com/cgrates/birpc/context" + "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" "github.com/cgrates/cgrates/utils" ) @@ -44,7 +45,7 @@ func TestSSv1AuthorizeEventSMS(t *testing.T) { default: t.Fatal("Unknown Database type") } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigPath: path.Join(*utils.DataDir, "conf", "samples", cfgDir), TpPath: path.Join(*utils.DataDir, "tariffplans", "testit"), } diff --git a/general_tests/balance_blocker_it_test.go b/general_tests/balance_blocker_it_test.go index cab3d930d..7855c88d3 100644 --- a/general_tests/balance_blocker_it_test.go +++ b/general_tests/balance_blocker_it_test.go @@ -96,7 +96,7 @@ RP_ANY,DR_ANY,*any,10`, cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_ANY,`, } - testNg := TestEngine{ + testNg := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -199,7 +199,7 @@ RP_ANY,DR_ANY,*any,10`, cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_ANY,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -324,7 +324,7 @@ RP_ANY,DR_ANY,*any,10`, cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_ANY,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -465,7 +465,7 @@ RP_ANY,DR_ANY,*any,10`, cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_ANY,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -568,7 +568,7 @@ RP_ANY,DR_ANY,*any,10`, cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_ANY,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -693,7 +693,7 @@ RP_ANY,DR_ANY,*any,10`, cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_ANY,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -837,7 +837,7 @@ RP_ANY,DR_ANY,*any,10`, cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_ANY,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -941,7 +941,7 @@ RP_ANY,DR_ANY,*any,10`, cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_ANY,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -1067,7 +1067,7 @@ RP_ANY,DR_ANY,*any,10`, cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_ANY,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -1209,7 +1209,7 @@ RP_ANY,DR_ANY,*any,10`, cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_ANY,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -1313,7 +1313,7 @@ RP_ANY,DR_ANY,*any,10`, cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_ANY,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -1439,7 +1439,7 @@ RP_ANY,DR_ANY,*any,10`, cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_ANY,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } diff --git a/general_tests/balance_it_test.go b/general_tests/balance_it_test.go index e62ba10ad..674e4d490 100644 --- a/general_tests/balance_it_test.go +++ b/general_tests/balance_it_test.go @@ -107,7 +107,7 @@ RP_ANY,DR_ANY,*any,10`, cgrates.org,sms,1001,2014-01-14T00:00:00Z,RP_ANY,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -351,7 +351,7 @@ cgrates.org,sms,1001,2014-01-14T00:00:00Z,RP_SMS, cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_VOICE,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -867,7 +867,7 @@ ACT_TOPUP_MONETARY,*cdrlog,"{""BalanceID"":""~*acnt.BalanceID""}",,,,,,,,,,,,,, ACT_TOPUP_SMS,*topup_reset,,,balance_sms,*sms,,*any,,,*unlimited,,1000,10,false,false,10`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -1255,7 +1255,7 @@ RP_MONETARY,DR_MONETARY,*any,10`, utils.RatingProfilesCsv: `#Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } diff --git a/general_tests/balance_timings_it_test.go b/general_tests/balance_timings_it_test.go index 3ab44145c..f9823c149 100644 --- a/general_tests/balance_timings_it_test.go +++ b/general_tests/balance_timings_it_test.go @@ -121,7 +121,7 @@ HALF1,*any,*any,*any,*any,00:00:00;11:59:59 HALF2,*any,*any,*any,*any,12:00:00;23:59:59`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -370,7 +370,7 @@ RP_1001,DR_1002_20CNT,*any,10`, cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_1001,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, } client, _ := ng.Run(t) @@ -437,7 +437,7 @@ cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_1001,`, } // LoadTPFromFolder customTpPath := t.TempDir() - loadCSVs(t, client, "", customTpPath, tpFiles) + engine.LoadCSVs(t, client, "", customTpPath, tpFiles) attrsEA := &utils.AttrExecuteAction{Tenant: "cgrates.org", Account: "1001", ActionsId: "ACT_TOPUP_RST_10"} if err := client.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Errorf("APIerSv1ExecuteAction failed unexpectedly: %v", err) @@ -655,7 +655,7 @@ RP_1001,DR_1002_20CNT,*any,10`, cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_1001,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, } client, _ := ng.Run(t) @@ -722,7 +722,7 @@ cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_1001,`, } // LoadTPFromFolder customTpPath := t.TempDir() - loadCSVs(t, client, "", customTpPath, tpFiles) + engine.LoadCSVs(t, client, "", customTpPath, tpFiles) attrsEA := &utils.AttrExecuteAction{Tenant: "cgrates.org", Account: "1001", ActionsId: "ACT_TOPUP_RST_10"} if err := client.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Errorf("APIerSv1ExecuteAction failed unexpectedly: %v", err) diff --git a/general_tests/cdrlog_ees_it_test.go b/general_tests/cdrlog_ees_it_test.go index 726a63b48..08b439f27 100644 --- a/general_tests/cdrlog_ees_it_test.go +++ b/general_tests/cdrlog_ees_it_test.go @@ -180,7 +180,7 @@ func TestCdrLogEes(t *testing.T) { } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: map[string]string{}, } diff --git a/general_tests/dsp_routes_it_test.go b/general_tests/dsp_routes_it_test.go index 222e8c1f9..a7c5d9acc 100644 --- a/general_tests/dsp_routes_it_test.go +++ b/general_tests/dsp_routes_it_test.go @@ -123,11 +123,11 @@ func TestDispatcherRoutesNotFound(t *testing.T) { t.Fatal("unsupported dbtype value") } - host1 := TestEngine{ // first engine, port 4012 + host1 := engine.TestEngine{ // first engine, port 4012 ConfigJSON: fmt.Sprintf(hostCfg, "host1", 40), } ng1Client, _ := host1.Run(t) - host2 := TestEngine{ // second engine, port 6012 + host2 := engine.TestEngine{ // second engine, port 6012 ConfigJSON: fmt.Sprintf(hostCfg, "host2", 60), } ng2Client, _ := host2.Run(t) @@ -150,13 +150,13 @@ func TestDispatcherRoutes(t *testing.T) { t.Fatal("unsupported dbtype value") } - setter := TestEngine{ // engine used to set dispatcher hosts/profiles (:2012) + setter := engine.TestEngine{ // engine used to set dispatcher hosts/profiles (:2012) ConfigJSON: hostSetterCfg, } setterClient, _ := setter.Run(t) // Starting only the second dispatcher engine, for now. - host2 := TestEngine{ + host2 := engine.TestEngine{ ConfigJSON: fmt.Sprintf(hostCfg, "host2", 60), PreserveDataDB: true, PreserveStorDB: true, @@ -208,7 +208,7 @@ func TestDispatcherRoutes(t *testing.T) { getCacheItem(t, ng2Client, false, utils.CacheDispatchers, "cgrates.org:dsp_test", map[string]any{}) // Start the first engine. - host1 := TestEngine{ + host1 := engine.TestEngine{ ConfigJSON: fmt.Sprintf(hostCfg, "host1", 40), PreserveDataDB: true, PreserveStorDB: true, diff --git a/general_tests/ees_it_test.go b/general_tests/ees_it_test.go index 01e4ae574..927345fbb 100644 --- a/general_tests/ees_it_test.go +++ b/general_tests/ees_it_test.go @@ -113,7 +113,7 @@ func TestEEsExportEventChanges(t *testing.T) { }` - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, } client, _ := ng.Run(t) @@ -387,7 +387,7 @@ func TestEEsReplayFailedPosts(t *testing.T) { }`, failedDir) - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, } client, _ := ng.Run(t) diff --git a/general_tests/ers_linenr_it_test.go b/general_tests/ers_linenr_it_test.go index 27de5ff9d..0c37b7fa0 100644 --- a/general_tests/ers_linenr_it_test.go +++ b/general_tests/ers_linenr_it_test.go @@ -30,6 +30,7 @@ import ( "testing" "time" + "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -105,7 +106,7 @@ func TestERsLineNr(t *testing.T) { }`, csvFd, procFd, fwvFd, procFd, xmlFd, procFd) buf := &bytes.Buffer{} - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, LogBuffer: buf, } diff --git a/general_tests/fallback_depth_it_test.go b/general_tests/fallback_depth_it_test.go index c1d710488..bc207f6b2 100644 --- a/general_tests/fallback_depth_it_test.go +++ b/general_tests/fallback_depth_it_test.go @@ -112,7 +112,7 @@ cgrates.org,call,DEFAULT,,RP_DEFAULT,`, } buf := &bytes.Buffer{} - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, LogBuffer: buf, diff --git a/general_tests/filterhttp_it_test.go b/general_tests/filterhttp_it_test.go index 47d22daeb..f87bfdf77 100644 --- a/general_tests/filterhttp_it_test.go +++ b/general_tests/filterhttp_it_test.go @@ -165,7 +165,7 @@ cgrates.org,ATTR_ACNT_1001,*any,FLTR_HTTP,,,*req.OfficeGroup,*http#[` + srv.URL cgrates.org,ATTR_DEST,*any,FLTR_DST_1002;FLTR_DEST,,,*req.Supplier,*constant,Supplier1,,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } diff --git a/general_tests/get_account_cost_it_test.go b/general_tests/get_account_cost_it_test.go index 422f0c036..8809f9bd3 100644 --- a/general_tests/get_account_cost_it_test.go +++ b/general_tests/get_account_cost_it_test.go @@ -35,7 +35,7 @@ import ( var aSummaryBefore *engine.AccountSummary func TestGetAccountCost(t *testing.T) { - ng := TestEngine{ + ng := engine.TestEngine{ ConfigPath: path.Join(*utils.DataDir, "conf", "samples", "rerate_cdrs_mysql"), TpPath: path.Join(*utils.DataDir, "tariffplans", "reratecdrs"), } diff --git a/general_tests/kafka_ssl_it_test.go b/general_tests/kafka_ssl_it_test.go index 72ccf853f..8eaa30498 100644 --- a/general_tests/kafka_ssl_it_test.go +++ b/general_tests/kafka_ssl_it_test.go @@ -129,7 +129,7 @@ func TestKafkaSSL(t *testing.T) { }`, brokerSSLURL, mainTopic, brokerPlainURL, processedTopic, brokerSSLURL, mainTopic) - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, } client, _ := ng.Run(t) diff --git a/general_tests/lib_test.go b/general_tests/lib_test.go index 6870f6e7c..7d2006a2a 100644 --- a/general_tests/lib_test.go +++ b/general_tests/lib_test.go @@ -21,19 +21,10 @@ package general_tests import ( "errors" - "io" - "os" - "os/exec" - "path" - "path/filepath" - "testing" - "time" "github.com/cgrates/birpc" - "github.com/cgrates/birpc/context" "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -51,171 +42,3 @@ func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { return nil, errors.New("UNSUPPORTED_RPC") } } - -// TestEngine holds the setup parameters and configurations -// required for running integration tests. -type TestEngine struct { - ConfigPath string // path to the main configuration file - ConfigJSON string // configuration JSON content (used if ConfigPath is empty) - LogBuffer io.Writer // captures log output of the test environment - PreserveDataDB bool // prevents automatic data_db flush when set - PreserveStorDB bool // prevents automatic stor_db flush when set - TpPath string // path to the tariff plans - TpFiles map[string]string // CSV data for tariff plans: filename -> content - - // PreStartHook executes custom logic relying on CGRConfig - // before starting cgr-engine. - PreStartHook func(*testing.T, *config.CGRConfig) -} - -// Run initializes a cgr-engine instance for testing, loads tariff plans (if available) and returns -// an RPC client and the CGRConfig object. It calls t.Fatal on any setup failure. -func (ng TestEngine) Run(t *testing.T) (*birpc.Client, *config.CGRConfig) { - t.Helper() - - // Parse config files. - var cfgPath string - switch { - case ng.ConfigJSON != "": - cfgPath = t.TempDir() - filePath := filepath.Join(cfgPath, "cgrates.json") - if err := os.WriteFile(filePath, []byte(ng.ConfigJSON), 0644); err != nil { - t.Fatal(err) - } - case ng.ConfigPath != "": - cfgPath = ng.ConfigPath - default: - t.Fatal("missing config source") - } - cfg, err := config.NewCGRConfigFromPath(cfgPath) - if err != nil { - t.Fatalf("could not init config from path %s: %v", cfgPath, err) - } - - flushDBs(t, cfg, !ng.PreserveDataDB, !ng.PreserveStorDB) - - if ng.PreStartHook != nil { - ng.PreStartHook(t, cfg) - } - - startEngine(t, cfg, ng.LogBuffer) - - client, err := newRPCClient(cfg.ListenCfg()) - if err != nil { - t.Fatalf("could not connect to cgr-engine: %v", err) - } - - var customTpPath string - if len(ng.TpFiles) != 0 { - customTpPath = t.TempDir() - } - loadCSVs(t, client, ng.TpPath, customTpPath, ng.TpFiles) - - return client, cfg -} - -// loadCSVs loads tariff plan data from CSV files into the service. It handles directory creation and file -// writing for custom paths, and loads data from the specified paths using the provided RPC client. -func loadCSVs(t *testing.T, client *birpc.Client, tpPath, customTpPath string, csvFiles map[string]string) { - t.Helper() - paths := make([]string, 0, 2) - if customTpPath != "" { - for fileName, content := range csvFiles { - filePath := path.Join(customTpPath, fileName) - if err := os.WriteFile(filePath, []byte(content), 0644); err != nil { - t.Fatalf("could not write to file %s: %v", filePath, err) - } - } - paths = append(paths, customTpPath) - } - if tpPath != "" { - paths = append(paths, tpPath) - } - if len(paths) == 0 { - return - } - - ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond) - defer cancel() - waitForService(t, ctx, client, utils.APIerSv1) - - var reply string - for _, path := range paths { - args := &utils.AttrLoadTpFromFolder{FolderPath: path} - err := client.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, args, &reply) - if err != nil { - t.Fatalf("%s call failed for path %s: %v", utils.APIerSv1LoadTariffPlanFromFolder, path, err) - } - } -} - -// flushDBs resets the databases specified in the configuration if the corresponding flags are true. -func flushDBs(t *testing.T, cfg *config.CGRConfig, flushDataDB, flushStorDB bool) { - t.Helper() - if flushDataDB { - if err := engine.InitDataDb(cfg); err != nil { - t.Fatalf("failed to flush %s dataDB: %v", cfg.DataDbCfg().Type, err) - } - } - if flushStorDB { - if err := engine.InitStorDb(cfg); err != nil { - t.Fatalf("failed to flush %s storDB: %v", cfg.StorDbCfg().Type, err) - } - } -} - -// startEngine starts the CGR engine process with the provided configuration. It writes engine logs to the -// provided logBuffer (if any). -func startEngine(t *testing.T, cfg *config.CGRConfig, logBuffer io.Writer) { - t.Helper() - binPath, err := exec.LookPath("cgr-engine") - if err != nil { - t.Fatal(err) - } - engine := exec.Command( - binPath, - "-config_path", cfg.ConfigPath, - "-logger", utils.MetaStdLog, - ) - if logBuffer != nil { - engine.Stdout = logBuffer - engine.Stderr = logBuffer - } - if err := engine.Start(); err != nil { - t.Fatalf("cgr-engine command failed: %v", err) - } - t.Cleanup(func() { - if err := engine.Process.Kill(); err != nil { - t.Errorf("failed to kill cgr-engine process (%d): %v", engine.Process.Pid, err) - } - }) - fib := utils.FibDuration(time.Millisecond, 0) - for i := 0; i < 16; i++ { - time.Sleep(fib()) - if _, err := jsonrpc.Dial(utils.TCP, cfg.ListenCfg().RPCJSONListen); err == nil { - break - } - } - if err != nil { - t.Fatalf("starting cgr-engine on port %s failed: %v", cfg.ListenCfg().RPCJSONListen, err) - } -} - -func waitForService(t *testing.T, ctx *context.Context, client *birpc.Client, service string) { - t.Helper() - method := service + ".Ping" - backoff := utils.FibDuration(time.Millisecond, 0) - var reply any - for { - select { - case <-ctx.Done(): - t.Fatalf("%s service did not become available: %v", service, ctx.Err()) - default: - err := client.Call(context.Background(), method, nil, &reply) - if err == nil && reply == utils.Pong { - return - } - time.Sleep(backoff()) - } - } -} diff --git a/general_tests/process_message_it_test.go b/general_tests/process_message_it_test.go index 9a296738f..3e74c6910 100644 --- a/general_tests/process_message_it_test.go +++ b/general_tests/process_message_it_test.go @@ -80,7 +80,7 @@ RP_ANY,DR_ANY,*any,10`, cgrates.org,sms,subj_test,,RP_ANY,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } diff --git a/general_tests/reproc_cdrs_for_stats_it_test.go b/general_tests/reproc_cdrs_for_stats_it_test.go index cf0a2e779..94c269806 100644 --- a/general_tests/reproc_cdrs_for_stats_it_test.go +++ b/general_tests/reproc_cdrs_for_stats_it_test.go @@ -126,7 +126,7 @@ func testRpcdrsRpcConn(t *testing.T) { } func testRpcdrsLoadTP(t *testing.T) { - loadCSVs(t, rpcdrsRpc, path.Join(*utils.DataDir, "tariffplans", "reratecdrs"), "", nil) + engine.LoadCSVs(t, rpcdrsRpc, path.Join(*utils.DataDir, "tariffplans", "reratecdrs"), "", nil) } func testRpcdrsSetBalance(t *testing.T) { @@ -375,7 +375,7 @@ cgrates.org,STAT_AGG,,2014-07-29T15:00:00Z,0,-1,0,*tcd;*tcc;*sum#1,,false,false, t.Fatalf("could not connect to cgr-engine: %v", err) } - loadCSVs(t, rpcdrsRpc, "", t.TempDir(), tpFiles) + engine.LoadCSVs(t, rpcdrsRpc, "", t.TempDir(), tpFiles) } diff --git a/general_tests/rerate_cdrs_it_test.go b/general_tests/rerate_cdrs_it_test.go index c4dcd26b9..9c3271fa3 100644 --- a/general_tests/rerate_cdrs_it_test.go +++ b/general_tests/rerate_cdrs_it_test.go @@ -46,7 +46,7 @@ func TestRerateCDRs(t *testing.T) { default: t.Fatal("Unknown Database type") } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigPath: path.Join(*utils.DataDir, "conf", "samples", cfgDir), TpPath: path.Join(*utils.DataDir, "tariffplans", "reratecdrs"), } diff --git a/general_tests/rpsubj_set_it_test.go b/general_tests/rpsubj_set_it_test.go index ae018e2fe..f7679473e 100644 --- a/general_tests/rpsubj_set_it_test.go +++ b/general_tests/rpsubj_set_it_test.go @@ -85,7 +85,7 @@ RP_DATA,DR_DATA,*any,10`, cgrates.org,data,RPF_DATA,2022-01-14T00:00:00Z,RP_DATA,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } @@ -213,7 +213,7 @@ RP_DATA,DR_DATA,*any,10`, cgrates.org,data,1001,2022-01-14T00:00:00Z,RP_DATA,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } diff --git a/general_tests/service_toggle_it_test.go b/general_tests/service_toggle_it_test.go index e2c3f8af5..327fbe107 100644 --- a/general_tests/service_toggle_it_test.go +++ b/general_tests/service_toggle_it_test.go @@ -30,6 +30,7 @@ import ( "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -112,7 +113,7 @@ func TestServiceToggle(t *testing.T) { // Start a cgr-engine instance that has all the services // from the slice above enabled. - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: fmt.Sprintf(cfgJSON, "true"), } client, cfg := ng.Run(t) @@ -121,7 +122,7 @@ func TestServiceToggle(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) defer cancel() for _, service := range services { - waitForService(t, ctx, client, service) + engine.WaitForService(t, ctx, client, service) } // Toggle the state of all services via config reload. diff --git a/general_tests/session_bkup_interval_it_test.go b/general_tests/session_bkup_interval_it_test.go index abe267192..cb428a8fb 100644 --- a/general_tests/session_bkup_interval_it_test.go +++ b/general_tests/session_bkup_interval_it_test.go @@ -137,7 +137,7 @@ RP_ANY,DR_ANY_20CNT,*any,10`, cgrates.org,call,*any,2014-01-14T00:00:00Z,RP_ANY,`, } - loadCSVs(t, sBkupRPC, "", t.TempDir(), tpFiles) + engine.LoadCSVs(t, sBkupRPC, "", t.TempDir(), tpFiles) time.Sleep(time.Duration(*utils.WaitRater) * time.Millisecond) } diff --git a/general_tests/set_rmv_prfl_dlay_it_test.go b/general_tests/set_rmv_prfl_dlay_it_test.go index c0de59949..4b7da7dcc 100644 --- a/general_tests/set_rmv_prfl_dlay_it_test.go +++ b/general_tests/set_rmv_prfl_dlay_it_test.go @@ -47,7 +47,7 @@ func TestSetRemoveProfilesWithCachingDelay(t *testing.T) { default: t.Fatal("Unknown Database type") } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigPath: path.Join(*utils.DataDir, "conf", "samples", cfgDir), TpPath: path.Join(*utils.DataDir, "tariffplans", "tutorial"), } diff --git a/general_tests/shared_subject_it_test.go b/general_tests/shared_subject_it_test.go index e477f15c7..0c3994459 100644 --- a/general_tests/shared_subject_it_test.go +++ b/general_tests/shared_subject_it_test.go @@ -121,7 +121,7 @@ cgrates.org,call,Subject1,2014-01-14T00:00:00Z,RP_Subject1, cgrates.org,call,Subject2,2014-01-14T00:00:00Z,RP_Subject2,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } diff --git a/general_tests/stats_export_it_test.go b/general_tests/stats_export_it_test.go index 664a508e7..5bb7deb31 100644 --- a/general_tests/stats_export_it_test.go +++ b/general_tests/stats_export_it_test.go @@ -88,7 +88,7 @@ func TestStatsEEsExport(t *testing.T) { }` - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, } client, _ := ng.Run(t) diff --git a/general_tests/transfer_balance_it_test.go b/general_tests/transfer_balance_it_test.go index b495ad6a3..8a69bee31 100644 --- a/general_tests/transfer_balance_it_test.go +++ b/general_tests/transfer_balance_it_test.go @@ -92,7 +92,7 @@ ACT_TRANSFER,*transfer_balance,"{""DestinationAccountID"":""cgrates.org:ACC_DEST ACT_TRANSFER,*cdrlog,,,,,,,,,,,,,,,`, } - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } diff --git a/general_tests/trends_schedule_it_test.go b/general_tests/trends_schedule_it_test.go index 8448f3588..06f4891a0 100644 --- a/general_tests/trends_schedule_it_test.go +++ b/general_tests/trends_schedule_it_test.go @@ -113,7 +113,7 @@ cgrates.org,Threshold1,*string:~*req.Metrics.*acd.ID:*acd,2024-07-29T15:00:00Z,- cgrates.org,Threshold2,*string:~*req.Metrics.*pdd.ID:*pdd,2024-07-29T15:00:00Z,-1,10,1s,false,10,,true `} - ng := TestEngine{ + ng := engine.TestEngine{ ConfigJSON: content, TpFiles: tpFiles, } diff --git a/loaders/loader_it_test.go b/loaders/loader_it_test.go index dfaaeefac..57b7b6423 100644 --- a/loaders/loader_it_test.go +++ b/loaders/loader_it_test.go @@ -169,7 +169,7 @@ func testLoaderRPCConn(t *testing.T) { func testLoaderPopulateData(t *testing.T) { fileName := utils.AttributesCsv tmpFilePath := path.Join("/tmp", fileName) - if err := os.WriteFile(tmpFilePath, []byte(engine.AttributesCSVContent), os.ModePerm); err != nil { + if err := os.WriteFile(tmpFilePath, []byte(AttributesCSVContent), os.ModePerm); err != nil { t.Fatal(err.Error()) } if err := os.Rename(tmpFilePath, path.Join("/tmp/In", fileName)); err != nil { @@ -189,8 +189,8 @@ func testLoaderVerifyOutDir(t *testing.T) { time.Sleep(100 * time.Millisecond) if outContent1, err := os.ReadFile(path.Join("/tmp/Out", utils.AttributesCsv)); err != nil { t.Error(err) - } else if engine.AttributesCSVContent != string(outContent1) { - t.Errorf("Expecting: %q, received: %q", engine.AttributesCSVContent, string(outContent1)) + } else if AttributesCSVContent != string(outContent1) { + t.Errorf("Expecting: %q, received: %q", AttributesCSVContent, string(outContent1)) } } @@ -240,7 +240,7 @@ func testLoaderCheckAttributes(t *testing.T) { func testLoaderPopulateDataWithoutMoving(t *testing.T) { fileName := utils.AttributesCsv tmpFilePath := path.Join("/tmp/", fileName) - if err := os.WriteFile(tmpFilePath, []byte(engine.AttributesCSVContent), os.ModePerm); err != nil { + if err := os.WriteFile(tmpFilePath, []byte(AttributesCSVContent), os.ModePerm); err != nil { t.Fatal(err.Error()) } if err := os.Rename(tmpFilePath, path.Join("/tmp/LoaderIn", fileName)); err != nil { @@ -261,15 +261,15 @@ func testLoaderVerifyOutDirWithoutMoving(t *testing.T) { // we expect that after the LoaderS process the file leave in in the input folder if outContent1, err := os.ReadFile(path.Join("/tmp/LoaderIn", utils.AttributesCsv)); err != nil { t.Error(err) - } else if engine.AttributesCSVContent != string(outContent1) { - t.Errorf("Expecting: %q, received: %q", engine.AttributesCSVContent, string(outContent1)) + } else if AttributesCSVContent != string(outContent1) { + t.Errorf("Expecting: %q, received: %q", AttributesCSVContent, string(outContent1)) } } func testLoaderPopulateDataWithSubpath(t *testing.T) { fileName := utils.AttributesCsv tmpFilePath := path.Join("/tmp/", fileName) - if err := os.WriteFile(tmpFilePath, []byte(engine.AttributesCSVContent), os.ModePerm); err != nil { + if err := os.WriteFile(tmpFilePath, []byte(AttributesCSVContent), os.ModePerm); err != nil { t.Fatal(err.Error()) } if err := os.MkdirAll("/tmp/SubpathWithoutMove/folder1", 0755); err != nil { @@ -293,15 +293,15 @@ func testLoaderVerifyOutDirWithSubpath(t *testing.T) { // we expect that after the LoaderS process the file leave in in the input folder if outContent1, err := os.ReadFile(path.Join("/tmp/SubpathWithoutMove/folder1", utils.AttributesCsv)); err != nil { t.Error(err) - } else if engine.AttributesCSVContent != string(outContent1) { - t.Errorf("Expecting: %q, received: %q", engine.AttributesCSVContent, string(outContent1)) + } else if AttributesCSVContent != string(outContent1) { + t.Errorf("Expecting: %q, received: %q", AttributesCSVContent, string(outContent1)) } } func testLoaderPopulateDataWithSubpathWithMove(t *testing.T) { fileName := utils.AttributesCsv tmpFilePath := path.Join("/tmp/", fileName) - if err := os.WriteFile(tmpFilePath, []byte(engine.AttributesCSVContent), os.ModePerm); err != nil { + if err := os.WriteFile(tmpFilePath, []byte(AttributesCSVContent), os.ModePerm); err != nil { t.Fatal(err.Error()) } if err := os.MkdirAll("/tmp/SubpathLoaderWithMove/folder1", 0755); err != nil { @@ -324,15 +324,15 @@ func testLoaderVerifyOutDirWithSubpathWithMove(t *testing.T) { time.Sleep(100 * time.Millisecond) if outContent1, err := os.ReadFile(path.Join("/tmp/SubpathOut/folder1", utils.AttributesCsv)); err != nil { t.Error(err) - } else if engine.AttributesCSVContent != string(outContent1) { - t.Errorf("Expecting: %q, received: %q", engine.AttributesCSVContent, string(outContent1)) + } else if AttributesCSVContent != string(outContent1) { + t.Errorf("Expecting: %q, received: %q", AttributesCSVContent, string(outContent1)) } } func testLoaderPopulateDataForTemplateLoader(t *testing.T) { fileName := utils.AttributesCsv tmpFilePath := path.Join("/tmp/", fileName) - if err := os.WriteFile(tmpFilePath, []byte(engine.AttributesCSVContent), os.ModePerm); err != nil { + if err := os.WriteFile(tmpFilePath, []byte(AttributesCSVContent), os.ModePerm); err != nil { t.Fatal(err.Error()) } if err := os.MkdirAll("/tmp/templateLoaderIn", 0755); err != nil { @@ -355,8 +355,8 @@ func testLoaderVerifyOutDirForTemplateLoader(t *testing.T) { time.Sleep(100 * time.Millisecond) if outContent1, err := os.ReadFile(path.Join("/tmp/templateLoaderOut", utils.AttributesCsv)); err != nil { t.Error(err) - } else if engine.AttributesCSVContent != string(outContent1) { - t.Errorf("Expecting: %q, received: %q", engine.AttributesCSVContent, string(outContent1)) + } else if AttributesCSVContent != string(outContent1) { + t.Errorf("Expecting: %q, received: %q", AttributesCSVContent, string(outContent1)) } } diff --git a/loaders/loader_test.go b/loaders/loader_test.go index 21de3c83d..ec83c9500 100644 --- a/loaders/loader_test.go +++ b/loaders/loader_test.go @@ -40,6 +40,60 @@ import ( var data = engine.NewInternalDB(nil, nil, false, config.CgrConfig().DataDbCfg().Items) +const ( + ResourcesCSVContent = ` +#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],TTL[4],Limit[5],AllocationMessage[6],Blocker[7],Stored[8],Weight[9],Thresholds[10] +cgrates.org,ResGroup21,*string:~*req.Account:1001,2014-07-29T15:00:00Z,1s,2,call,true,true,10, +cgrates.org,ResGroup22,*string:~*req.Account:dan,2014-07-29T15:00:00Z,3600s,2,premium_call,true,true,10, +` + StatsCSVContent = ` +#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],QueueLength[4],TTL[5],MinItems[6],Metrics[7],MetricFilterIDs[8],Stored[9],Blocker[10],Weight[11],ThresholdIDs[12] +cgrates.org,TestStats,*string:~*req.Account:1001,2014-07-29T15:00:00Z,100,1s,2,*sum#~*req.Value;*average#~*req.Value,,true,true,20,Th1;Th2 +cgrates.org,TestStats,,,,,2,*sum#~*req.Usage,,true,true,20, +cgrates.org,TestStats2,FLTR_1,2014-07-29T15:00:00Z,100,1s,2,*sum#~*req.Value;*sum#~*req.Usage;*average#~*req.Value;*average#~*req.Usage,,true,true,20,Th +cgrates.org,TestStats2,,,,,2,*sum#~*req.Cost;*average#~*req.Cost,,true,true,20, +` + ThresholdsCSVContent = ` +#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],MaxHits[4],MinHits[5],MinSleep[6],Blocker[7],Weight[8],ActionIDs[9],Async[10] +cgrates.org,Threshold1,*string:~*req.Account:1001;*string:~*req.RunID:*default,2014-07-29T15:00:00Z,12,10,1s,true,10,THRESH1,true +` + FiltersCSVContent = ` +#Tenant[0],ID[1],Type[2],Element[3],Values[4],ActivationInterval[5] +cgrates.org,FLTR_1,*string,~*req.Account,1001;1002,2014-07-29T15:00:00Z +cgrates.org,FLTR_1,*prefix,~*req.Destination,10;20,2014-07-29T15:00:00Z +cgrates.org,FLTR_1,*rsr,~*req.Subject,~^1.*1$, +cgrates.org,FLTR_1,*rsr,~*req.Destination,1002, +cgrates.org,FLTR_ACNT_dan,*string,~*req.Account,dan,2014-07-29T15:00:00Z +cgrates.org,FLTR_DST_DE,*destinations,~*req.Destination,DST_DE,2014-07-29T15:00:00Z +cgrates.org,FLTR_DST_NL,*destinations,~*req.Destination,DST_NL,2014-07-29T15:00:00Z +` + RoutesCSVContent = ` +#Tenant[0],ID[1],FilterIDs[2],ActivationInterval[3],Sorting[4],SortingParameters[5],RouteID[6],RouteFilterIDs[7],RouteAccountIDs[8],RouteRatingPlanIDs[9],RouteResourceIDs[10],RouteStatIDs[11],RouteWeight[12],RouteBlocker[13],RouteParameters[14],Weight[15] +cgrates.org,RoutePrf1,*string:~*req.Account:dan,2014-07-29T15:00:00Z,*lc,,route1,FLTR_ACNT_dan,Account1;Account1_1,RPL_1,ResGroup1,Stat1,10,true,param1,20 +cgrates.org,RoutePrf1,,,,,route1,,,RPL_2,ResGroup2,,10,,, +cgrates.org,RoutePrf1,,,,,route1,FLTR_DST_DE,Account2,RPL_3,ResGroup3,Stat2,10,,, +cgrates.org,RoutePrf1,,,,,route1,,,,ResGroup4,Stat3,10,,, +` + AttributesCSVContent = ` +#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight +cgrates.org,ALS1,con1,*string:~*req.Account:1001,2014-07-29T15:00:00Z,*string:~*req.Field1:Initial,*req.Field1,*variable,Sub1,true,20 +cgrates.org,ALS1,con2;con3,,,,*req.Field2,*variable,Sub2,true,20 +` + ChargersCSVContent = ` +#Tenant,ID,FilterIDs,ActivationInterval,RunID,AttributeIDs,Weight +cgrates.org,Charger1,*string:~*req.Account:1001,2014-07-29T15:00:00Z,*rated,ATTR_1001_SIMPLEAUTH,20 +` + DispatcherCSVContent = ` +#Tenant,ID,FilterIDs,ActivationInterval,Strategy,Hosts,Weight +cgrates.org,D1,*any,*string:~*req.Account:1001,2014-07-29T15:00:00Z,*first,,C1,*gt:~*req.Usage:10,10,false,192.168.56.203,20 +cgrates.org,D1,,,,*first,,C2,*lt:~*req.Usage:10,10,false,192.168.56.204, +` + DispatcherHostCSVContent = ` +#Tenant[0],ID[1],Address[2],Transport[3],ConnectAttempts[4],Reconnects[5],MaxReconnectInterval[6],ConnectTimeout[7],ReplyTimeout[8],Tls[9],ClientKey[10],ClientCertificate[11],CaCertificate[12] +cgrates.org,ALL,127.0.0.1:6012,*json,1,3,5m,1m,2m,false,,, +` +) + func TestLoaderProcessContentSingleFile(t *testing.T) { ldr := &Loader{ ldrID: "TestLoaderProcessContent", @@ -86,7 +140,7 @@ func TestLoaderProcessContentSingleFile(t *testing.T) { Value: config.NewRSRParsersMustCompile("~*req.10", utils.InfieldSep)}, }, } - rdr := io.NopCloser(strings.NewReader(engine.AttributesCSVContent)) + rdr := io.NopCloser(strings.NewReader(AttributesCSVContent)) csvRdr := csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -103,7 +157,7 @@ func TestLoaderProcessContentSingleFile(t *testing.T) { //processContent successfully when dryrun is false ldr.dryRun = false - rdr = io.NopCloser(strings.NewReader(engine.AttributesCSVContent)) + rdr = io.NopCloser(strings.NewReader(AttributesCSVContent)) csvRdr = csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -152,7 +206,7 @@ func TestLoaderProcessContentSingleFile(t *testing.T) { //cannot set AttributeProfile when dataManager is nil ldr.dm = nil ldr.dryRun = false - rdr = io.NopCloser(strings.NewReader(engine.AttributesCSVContent)) + rdr = io.NopCloser(strings.NewReader(AttributesCSVContent)) csvRdr = csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -286,7 +340,7 @@ func TestLoaderProcessResource(t *testing.T) { Value: config.NewRSRParsersMustCompile("~*req.10", utils.InfieldSep)}, }, } - rdr := io.NopCloser(strings.NewReader(engine.ResourcesCSVContent)) + rdr := io.NopCloser(strings.NewReader(ResourcesCSVContent)) csvRdr := csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -377,7 +431,7 @@ func TestLoaderProcessFilters(t *testing.T) { Value: config.NewRSRParsersMustCompile("~*req.5", utils.InfieldSep)}, }, } - rdr := io.NopCloser(strings.NewReader(engine.FiltersCSVContent)) + rdr := io.NopCloser(strings.NewReader(FiltersCSVContent)) csvRdr := csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -394,7 +448,7 @@ func TestLoaderProcessFilters(t *testing.T) { //processContent when dryrun is false ldr.dryRun = false - rdr = io.NopCloser(strings.NewReader(engine.FiltersCSVContent)) + rdr = io.NopCloser(strings.NewReader(FiltersCSVContent)) csvRdr = csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -528,7 +582,7 @@ func TestLoaderProcessThresholds(t *testing.T) { Value: config.NewRSRParsersMustCompile("~*req.10", utils.InfieldSep)}, }, } - rdr := io.NopCloser(strings.NewReader(engine.ThresholdsCSVContent)) + rdr := io.NopCloser(strings.NewReader(ThresholdsCSVContent)) csvRdr := csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -569,7 +623,7 @@ func TestLoaderProcessThresholds(t *testing.T) { //cannot set thresholdProfile when dryrun is true ldr.dryRun = true - rdr = io.NopCloser(strings.NewReader(engine.ThresholdsCSVContent)) + rdr = io.NopCloser(strings.NewReader(ThresholdsCSVContent)) csvRdr = csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -635,7 +689,7 @@ func TestLoaderProcessStats(t *testing.T) { Value: config.NewRSRParsersMustCompile("~*req.12", utils.InfieldSep)}, }, } - rdr := io.NopCloser(strings.NewReader(engine.StatsCSVContent)) + rdr := io.NopCloser(strings.NewReader(StatsCSVContent)) csvRdr := csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -683,7 +737,7 @@ func TestLoaderProcessStats(t *testing.T) { //cannot set statsProfile when dryrun is true ldr.dryRun = true - rdr = io.NopCloser(strings.NewReader(engine.StatsCSVContent)) + rdr = io.NopCloser(strings.NewReader(StatsCSVContent)) csvRdr = csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -807,7 +861,7 @@ func TestLoaderProcessRoutes(t *testing.T) { Value: config.NewRSRParsersMustCompile("~*req.15", utils.InfieldSep)}, }, } - rdr := io.NopCloser(strings.NewReader(engine.RoutesCSVContent)) + rdr := io.NopCloser(strings.NewReader(RoutesCSVContent)) csvRdr := csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -887,7 +941,7 @@ func TestLoaderProcessRoutes(t *testing.T) { //cannot set RoutesProfile when dryrun is true ldr.dryRun = true - rdr = io.NopCloser(strings.NewReader(engine.RoutesCSVContent)) + rdr = io.NopCloser(strings.NewReader(RoutesCSVContent)) csvRdr = csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -934,7 +988,7 @@ func TestLoaderProcessChargers(t *testing.T) { Value: config.NewRSRParsersMustCompile("~*req.6", utils.InfieldSep)}, }, } - rdr := io.NopCloser(strings.NewReader(engine.ChargersCSVContent)) + rdr := io.NopCloser(strings.NewReader(ChargersCSVContent)) csvRdr := csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -970,7 +1024,7 @@ func TestLoaderProcessChargers(t *testing.T) { //cannot set chargerProfile when dryrun is true ldr.dryRun = true - rdr = io.NopCloser(strings.NewReader(engine.ChargersCSVContent)) + rdr = io.NopCloser(strings.NewReader(ChargersCSVContent)) csvRdr = csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -1074,7 +1128,7 @@ func TestLoaderProcessDispatches(t *testing.T) { }, }, } - rdr := io.NopCloser(strings.NewReader(engine.DispatcherCSVContent)) + rdr := io.NopCloser(strings.NewReader(DispatcherCSVContent)) csvRdr := csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -1134,7 +1188,7 @@ func TestLoaderProcessDispatches(t *testing.T) { //cannot set DispatchersProfile when dryrun is true ldr.dryRun = true - rdr = io.NopCloser(strings.NewReader(engine.DispatcherCSVContent)) + rdr = io.NopCloser(strings.NewReader(DispatcherCSVContent)) csvRdr = csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -1251,7 +1305,7 @@ func TestLoaderProcessDispatcheHosts(t *testing.T) { }, }, } - rdr := io.NopCloser(strings.NewReader(engine.DispatcherHostCSVContent)) + rdr := io.NopCloser(strings.NewReader(DispatcherHostCSVContent)) csvRdr := csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -1295,7 +1349,7 @@ func TestLoaderProcessDispatcheHosts(t *testing.T) { //cannot set DispatcherHostProfile when dryrun is true ldr.dryRun = true - rdr = io.NopCloser(strings.NewReader(engine.DispatcherHostCSVContent)) + rdr = io.NopCloser(strings.NewReader(DispatcherHostCSVContent)) csvRdr = csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -1331,7 +1385,7 @@ func TestLoaderRemoveContentSingleFile(t *testing.T) { Mandatory: true}, }, } - rdr := io.NopCloser(strings.NewReader(engine.AttributesCSVContent)) + rdr := io.NopCloser(strings.NewReader(AttributesCSVContent)) csvRdr := csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -1399,7 +1453,7 @@ func TestLoaderRemoveContentSingleFile(t *testing.T) { //cannot remove when dryrun is true ldr.dryRun = true - rdr = io.NopCloser(strings.NewReader(engine.AttributesCSVContent)) + rdr = io.NopCloser(strings.NewReader(AttributesCSVContent)) csvRdr = csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ @@ -2842,7 +2896,7 @@ func TestProcessContentEmptyDataBase(t *testing.T) { }, }, } - rdr := io.NopCloser(strings.NewReader(engine.DispatcherHostCSVContent)) + rdr := io.NopCloser(strings.NewReader(DispatcherHostCSVContent)) csvRdr := csv.NewReader(rdr) csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ diff --git a/services/loaders_it_test.go b/services/loaders_it_test.go index fce226150..7f0e58272 100644 --- a/services/loaders_it_test.go +++ b/services/loaders_it_test.go @@ -47,7 +47,11 @@ func testCreateDirs(t *testing.T) { t.Fatal("Error creating folder: ", dir, err) } } - if err := os.WriteFile(path.Join("/tmp/In", utils.AttributesCsv), []byte(engine.AttributesCSVContent), 0644); err != nil { + if err := os.WriteFile(path.Join("/tmp/In", utils.AttributesCsv), []byte(` +#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight +cgrates.org,ALS1,con1,*string:~*req.Account:1001,2014-07-29T15:00:00Z,*string:~*req.Field1:Initial,*req.Field1,*variable,Sub1,true,20 +cgrates.org,ALS1,con2;con3,,,,*req.Field2,*variable,Sub2,true,20 +`), 0644); err != nil { t.Fatal(err.Error()) } }