Updated IT tests in apier

This commit is contained in:
adragusin
2020-01-10 15:12:22 +02:00
parent 200e51604f
commit a7cb91a40e
6 changed files with 450 additions and 37 deletions

View File

@@ -21,10 +21,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package v1
import (
"path"
"reflect"
"testing"
"time"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/sessions"
"github.com/cgrates/cgrates/utils"
@@ -51,35 +53,99 @@ var sTestSessionSv1ProcessEvent = []func(t *testing.T){
}
func TestSSv1ItProcessEventWithPrepaid(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
sessionsConfDIR = "sessions_internal"
case utils.MetaSQL:
sessionsConfDIR = "sessions_mysql"
case utils.MetaMongo:
sessionsConfDIR = "sessions_mongo"
case utils.MetaPostgres:
t.SkipNow()
default:
t.Fatal("Unknown Database type")
}
sSV1RequestType = utils.META_PREPAID
for _, stest := range sTestSessionSv1ProcessEvent {
t.Run(sSV1RequestType, stest)
t.Run(sessionsConfDIR+utils.EmptyString+sSV1RequestType, stest)
}
}
func TestSSv1ItProcessEventWithPostPaid(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
sessionsConfDIR = "sessions_internal"
case utils.MetaSQL:
sessionsConfDIR = "sessions_mysql"
case utils.MetaMongo:
sessionsConfDIR = "sessions_mongo"
case utils.MetaPostgres:
t.SkipNow()
default:
t.Fatal("Unknown Database type")
}
sSV1RequestType = utils.META_POSTPAID
sTestSessionSv1ProcessEvent = append(sTestSessionSv1ProcessEvent[:len(sTestSessionSv1ProcessEvent)-3], testSSv1ItStopCgrEngine)
for _, stest := range sTestSessionSv1ProcessEvent {
t.Run(sSV1RequestType, stest)
t.Run(sessionsConfDIR+utils.EmptyString+sSV1RequestType, stest)
}
}
func TestSSv1ItProcessEventWithRated(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
sessionsConfDIR = "sessions_internal"
case utils.MetaSQL:
sessionsConfDIR = "sessions_mysql"
case utils.MetaMongo:
sessionsConfDIR = "sessions_mongo"
case utils.MetaPostgres:
t.SkipNow()
default:
t.Fatal("Unknown Database type")
}
sSV1RequestType = utils.META_RATED
sTestSessionSv1ProcessEvent = append(sTestSessionSv1ProcessEvent[:len(sTestSessionSv1ProcessEvent)-3], testSSv1ItStopCgrEngine)
for _, stest := range sTestSessionSv1ProcessEvent {
t.Run(sSV1RequestType, stest)
t.Run(sessionsConfDIR+utils.EmptyString+sSV1RequestType, stest)
}
}
func TestSSv1ItProcessEventWithPseudoPrepaid(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
sessionsConfDIR = "sessions_internal"
case utils.MetaSQL:
sessionsConfDIR = "sessions_mysql"
case utils.MetaMongo:
sessionsConfDIR = "sessions_mongo"
case utils.MetaPostgres:
t.SkipNow()
default:
t.Fatal("Unknown Database type")
}
sSV1RequestType = utils.META_PSEUDOPREPAID
for _, stest := range sTestSessionSv1ProcessEvent {
t.Run(sSV1RequestType, stest)
t.Run(sessionsConfDIR+utils.EmptyString+sSV1RequestType, stest)
}
}
func testSSv1ItInitCfg(t *testing.T) {
var err error
sSv1CfgPath = path.Join(*dataDir, "conf", "samples", sessionsConfDIR)
// Init config first
sSv1Cfg, err = config.NewCGRConfigFromPath(sSv1CfgPath)
if err != nil {
t.Error(err)
}
sSv1Cfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
config.SetCgrConfig(sSv1Cfg)
}
func testSSv1ItProcessEventAuth(t *testing.T) {
authUsage := 5 * time.Minute
args := &sessions.V1ProcessEventArgs{
@@ -109,7 +175,7 @@ func testSSv1ItProcessEventAuth(t *testing.T) {
if rply.MaxUsage != authUsage {
t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
}
if *rply.ResourceMessage == "" {
if *rply.ResourceMessage == utils.EmptyString {
t.Errorf("Unexpected ResourceMessage: %s", *rply.ResourceMessage)
}
eSplrs := &engine.SortedSuppliers{

View File

@@ -40,8 +40,48 @@ var (
sSv1BiRpc2 *rpc2.Client
sSApierRpc2 *rpc.Client
disconnectEvChan2 = make(chan *utils.AttrDisconnectSession)
sessionsConfDIR string
sessionsThresholdTests = []func(t *testing.T){
testSessionSv1ItInitCfg,
testSessionSv1ItResetDataDb,
testSessionSv1ItResetStorDb,
testSessionSv1ItStartEngine,
testSessionSv1ItRpcConn,
testSessionSv1ItTPFromFolder,
testSessionSv1ItGetThreshold,
testSessionSv1ItAuth,
testSessionSv1ItInitiateSession,
testSessionSv1ItTerminateSession,
testSessionSv1ItAuthNotFoundThreshold,
testSessionSv1ItInitNotFoundThreshold,
testSessionSv1ItTerminateNotFoundThreshold,
testSessionSv1ItAuthNotFoundThresholdAndStats,
testSessionSv1ItInitNotFoundThresholdAndStats,
testSessionSv1ItTerminateNotFoundThresholdAndStats,
testSessionSv1ItStopCgrEngine,
}
)
func TestSessionSITtests(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
sessionsConfDIR = "sessions_internal"
case utils.MetaSQL:
sessionsConfDIR = "sessions_mysql"
case utils.MetaMongo:
sessionsConfDIR = "sessions_mongo"
case utils.MetaPostgres:
t.SkipNow()
default:
t.Fatal("Unknown Database type")
}
for _, stest := range sessionsThresholdTests {
t.Run(sessionsConfDIR, stest)
}
}
func handleDisconnectSession2(clnt *rpc2.Client,
args *utils.AttrDisconnectSession, reply *string) error {
disconnectEvChan2 <- args
@@ -49,9 +89,9 @@ func handleDisconnectSession2(clnt *rpc2.Client,
return nil
}
func TestSessionSv1ItInitCfg(t *testing.T) {
func testSessionSv1ItInitCfg(t *testing.T) {
var err error
sSv1CfgPath2 = path.Join(*dataDir, "conf", "samples", "sessions")
sSv1CfgPath2 = path.Join(*dataDir, "conf", "samples", sessionsConfDIR)
// Init config first
sSv1Cfg2, err = config.NewCGRConfigFromPath(sSv1CfgPath2)
if err != nil {
@@ -61,25 +101,25 @@ func TestSessionSv1ItInitCfg(t *testing.T) {
config.SetCgrConfig(sSv1Cfg2)
}
func TestSessionSv1ItResetDataDb(t *testing.T) {
func testSessionSv1ItResetDataDb(t *testing.T) {
if err := engine.InitDataDb(sSv1Cfg2); err != nil {
t.Fatal(err)
}
}
func TestSessionSv1ItResetStorDb(t *testing.T) {
func testSessionSv1ItResetStorDb(t *testing.T) {
if err := engine.InitStorDb(sSv1Cfg2); err != nil {
t.Fatal(err)
}
}
func TestSessionSv1ItStartEngine(t *testing.T) {
func testSessionSv1ItStartEngine(t *testing.T) {
if _, err := engine.StopStartEngine(sSv1CfgPath2, 100); err != nil {
t.Fatal(err)
}
}
func TestSessionSv1ItRpcConn(t *testing.T) {
func testSessionSv1ItRpcConn(t *testing.T) {
dummyClnt, err := utils.NewBiJSONrpcClient(sSv1Cfg2.SessionSCfg().ListenBijson,
nil)
if err != nil {
@@ -99,18 +139,17 @@ func TestSessionSv1ItRpcConn(t *testing.T) {
}
// Load the tariff plan, creating accounts and their balances
func TestSessionSv1ItTPFromFolder(t *testing.T) {
func testSessionSv1ItTPFromFolder(t *testing.T) {
attrs := &utils.AttrLoadTpFromFolder{
FolderPath: path.Join(*dataDir, "tariffplans", "testit")}
var loadInst utils.LoadInstance
if err := sSApierRpc2.Call(utils.ApierV2LoadTariffPlanFromFolder,
attrs, &loadInst); err != nil {
if err := sSApierRpc2.Call(utils.ApierV2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil {
t.Error(err)
}
time.Sleep(500 * time.Millisecond)
}
func TestSessionSv1ItGetThreshold(t *testing.T) {
func testSessionSv1ItGetThreshold(t *testing.T) {
tPrfl := &engine.ThresholdProfile{
Tenant: "cgrates.org",
ID: "THD_ACNT_1001",
@@ -165,7 +204,7 @@ func TestSessionSv1ItGetThreshold(t *testing.T) {
}
}
func TestSessionSv1ItAuth(t *testing.T) {
func testSessionSv1ItAuth(t *testing.T) {
args := &sessions.V1AuthorizeArgs{
AuthorizeResources: true,
ProcessThresholds: true,
@@ -224,7 +263,7 @@ func TestSessionSv1ItAuth(t *testing.T) {
}
}
func TestSessionSv1ItInitiateSession(t *testing.T) {
func testSessionSv1ItInitiateSession(t *testing.T) {
initUsage := 5 * time.Minute
args := &sessions.V1InitSessionArgs{
InitSession: true,
@@ -287,7 +326,7 @@ func TestSessionSv1ItInitiateSession(t *testing.T) {
}
}
func TestSessionSv1ItTerminateSession(t *testing.T) {
func testSessionSv1ItTerminateSession(t *testing.T) {
args := &sessions.V1TerminateSessionArgs{
TerminateSession: true,
ReleaseResources: true,
@@ -344,7 +383,7 @@ func TestSessionSv1ItTerminateSession(t *testing.T) {
}
}
func TestSessionSv1ItAuthNotFoundThreshold(t *testing.T) {
func testSessionSv1ItAuthNotFoundThreshold(t *testing.T) {
args := &sessions.V1AuthorizeArgs{
ProcessStats: true,
GetMaxUsage: true,
@@ -376,7 +415,7 @@ func TestSessionSv1ItAuthNotFoundThreshold(t *testing.T) {
}
}
func TestSessionSv1ItInitNotFoundThreshold(t *testing.T) {
func testSessionSv1ItInitNotFoundThreshold(t *testing.T) {
initUsage := 1024
args := &sessions.V1InitSessionArgs{
ProcessStats: true,
@@ -427,7 +466,7 @@ func TestSessionSv1ItInitNotFoundThreshold(t *testing.T) {
}
}
func TestSessionSv1ItTerminateNotFoundThreshold(t *testing.T) {
func testSessionSv1ItTerminateNotFoundThreshold(t *testing.T) {
initUsage := 1024
args := &sessions.V1TerminateSessionArgs{
ProcessStats: true,
@@ -468,7 +507,7 @@ func TestSessionSv1ItTerminateNotFoundThreshold(t *testing.T) {
}
}
func TestSessionSv1ItAuthNotFoundThresholdAndStats(t *testing.T) {
func testSessionSv1ItAuthNotFoundThresholdAndStats(t *testing.T) {
var resp string
if err := sSApierRpc2.Call(utils.ApierV1RemoveStatQueueProfile,
&utils.TenantID{Tenant: "cgrates.org", ID: "Stat_2"}, &resp); err != nil {
@@ -509,7 +548,7 @@ func TestSessionSv1ItAuthNotFoundThresholdAndStats(t *testing.T) {
}
}
func TestSessionSv1ItInitNotFoundThresholdAndStats(t *testing.T) {
func testSessionSv1ItInitNotFoundThresholdAndStats(t *testing.T) {
initUsage := 1024
args := &sessions.V1InitSessionArgs{
ProcessStats: true,
@@ -561,7 +600,7 @@ func TestSessionSv1ItInitNotFoundThresholdAndStats(t *testing.T) {
}
}
func TestSessionSv1ItTerminateNotFoundThresholdAndStats(t *testing.T) {
func testSessionSv1ItTerminateNotFoundThresholdAndStats(t *testing.T) {
initUsage := 1024
args := &sessions.V1TerminateSessionArgs{
ProcessStats: true,
@@ -602,7 +641,7 @@ func TestSessionSv1ItTerminateNotFoundThresholdAndStats(t *testing.T) {
}
}
func TestSessionSv1ItStopCgrEngine(t *testing.T) {
func testSessionSv1ItStopCgrEngine(t *testing.T) {
if err := sSv1BiRpc2.Close(); err != nil { // Close the connection so we don't get EOF warnings from client
t.Error(err)
}

View File

@@ -41,6 +41,7 @@ var (
sSApierRpc *rpc.Client
discEvChan = make(chan *utils.AttrDisconnectSession, 1)
sSV1RequestType string
sTestSessionSv1 = []func(t *testing.T){
testSSv1ItInitCfg,
testSSv1ItResetDataDb,
@@ -67,6 +68,25 @@ var (
}
)
func TestSessionSv1ITtests(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
sessionsConfDIR = "sessions_internal"
case utils.MetaSQL:
sessionsConfDIR = "sessions_mysql"
case utils.MetaMongo:
sessionsConfDIR = "sessions_mongo"
case utils.MetaPostgres:
t.SkipNow()
default:
t.Fatal("Unknown Database type")
}
for _, stest := range sTestSessionSv1 {
t.Run(sessionsConfDIR, stest)
}
}
func handleDisconnectSession(clnt *rpc2.Client,
args *utils.AttrDisconnectSession, reply *string) error {
discEvChan <- args
@@ -109,18 +129,6 @@ func TestSSv1ItWithPseudoPrepaid(t *testing.T) {
}
}
func testSSv1ItInitCfg(t *testing.T) {
var err error
sSv1CfgPath = path.Join(*dataDir, "conf", "samples", "sessions")
// Init config first
sSv1Cfg, err = config.NewCGRConfigFromPath(sSv1CfgPath)
if err != nil {
t.Error(err)
}
sSv1Cfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
config.SetCgrConfig(sSv1Cfg)
}
func testSSv1ItResetDataDb(t *testing.T) {
if err := engine.InitDataDb(sSv1Cfg); err != nil {
t.Fatal(err)

View File

@@ -0,0 +1,98 @@
{
// CGRateS Configuration file
//
// Used for SessionSv1 integration tests
"general": {
"log_level": 7,
},
"listen": {
"rpc_json": ":2012",
"rpc_gob": ":2013",
"http": ":2080",
},
"data_db": {
"db_type": "*internal",
},
"stor_db": {
"db_type": "*internal",
},
"rals": {
"enabled": true,
},
"schedulers": {
"enabled": true,
},
"cdrs": {
"enabled": true,
"chargers_conns":["*internal"],
"rals_conns": ["*internal"],
},
"chargers": {
"enabled": true,
"attributes_conns": ["*internal"],
},
"resources": {
"enabled": true,
"store_interval": "-1",
},
"attributes": {
"enabled": true,
},
"thresholds": {
"enabled": true,
"store_interval": "-1",
},
"stats": {
"enabled": true,
"store_interval": "-1",
"thresholds_conns": ["*internal"],
},
"suppliers": {
"enabled": true,
},
"sessions": {
"enabled": true,
"session_ttl": "50ms",
"chargers_conns": ["*internal"],
"rals_conns": ["*internal"],
"cdrs_conns": ["*internal"],
"resources_conns": ["*internal"],
"thresholds_conns": ["*internal"],
"stats_conns": ["*internal"],
"suppliers_conns": ["*internal"],
"attributes_conns": ["*internal"],
},
"apier": {
"scheduler_conns": ["*internal"],
},
}

View File

@@ -0,0 +1,103 @@
{
// CGRateS Configuration file
//
// Used for SessionSv1 integration tests
"general": {
"log_level": 7,
},
"listen": {
"rpc_json": ":2012",
"rpc_gob": ":2013",
"http": ":2080",
},
"data_db": {
"db_type": "mongo",
"db_name": "10",
"db_port": 27017,
},
"stor_db": {
"db_type": "mongo",
"db_name": "cgrates",
"db_port": 27017,
},
"rals": {
"enabled": true,
},
"schedulers": {
"enabled": true,
},
"cdrs": {
"enabled": true,
"chargers_conns":["*internal"],
"rals_conns": ["*internal"],
},
"chargers": {
"enabled": true,
"attributes_conns": ["*internal"],
},
"resources": {
"enabled": true,
},
"attributes": {
"enabled": true,
},
"thresholds": {
"enabled": true,
"store_interval": "1s",
},
"stats": {
"enabled": true,
"store_interval": "1s",
"thresholds_conns": ["*internal"],
},
"suppliers": {
"enabled": true,
},
"sessions": {
"enabled": true,
"session_ttl": "50ms",
"chargers_conns": ["*internal"],
"rals_conns": ["*internal"],
"cdrs_conns": ["*internal"],
"resources_conns": ["*internal"],
"thresholds_conns": ["*internal"],
"stats_conns": ["*internal"],
"suppliers_conns": ["*internal"],
"attributes_conns": ["*internal"],
},
"apier": {
"scheduler_conns": ["*internal"],
},
}

View File

@@ -0,0 +1,99 @@
{
// CGRateS Configuration file
//
// Used for SessionSv1 integration tests
"general": {
"log_level": 7,
},
"listen": {
"rpc_json": ":2012",
"rpc_gob": ":2013",
"http": ":2080",
},
"data_db": {
"db_type": "redis",
"db_port": 6379,
"db_name": "10",
},
"stor_db": {
"db_password": "CGRateS.org",
},
"rals": {
"enabled": true,
},
"schedulers": {
"enabled": true,
},
"cdrs": {
"enabled": true,
"chargers_conns":["*internal"],
"rals_conns": ["*internal"],
},
"chargers": {
"enabled": true,
"attributes_conns": ["*internal"],
},
"resources": {
"enabled": true,
},
"attributes": {
"enabled": true,
},
"thresholds": {
"enabled": true,
"store_interval": "1s",
},
"stats": {
"enabled": true,
"store_interval": "1s",
"thresholds_conns": ["*internal"],
},
"suppliers": {
"enabled": true,
},
"sessions": {
"enabled": true,
"session_ttl": "50ms",
"chargers_conns": ["*internal"],
"rals_conns": ["*internal"],
"cdrs_conns": ["*internal"],
"resources_conns": ["*internal"],
"thresholds_conns": ["*internal"],
"stats_conns": ["*internal"],
"suppliers_conns": ["*internal"],
"attributes_conns": ["*internal"],
},
"apier": {
"scheduler_conns": ["*internal"],
},
}