Add integration test for LoaderS for sub_path in fileName

This commit is contained in:
TeoV
2020-08-05 14:45:39 +03:00
committed by Dan Christian Bogos
parent ef8ca799bb
commit 04a6e94a23
5 changed files with 264 additions and 2 deletions

View File

@@ -105,6 +105,68 @@
],
},
],
},
{
"id": "SubpathLoaderWithoutMove",
"enabled": true,
"dry_run": false,
"tenant": "cgrates.org",
"run_delay": 0,
"lock_filename": ".cgr.lock",
"caches_conns": ["*internal"],
"field_separator": ",",
"tp_in_dir": "/tmp/SubpathWithoutMove",
"tp_out_dir": "",
"data":[
{
"type": "*attributes",
"file_name": "folder1/Attributes.csv",
"fields": [
{"tag": "TenantID", "path": "Tenant", "type": "*variable", "value": "~*req.0", "mandatory": true},
{"tag": "ProfileID", "path": "ID", "type": "*variable", "value": "~*req.1", "mandatory": true},
{"tag": "Contexts", "path": "Contexts", "type": "*variable", "value": "~*req.2"},
{"tag": "FilterIDs", "path": "FilterIDs", "type": "*variable", "value": "~*req.3"},
{"tag": "ActivationInterval", "path": "ActivationInterval", "type": "*variable", "value": "~*req.4"},
{"tag": "AttributeFilterIDs", "path": "AttributeFilterIDs", "type": "*variable", "value": "~*req.5"},
{"tag": "Path", "path": "Path", "type": "*variable", "value": "~*req.6"},
{"tag": "Type", "path": "Type", "type": "*variable", "value": "~*req.7"},
{"tag": "Value", "path": "Value", "type": "*variable", "value": "~*req.8"},
{"tag": "Blocker", "path": "Blocker", "type": "*variable", "value": "~*req.9"},
{"tag": "Weight", "path": "Weight", "type": "*variable", "value": "~*req.10"},
],
},
],
},
{
"id": "SubpathLoaderWithMove",
"enabled": true,
"dry_run": false,
"tenant": "cgrates.org",
"run_delay": 0,
"lock_filename": ".cgr.lock",
"caches_conns": ["*internal"],
"field_separator": ",",
"tp_in_dir": "/tmp/SubpathLoaderWithMove",
"tp_out_dir": "/tmp/SubpathOut",
"data":[
{
"type": "*attributes",
"file_name": "folder1/Attributes.csv",
"fields": [
{"tag": "TenantID", "path": "Tenant", "type": "*variable", "value": "~*req.0", "mandatory": true},
{"tag": "ProfileID", "path": "ID", "type": "*variable", "value": "~*req.1", "mandatory": true},
{"tag": "Contexts", "path": "Contexts", "type": "*variable", "value": "~*req.2"},
{"tag": "FilterIDs", "path": "FilterIDs", "type": "*variable", "value": "~*req.3"},
{"tag": "ActivationInterval", "path": "ActivationInterval", "type": "*variable", "value": "~*req.4"},
{"tag": "AttributeFilterIDs", "path": "AttributeFilterIDs", "type": "*variable", "value": "~*req.5"},
{"tag": "Path", "path": "Path", "type": "*variable", "value": "~*req.6"},
{"tag": "Type", "path": "Type", "type": "*variable", "value": "~*req.7"},
{"tag": "Value", "path": "Value", "type": "*variable", "value": "~*req.8"},
{"tag": "Blocker", "path": "Blocker", "type": "*variable", "value": "~*req.9"},
{"tag": "Weight", "path": "Weight", "type": "*variable", "value": "~*req.10"},
],
},
],
}
],

View File

@@ -145,6 +145,68 @@
],
},
],
},
{
"id": "SubpathLoaderWithoutMove",
"enabled": true,
"dry_run": false,
"tenant": "cgrates.org",
"run_delay": 0,
"lock_filename": ".cgr.lock",
"caches_conns": ["*internal"],
"field_separator": ",",
"tp_in_dir": "/tmp/SubpathWithoutMove",
"tp_out_dir": "",
"data":[
{
"type": "*attributes",
"file_name": "folder1/Attributes.csv",
"fields": [
{"tag": "TenantID", "path": "Tenant", "type": "*variable", "value": "~*req.0", "mandatory": true},
{"tag": "ProfileID", "path": "ID", "type": "*variable", "value": "~*req.1", "mandatory": true},
{"tag": "Contexts", "path": "Contexts", "type": "*variable", "value": "~*req.2"},
{"tag": "FilterIDs", "path": "FilterIDs", "type": "*variable", "value": "~*req.3"},
{"tag": "ActivationInterval", "path": "ActivationInterval", "type": "*variable", "value": "~*req.4"},
{"tag": "AttributeFilterIDs", "path": "AttributeFilterIDs", "type": "*variable", "value": "~*req.5"},
{"tag": "Path", "path": "Path", "type": "*variable", "value": "~*req.6"},
{"tag": "Type", "path": "Type", "type": "*variable", "value": "~*req.7"},
{"tag": "Value", "path": "Value", "type": "*variable", "value": "~*req.8"},
{"tag": "Blocker", "path": "Blocker", "type": "*variable", "value": "~*req.9"},
{"tag": "Weight", "path": "Weight", "type": "*variable", "value": "~*req.10"},
],
},
],
},
{
"id": "SubpathLoaderWithMove",
"enabled": true,
"dry_run": false,
"tenant": "cgrates.org",
"run_delay": 0,
"lock_filename": ".cgr.lock",
"caches_conns": ["*internal"],
"field_separator": ",",
"tp_in_dir": "/tmp/SubpathLoaderWithMove",
"tp_out_dir": "/tmp/SubpathOut",
"data":[
{
"type": "*attributes",
"file_name": "folder1/Attributes.csv",
"fields": [
{"tag": "TenantID", "path": "Tenant", "type": "*variable", "value": "~*req.0", "mandatory": true},
{"tag": "ProfileID", "path": "ID", "type": "*variable", "value": "~*req.1", "mandatory": true},
{"tag": "Contexts", "path": "Contexts", "type": "*variable", "value": "~*req.2"},
{"tag": "FilterIDs", "path": "FilterIDs", "type": "*variable", "value": "~*req.3"},
{"tag": "ActivationInterval", "path": "ActivationInterval", "type": "*variable", "value": "~*req.4"},
{"tag": "AttributeFilterIDs", "path": "AttributeFilterIDs", "type": "*variable", "value": "~*req.5"},
{"tag": "Path", "path": "Path", "type": "*variable", "value": "~*req.6"},
{"tag": "Type", "path": "Type", "type": "*variable", "value": "~*req.7"},
{"tag": "Value", "path": "Value", "type": "*variable", "value": "~*req.8"},
{"tag": "Blocker", "path": "Blocker", "type": "*variable", "value": "~*req.9"},
{"tag": "Weight", "path": "Weight", "type": "*variable", "value": "~*req.10"},
],
},
],
}
],

View File

@@ -106,6 +106,68 @@
],
},
],
},
{
"id": "SubpathLoaderWithoutMove",
"enabled": true,
"dry_run": false,
"tenant": "cgrates.org",
"run_delay": 0,
"lock_filename": ".cgr.lock",
"caches_conns": ["*internal"],
"field_separator": ",",
"tp_in_dir": "/tmp/SubpathWithoutMove",
"tp_out_dir": "",
"data":[
{
"type": "*attributes",
"file_name": "folder1/Attributes.csv",
"fields": [
{"tag": "TenantID", "path": "Tenant", "type": "*variable", "value": "~*req.0", "mandatory": true},
{"tag": "ProfileID", "path": "ID", "type": "*variable", "value": "~*req.1", "mandatory": true},
{"tag": "Contexts", "path": "Contexts", "type": "*variable", "value": "~*req.2"},
{"tag": "FilterIDs", "path": "FilterIDs", "type": "*variable", "value": "~*req.3"},
{"tag": "ActivationInterval", "path": "ActivationInterval", "type": "*variable", "value": "~*req.4"},
{"tag": "AttributeFilterIDs", "path": "AttributeFilterIDs", "type": "*variable", "value": "~*req.5"},
{"tag": "Path", "path": "Path", "type": "*variable", "value": "~*req.6"},
{"tag": "Type", "path": "Type", "type": "*variable", "value": "~*req.7"},
{"tag": "Value", "path": "Value", "type": "*variable", "value": "~*req.8"},
{"tag": "Blocker", "path": "Blocker", "type": "*variable", "value": "~*req.9"},
{"tag": "Weight", "path": "Weight", "type": "*variable", "value": "~*req.10"},
],
},
],
},
{
"id": "SubpathLoaderWithMove",
"enabled": true,
"dry_run": false,
"tenant": "cgrates.org",
"run_delay": 0,
"lock_filename": ".cgr.lock",
"caches_conns": ["*internal"],
"field_separator": ",",
"tp_in_dir": "/tmp/SubpathLoaderWithMove",
"tp_out_dir": "/tmp/SubpathOut",
"data":[
{
"type": "*attributes",
"file_name": "folder1/Attributes.csv",
"fields": [
{"tag": "TenantID", "path": "Tenant", "type": "*variable", "value": "~*req.0", "mandatory": true},
{"tag": "ProfileID", "path": "ID", "type": "*variable", "value": "~*req.1", "mandatory": true},
{"tag": "Contexts", "path": "Contexts", "type": "*variable", "value": "~*req.2"},
{"tag": "FilterIDs", "path": "FilterIDs", "type": "*variable", "value": "~*req.3"},
{"tag": "ActivationInterval", "path": "ActivationInterval", "type": "*variable", "value": "~*req.4"},
{"tag": "AttributeFilterIDs", "path": "AttributeFilterIDs", "type": "*variable", "value": "~*req.5"},
{"tag": "Path", "path": "Path", "type": "*variable", "value": "~*req.6"},
{"tag": "Type", "path": "Type", "type": "*variable", "value": "~*req.7"},
{"tag": "Value", "path": "Value", "type": "*variable", "value": "~*req.8"},
{"tag": "Blocker", "path": "Blocker", "type": "*variable", "value": "~*req.9"},
{"tag": "Weight", "path": "Weight", "type": "*variable", "value": "~*req.10"},
],
},
],
}
],

View File

@@ -35,6 +35,9 @@ var (
dbType = flag.String("dbtype", utils.MetaInternal, "The type of DataBase (Internal/Mongo/mySql)")
)
var loaderPaths = []string{"/tmp/In", "/tmp/Out", "/tmp/LoaderIn", "/tmp/SubpathWithoutMove",
"/tmp/SubpathLoaderWithMove", "/tmp/SubpathOut"}
func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) {
switch *encoding {
case utils.MetaJSON:

View File

@@ -55,6 +55,16 @@ var (
testLoaderLoadAttributesWithoutMoving,
testLoaderVerifyOutDirWithoutMoving,
testLoaderCheckAttributes,
testLoaderResetDataDB,
testLoaderPopulateDataWithSubpath,
testLoaderLoadAttributesWithSubpath,
testLoaderVerifyOutDirWithSubpath,
testLoaderCheckAttributes,
testLoaderResetDataDB,
testLoaderPopulateDataWithSubpathWithMove,
testLoaderLoadAttributesWithoutSubpathWithMove,
testLoaderVerifyOutDirWithSubpathWithMove,
testLoaderCheckAttributes,
testLoaderKillEngine,
}
)
@@ -74,7 +84,6 @@ func TestLoaderIT(t *testing.T) {
t.Fatal("Unknown Database type")
}
loaderCfgDIR = "tutmysql"
for _, stest := range sTestsLoader {
t.Run(loaderCfgDIR, stest)
}
@@ -93,7 +102,7 @@ func testLoaderInitCfg(t *testing.T) {
func testLoaderMakeFolders(t *testing.T) {
// active the loaders here
for _, dir := range []string{"/tmp/In", "/tmp/Out", "/tmp/LoaderIn"} {
for _, dir := range loaderPaths {
if err := os.RemoveAll(dir); err != nil {
t.Fatal("Error removing folder: ", dir, err)
}
@@ -108,6 +117,7 @@ func testLoaderResetDataDB(t *testing.T) {
if err := engine.InitDataDb(loaderCfg); err != nil {
t.Fatal(err)
}
engine.Cache.Clear(nil)
}
// Start CGR Engine
@@ -226,6 +236,69 @@ func testLoaderVerifyOutDirWithoutMoving(t *testing.T) {
}
}
func testLoaderPopulateDataWithSubpath(t *testing.T) {
fileName := utils.AttributesCsv
tmpFilePath := path.Join("/tmp/", fileName)
if err := ioutil.WriteFile(tmpFilePath, []byte(engine.AttributesCSVContent), 0777); err != nil {
t.Fatal(err.Error())
}
if err := os.MkdirAll("/tmp/SubpathWithoutMove/folder1", 0755); err != nil {
t.Fatal("Error creating folder: /tmp/SubpathWithoutMove/folder1", err)
}
if err := os.Rename(tmpFilePath, path.Join("/tmp/SubpathWithoutMove/folder1", fileName)); err != nil {
t.Fatal("Error moving file to processing directory: ", err)
}
}
func testLoaderLoadAttributesWithSubpath(t *testing.T) {
var reply string
if err := loaderRPC.Call(utils.LoaderSv1Load,
&ArgsProcessFolder{LoaderID: "SubpathLoaderWithoutMove"}, &reply); err != nil {
t.Error(err)
}
}
func testLoaderVerifyOutDirWithSubpath(t *testing.T) {
time.Sleep(100 * time.Millisecond)
// we expect that after the LoaderS process the file leave in in the input folder
if outContent1, err := ioutil.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))
}
}
func testLoaderPopulateDataWithSubpathWithMove(t *testing.T) {
fileName := utils.AttributesCsv
tmpFilePath := path.Join("/tmp/", fileName)
if err := ioutil.WriteFile(tmpFilePath, []byte(engine.AttributesCSVContent), 0777); err != nil {
t.Fatal(err.Error())
}
if err := os.MkdirAll("/tmp/SubpathLoaderWithMove/folder1", 0755); err != nil {
t.Fatal("Error creating folder: /tmp/SubpathLoaderWithMove/folder1", err)
}
if err := os.Rename(tmpFilePath, path.Join("/tmp/SubpathLoaderWithMove/folder1", fileName)); err != nil {
t.Fatal("Error moving file to processing directory: ", err)
}
}
func testLoaderLoadAttributesWithoutSubpathWithMove(t *testing.T) {
var reply string
if err := loaderRPC.Call(utils.LoaderSv1Load,
&ArgsProcessFolder{LoaderID: "SubpathLoaderWithMove"}, &reply); err != nil {
t.Error(err)
}
}
func testLoaderVerifyOutDirWithSubpathWithMove(t *testing.T) {
time.Sleep(100 * time.Millisecond)
if outContent1, err := ioutil.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))
}
}
func testLoaderKillEngine(t *testing.T) {
if err := engine.KillEngine(100); err != nil {
t.Error(err)