mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
117 lines
3.4 KiB
Go
117 lines
3.4 KiB
Go
/*
|
|
Real-time Charging System for Telecom & ISP environments
|
|
Copyright (C) ITsysCOM GmbH
|
|
|
|
This program is free software: you can Storagetribute 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 WITH*out 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 general_tests
|
|
|
|
import (
|
|
"github.com/cgrates/cgrates/config"
|
|
"github.com/cgrates/cgrates/engine"
|
|
"github.com/cgrates/cgrates/utils"
|
|
"net/rpc"
|
|
"net/rpc/jsonrpc"
|
|
"os/exec"
|
|
"path"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
var tutCfgPath string
|
|
var tutCfg *config.CGRConfig
|
|
var tutRpc *rpc.Client
|
|
|
|
func init() {
|
|
tutCfgPath = path.Join(*dataDir, "conf", "samples", "tutorial_local_test.cfg")
|
|
tutCfg, _ = config.NewCGRConfigFromFile(&tutCfgPath)
|
|
tutCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
|
config.SetCgrConfig(tutCfg)
|
|
}
|
|
|
|
func TestTutLclResetDb(t *testing.T) {
|
|
if !*testLocal {
|
|
return
|
|
}
|
|
if db, err := engine.NewMySQLStorage(tutCfg.StorDBHost, tutCfg.StorDBPort, tutCfg.StorDBName, tutCfg.StorDBUser, tutCfg.StorDBPass); err != nil {
|
|
t.Error(err)
|
|
} else if errFlush := db.Flush(); errFlush != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestTutLclResetDataDb(t *testing.T) {
|
|
if !*testLocal {
|
|
return
|
|
}
|
|
ratingDb, err := engine.ConfigureRatingStorage(tutCfg.RatingDBType, tutCfg.RatingDBHost, tutCfg.RatingDBPort, tutCfg.RatingDBName,
|
|
tutCfg.RatingDBUser, tutCfg.RatingDBPass, tutCfg.DBDataEncoding)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
accountDb, err := engine.ConfigureAccountingStorage(tutCfg.AccountDBType, tutCfg.AccountDBHost, tutCfg.AccountDBPort, tutCfg.AccountDBName,
|
|
tutCfg.AccountDBUser, tutCfg.AccountDBPass, tutCfg.DBDataEncoding)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, db := range []engine.Storage{ratingDb, accountDb} {
|
|
if err := db.Flush(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestTutLclStartEngine(t *testing.T) {
|
|
if !*testLocal {
|
|
return
|
|
}
|
|
enginePath, err := exec.LookPath("cgr-engine")
|
|
if err != nil {
|
|
t.Fatal("Cannot find cgr-engine executable")
|
|
}
|
|
exec.Command("pkill", "cgr-engine").Run() // Just to make sure another one is not running, bit brutal maybe we can fine tune it
|
|
engine := exec.Command(enginePath, "-config", tutCfgPath)
|
|
if err := engine.Start(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time to rater to fire up
|
|
}
|
|
|
|
// Connect rpc client to rater
|
|
func TestTutLclRpcConn(t *testing.T) {
|
|
if !*testLocal {
|
|
return
|
|
}
|
|
var err error
|
|
tutRpc, err = jsonrpc.Dial("tcp", tutCfg.RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestTutLclLoadTariffPlanFromFolder(t *testing.T) {
|
|
if !*testLocal {
|
|
return
|
|
}
|
|
reply := ""
|
|
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")}
|
|
if err := tutRpc.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err != nil {
|
|
t.Error(err)
|
|
} else if reply != "OK" {
|
|
t.Error(reply)
|
|
}
|
|
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
|
|
}
|