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:
ionutboangiu
2024-04-02 19:13:36 +03:00
committed by Dan Christian Bogos
parent b9a39e233f
commit 5116a23f5b
5 changed files with 88 additions and 97 deletions

View File

@@ -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)
}
}

View File

@@ -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",
}

View File

@@ -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)
}
}

View File

@@ -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)
}
}