mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Set ChargerProfile through TPs instead of API in tests
Only for agents/ers tests. Done to prevent cyclic imports when adding ers APIs to apier package. In case of v2.AttrSetAccount, use a literal struct instead.
This commit is contained in:
committed by
Dan Christian Bogos
parent
b9a39e233f
commit
5116a23f5b
@@ -32,7 +32,6 @@ import (
|
||||
"github.com/cgrates/birpc/context"
|
||||
|
||||
"github.com/cgrates/birpc"
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
@@ -117,20 +116,23 @@ func testFWVITRpcConn(t *testing.T) {
|
||||
|
||||
func testFWVITLoadTPFromFolder(t *testing.T) {
|
||||
//add a default charger
|
||||
chargerProfile := &v1.ChargerWithAPIOpts{
|
||||
ChargerProfile: &engine.ChargerProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Default",
|
||||
RunID: utils.MetaDefault,
|
||||
AttributeIDs: []string{"*none"},
|
||||
Weight: 20,
|
||||
},
|
||||
tpDirPath := t.TempDir()
|
||||
filePath := path.Join(tpDirPath, utils.ChargersCsv)
|
||||
err := os.WriteFile(filePath,
|
||||
[]byte(`cgrates.org,Default,,,*default,*none,20`),
|
||||
0644)
|
||||
if err != nil {
|
||||
t.Errorf("could not write to file %s: %v",
|
||||
filePath, err)
|
||||
}
|
||||
var result string
|
||||
if err := fwvRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
var reply string
|
||||
args := &utils.AttrLoadTpFromFolder{FolderPath: tpDirPath}
|
||||
err = fwvRPC.Call(context.Background(),
|
||||
utils.APIerSv1LoadTariffPlanFromFolder,
|
||||
args, &reply)
|
||||
if err != nil {
|
||||
t.Errorf("%s call failed for path %s: %v",
|
||||
utils.APIerSv1LoadTariffPlanFromFolder, tpDirPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,6 @@ import (
|
||||
"github.com/cgrates/birpc/context"
|
||||
|
||||
"github.com/cgrates/birpc"
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
v2 "github.com/cgrates/cgrates/apier/v2"
|
||||
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
|
||||
@@ -133,30 +131,30 @@ func testJSONRpcConn(t *testing.T) {
|
||||
}
|
||||
|
||||
func testJSONAddData(t *testing.T) {
|
||||
var reply string
|
||||
//add a charger
|
||||
chargerProfile := &v1.ChargerWithAPIOpts{
|
||||
ChargerProfile: &engine.ChargerProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Default",
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
},
|
||||
RunID: utils.MetaDefault,
|
||||
AttributeIDs: []string{"*none"},
|
||||
Weight: 20,
|
||||
},
|
||||
APIOpts: map[string]any{
|
||||
utils.CacheOpt: utils.MetaReload,
|
||||
},
|
||||
tpDirPath := t.TempDir()
|
||||
filePath := path.Join(tpDirPath, utils.ChargersCsv)
|
||||
err := os.WriteFile(filePath,
|
||||
[]byte("cgrates.org,Default,,2014-07-14T14:35:00Z,*default,*none,20"),
|
||||
0644)
|
||||
if err != nil {
|
||||
t.Errorf("could not write to file %s: %v",
|
||||
filePath, err)
|
||||
}
|
||||
if err := jsonRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
var reply string
|
||||
args := &utils.AttrLoadTpFromFolder{FolderPath: tpDirPath}
|
||||
err = jsonRPC.Call(context.Background(),
|
||||
utils.APIerSv1LoadTariffPlanFromFolder,
|
||||
args, &reply)
|
||||
if err != nil {
|
||||
t.Errorf("%s call failed for path %s: %v",
|
||||
utils.APIerSv1LoadTariffPlanFromFolder, tpDirPath, err)
|
||||
}
|
||||
|
||||
attrSetAcnt := v2.AttrSetAccount{
|
||||
attrSetAcnt := struct {
|
||||
Tenant string
|
||||
Account string
|
||||
}{
|
||||
Tenant: "cgrates.org",
|
||||
Account: "voiceAccount",
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import (
|
||||
"github.com/cgrates/birpc/context"
|
||||
|
||||
"github.com/cgrates/birpc"
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
@@ -159,20 +158,23 @@ func testFlatstoreITRpcConn(t *testing.T) {
|
||||
|
||||
func testFlatstoreITLoadTPFromFolder(t *testing.T) {
|
||||
//add a default charger
|
||||
chargerProfile := &v1.ChargerWithAPIOpts{
|
||||
ChargerProfile: &engine.ChargerProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Default",
|
||||
RunID: utils.MetaDefault,
|
||||
AttributeIDs: []string{"*none"},
|
||||
Weight: 20,
|
||||
},
|
||||
tpDirPath := t.TempDir()
|
||||
filePath := path.Join(tpDirPath, utils.ChargersCsv)
|
||||
err := os.WriteFile(filePath,
|
||||
[]byte("cgrates.org,Default,,,*default,*none,20"),
|
||||
0644)
|
||||
if err != nil {
|
||||
t.Errorf("could not write to file %s: %v",
|
||||
filePath, err)
|
||||
}
|
||||
var result string
|
||||
if err := flatstoreRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
var reply string
|
||||
args := &utils.AttrLoadTpFromFolder{FolderPath: tpDirPath}
|
||||
err = flatstoreRPC.Call(context.Background(),
|
||||
utils.APIerSv1LoadTariffPlanFromFolder,
|
||||
args, &reply)
|
||||
if err != nil {
|
||||
t.Errorf("%s call failed for path %s: %v",
|
||||
utils.APIerSv1LoadTariffPlanFromFolder, tpDirPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import (
|
||||
"github.com/cgrates/birpc/context"
|
||||
|
||||
"github.com/cgrates/birpc"
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
@@ -128,20 +127,23 @@ func testPartITRpcConn(t *testing.T) {
|
||||
|
||||
func testPartITLoadTPFromFolder(t *testing.T) {
|
||||
//add a default charger
|
||||
chargerProfile := &v1.ChargerWithAPIOpts{
|
||||
ChargerProfile: &engine.ChargerProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Default",
|
||||
RunID: utils.MetaDefault,
|
||||
AttributeIDs: []string{"*none"},
|
||||
Weight: 20,
|
||||
},
|
||||
tpDirPath := t.TempDir()
|
||||
filePath := path.Join(tpDirPath, utils.ChargersCsv)
|
||||
err := os.WriteFile(filePath,
|
||||
[]byte("cgrates.org,Default,,,*default,*none,20"),
|
||||
0644)
|
||||
if err != nil {
|
||||
t.Errorf("could not write to file %s: %v",
|
||||
filePath, err)
|
||||
}
|
||||
var result string
|
||||
if err := partRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
var reply string
|
||||
args := &utils.AttrLoadTpFromFolder{FolderPath: tpDirPath}
|
||||
err = partRPC.Call(context.Background(),
|
||||
utils.APIerSv1LoadTariffPlanFromFolder,
|
||||
args, &reply)
|
||||
if err != nil {
|
||||
t.Errorf("%s call failed for path %s: %v",
|
||||
utils.APIerSv1LoadTariffPlanFromFolder, tpDirPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user