Files
cgrates/apier/v1/cdrs_it_test.go
2019-11-25 09:29:28 +01:00

113 lines
2.9 KiB
Go

// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package v1
import (
"net/rpc"
"path"
"testing"
"time"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var cdrsCfgPath string
var cdrsCfg *config.CGRConfig
var cdrsRpc *rpc.Client
var cdrsConfDIR string // run the tests for specific configuration
// subtests to be executed
var sTestsCDRsIT = []func(t *testing.T){
testV1CDRsInitConfig,
testV1CDRsInitDataDb,
testV1CDRsInitCdrDb,
testV1CDRsStartEngine,
testV1CDRsRpcConn,
testV1CDRsLoadTariffPlanFromFolder,
testV1CDRsProcessEventDebit,
testV1CDRsKillEngine,
}
// Tests starting here
func TestCDRsITInternal(t *testing.T) {
cdrsConfDIR = "cdrsv1internal"
for _, stest := range sTestsCDRsIT {
t.Run(cdrsConfDIR, stest)
}
}
func testV1CDRsInitConfig(t *testing.T) {
var err error
cdrsCfgPath = path.Join(*dataDir, "conf", "samples", cdrsConfDIR)
if cdrsCfg, err = config.NewCGRConfigFromPath(cdrsCfgPath); err != nil {
t.Fatal("Got config error: ", err.Error())
}
}
func testV1CDRsInitDataDb(t *testing.T) {
if err := engine.InitDataDb(cdrsCfg); err != nil {
t.Fatal(err)
}
}
// InitDb so we can rely on count
func testV1CDRsInitCdrDb(t *testing.T) {
if err := engine.InitStorDb(cdrsCfg); err != nil {
t.Fatal(err)
}
}
func testV1CDRsStartEngine(t *testing.T) {
if _, err := engine.StopStartEngine(cdrsCfgPath, *waitRater); err != nil {
t.Fatal(err)
}
}
// Connect rpc client to rater
func testV1CDRsRpcConn(t *testing.T) {
var err error
cdrsRpc, err = newRPCClient(cdrsCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
if err != nil {
t.Fatal("Could not connect to rater: ", err.Error())
}
}
func testV1CDRsLoadTariffPlanFromFolder(t *testing.T) {
var loadInst string
if err := cdrsRpc.Call(utils.ApierV1LoadTariffPlanFromFolder,
&utils.AttrLoadTpFromFolder{FolderPath: path.Join(
*dataDir, "tariffplans", "testit")}, &loadInst); err != nil {
t.Error(err)
}
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
}
func testV1CDRsProcessEventDebit(t *testing.T) {
return
}
func testV1CDRsKillEngine(t *testing.T) {
if err := engine.KillEngine(*waitRater); err != nil {
t.Error(err)
}
}