mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Added test cgr-loader flushStorDB
This commit is contained in:
committed by
Dan Christian Bogos
parent
f2a166215c
commit
29466d8770
@@ -87,7 +87,7 @@ var (
|
||||
`Separator for csv file (by default "," is used)`)
|
||||
|
||||
importID = cgrLoaderFlags.String("import_id", utils.EmptyString, "Uniquely identify an import/load, postpended to some automatic fields")
|
||||
timezone = cgrLoaderFlags.String("timezone", utils.EmptyString, `Timezone for timestamps where not specified <""|UTC|Local|$IANA_TZ_DB>`)
|
||||
timezone = cgrLoaderFlags.String("timezone", dfltCfg.GeneralCfg().DefaultTimezone, `Timezone for timestamps where not specified <""|UTC|Local|$IANA_TZ_DB>`)
|
||||
disableReverse = cgrLoaderFlags.Bool("disable_reverse_mappings", false, "Will disable reverse mappings rebuilding")
|
||||
flushStorDB = cgrLoaderFlags.Bool("flush_stordb", false, "Remove tariff plan data for id from the database")
|
||||
remove = cgrLoaderFlags.Bool("remove", false, "Will remove instead of adding data from DB")
|
||||
|
||||
@@ -37,6 +37,7 @@ import (
|
||||
|
||||
var (
|
||||
dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here")
|
||||
dbType = flag.String("dbtype", utils.MetaInternal, "The type of DataBase (Internal/Mongo/mySql)")
|
||||
)
|
||||
|
||||
func TestLoadConfig(t *testing.T) {
|
||||
@@ -93,6 +94,7 @@ func TestLoadConfig(t *testing.T) {
|
||||
// General
|
||||
*cachingArg = utils.MetaLoad
|
||||
*dbDataEncoding = utils.MetaJSON
|
||||
*timezone = utils.Local
|
||||
ldrCfg := loadConfig()
|
||||
ldrCfg.DataDbCfg().Items = nil
|
||||
ldrCfg.StorDbCfg().Items = nil
|
||||
@@ -102,6 +104,9 @@ func TestLoadConfig(t *testing.T) {
|
||||
if ldrCfg.GeneralCfg().DBDataEncoding != utils.MetaJSON {
|
||||
t.Errorf("Expected %s received %s", utils.MetaJSON, ldrCfg.GeneralCfg().DBDataEncoding)
|
||||
}
|
||||
if ldrCfg.GeneralCfg().DefaultTimezone != utils.Local {
|
||||
t.Errorf("Expected %s received %s", utils.Local, ldrCfg.GeneralCfg().DefaultTimezone)
|
||||
}
|
||||
if !reflect.DeepEqual(ldrCfg.StorDbCfg(), expStorDB) {
|
||||
t.Errorf("Expected %s received %s", utils.ToJSON(expStorDB), utils.ToJSON(ldrCfg.StorDbCfg()))
|
||||
}
|
||||
@@ -168,6 +173,7 @@ func TestLoadConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
var (
|
||||
ldrItCfgDir string
|
||||
ldrItCfgPath string
|
||||
ldrItCfg *config.CGRConfig
|
||||
db engine.DataDB
|
||||
@@ -181,6 +187,12 @@ var (
|
||||
testLoadItCheckAttributes,
|
||||
testLoadItStartLoaderRemove,
|
||||
testLoadItCheckAttributes2,
|
||||
|
||||
testLoadItStartLoaderToStorDB,
|
||||
testLoadItStartLoaderFlushStorDB,
|
||||
testLoadItStartLoaderFromStorDB,
|
||||
testLoadItCheckAttributes2,
|
||||
|
||||
testLoadItStartLoaderToStorDB,
|
||||
testLoadItCheckAttributes2,
|
||||
testLoadItStartLoaderFromStorDB,
|
||||
@@ -189,6 +201,18 @@ var (
|
||||
)
|
||||
|
||||
func TestLoadIt(t *testing.T) {
|
||||
switch *dbType {
|
||||
case utils.MetaInternal:
|
||||
ldrItCfgDir = "tutinternal"
|
||||
case utils.MetaMySQL:
|
||||
ldrItCfgDir = "tutmysql"
|
||||
case utils.MetaMongo:
|
||||
ldrItCfgDir = "tutmongo"
|
||||
case utils.MetaPostgres:
|
||||
t.SkipNow()
|
||||
default:
|
||||
t.Fatal("Unknown Database type")
|
||||
}
|
||||
for _, stest := range ldrItTests {
|
||||
t.Run("TestLoadIt", stest)
|
||||
}
|
||||
@@ -196,7 +220,7 @@ func TestLoadIt(t *testing.T) {
|
||||
|
||||
func testLoadItLoadConfig(t *testing.T) {
|
||||
var err error
|
||||
ldrItCfgPath = path.Join(*dataDir, "conf", "samples", "tutmongo")
|
||||
ldrItCfgPath = path.Join(*dataDir, "conf", "samples", ldrItCfgDir)
|
||||
if ldrItCfg, err = config.NewCGRConfigFromPath(ldrItCfgPath); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -311,3 +335,17 @@ func testLoadItStartLoaderFromStorDB(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testLoadItStartLoaderFlushStorDB(t *testing.T) {
|
||||
cmd := exec.Command("cgr-loader", "-config_path="+ldrItCfgPath, "-path="+path.Join(*dataDir, "tariffplans", "tutorial"), "-caches_address=", "-scheduler_address=", "-flush_stordb", "-tpid=TPID")
|
||||
output := bytes.NewBuffer(nil)
|
||||
outerr := bytes.NewBuffer(nil)
|
||||
cmd.Stdout = output
|
||||
cmd.Stderr = outerr
|
||||
if err := cmd.Run(); err != nil {
|
||||
t.Log(cmd.Args)
|
||||
t.Log(output.String())
|
||||
t.Log(outerr.String())
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,9 @@ results+=($?)
|
||||
echo "go test github.com/cgrates/cgrates/apier/v1 -tags=offline $@"
|
||||
go test github.com/cgrates/cgrates/apier/v1 -tags=offline $@
|
||||
results+=($?)
|
||||
echo "go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=offline $@"
|
||||
go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=integration $@
|
||||
results+=($?)
|
||||
else
|
||||
# Internal
|
||||
echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*internal'
|
||||
@@ -69,6 +72,9 @@ results+=($?)
|
||||
echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*internal'
|
||||
go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*internal
|
||||
results+=($?)
|
||||
echo "go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=offline -dbtype=*internal"
|
||||
go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=integration -dbtype=*internal
|
||||
results+=($?)
|
||||
# SQL
|
||||
echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*mysql'
|
||||
go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*mysql
|
||||
@@ -100,6 +106,9 @@ results+=($?)
|
||||
echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*mysql'
|
||||
go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*mysql
|
||||
results+=($?)
|
||||
echo "go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=offline -dbtype=*mysql"
|
||||
go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=integration -dbtype=*mysql
|
||||
results+=($?)
|
||||
# Mongo
|
||||
echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*mongo'
|
||||
go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*mongo
|
||||
@@ -131,6 +140,9 @@ results+=($?)
|
||||
echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*mongo'
|
||||
go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*mongo
|
||||
results+=($?)
|
||||
echo "go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=offline -dbtype=*mongo"
|
||||
go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=integration -dbtype=*mongo
|
||||
results+=($?)
|
||||
# Postgres
|
||||
echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*postgres'
|
||||
go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*postgres
|
||||
@@ -162,7 +174,9 @@ results+=($?)
|
||||
echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*postgres'
|
||||
go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*postgres
|
||||
results+=($?)
|
||||
|
||||
echo "go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=offline -dbtype=*postgres"
|
||||
go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=integration -dbtype=*postgres
|
||||
results+=($?)
|
||||
fi
|
||||
|
||||
echo 'go test github.com/cgrates/cgrates/config -tags=integration'
|
||||
|
||||
Reference in New Issue
Block a user