mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-13 02:56:24 +05:00
Started rate config enable reload test
This commit is contained in:
committed by
Dan Christian Bogos
parent
564e2e1c0c
commit
b835bd5604
173
general_tests/rate_config_enable_it_test.go
Normal file
173
general_tests/rate_config_enable_it_test.go
Normal file
@@ -0,0 +1,173 @@
|
||||
//go:build integration
|
||||
// +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 general_tests
|
||||
|
||||
import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/birpc"
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
testRateCfgDir string
|
||||
testRateCfgPath string
|
||||
testRateCfg *config.CGRConfig
|
||||
testRateRPC *birpc.Client
|
||||
|
||||
testRateTests = []func(t *testing.T){
|
||||
testRateLoadConfig,
|
||||
testRateResetDataDB,
|
||||
testRateResetStorDb,
|
||||
testRateStartEngine,
|
||||
testRateRPCConn,
|
||||
//testRateConfigSReloadRates,
|
||||
testRateStopCgrEngine,
|
||||
}
|
||||
)
|
||||
|
||||
func TestRateChange(t *testing.T) {
|
||||
switch *dbType {
|
||||
case utils.MetaInternal:
|
||||
testRateCfgDir = "tutinternal"
|
||||
case utils.MetaMySQL:
|
||||
testRateCfgDir = "tutmysql"
|
||||
case utils.MetaMongo:
|
||||
testRateCfgDir = "tutmongo"
|
||||
case utils.MetaPostgres:
|
||||
t.SkipNow()
|
||||
default:
|
||||
t.Fatal("Unknown Database type")
|
||||
}
|
||||
for _, testRateest := range testRateTests {
|
||||
t.Run(testRateCfgDir, testRateest)
|
||||
}
|
||||
}
|
||||
|
||||
func testRateLoadConfig(t *testing.T) {
|
||||
testRateCfgPath = path.Join(*dataDir, "conf", "samples", testRateCfgDir)
|
||||
if testRateCfg, err = config.NewCGRConfigFromPath(testRateCfgPath); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testRateResetDataDB(t *testing.T) {
|
||||
if err := engine.InitDataDB(testRateCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testRateResetStorDb(t *testing.T) {
|
||||
if err := engine.InitStorDB(testRateCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testRateStartEngine(t *testing.T) {
|
||||
if _, err := engine.StopStartEngine(testRateCfgPath, *waitRater); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testRateConfigSReloadRates(t *testing.T) {
|
||||
|
||||
var replyPingBf string
|
||||
if err := testRateRPC.Call(context.Background(), utils.RateSv1CostForEvent, &utils.CGREvent{}, &replyPingBf); err != nil {
|
||||
t.Error(err)
|
||||
} else if replyPingBf != utils.Pong {
|
||||
t.Errorf("Expected OK received: %s", replyPingBf)
|
||||
}
|
||||
|
||||
var reply string
|
||||
if err := testRateRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{
|
||||
Tenant: "cgrates.org",
|
||||
Config: ` "rates": {
|
||||
"enabled": true,
|
||||
"indexed_selects": true,
|
||||
"nested_fields": false,
|
||||
"prefix_indexed_fields": [],
|
||||
"rate_indexed_selects": true,
|
||||
"rate_nested_fields": false,
|
||||
"rate_prefix_indexed_fields": [
|
||||
"*req.Destination"
|
||||
],
|
||||
"rate_string_indexed_fields": [],
|
||||
"rate_suffix_indexed_fields": [],
|
||||
"string_indexed_fields": [],
|
||||
"suffix_indexed_fields": [],
|
||||
"verbosity": 1000
|
||||
},`,
|
||||
}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Expected OK received: %+v", reply)
|
||||
}
|
||||
cfgStr := ` "rates": {
|
||||
"enabled": true,
|
||||
"indexed_selects": true,
|
||||
"nested_fields": false,
|
||||
"prefix_indexed_fields": [],
|
||||
"rate_indexed_selects": true,
|
||||
"rate_nested_fields": false,
|
||||
"rate_prefix_indexed_fields": [
|
||||
"*req.Destination"
|
||||
],
|
||||
"rate_string_indexed_fields": [],
|
||||
"rate_suffix_indexed_fields": [],
|
||||
"string_indexed_fields": [],
|
||||
"suffix_indexed_fields": [],
|
||||
"verbosity": 1000
|
||||
},`
|
||||
var rpl string
|
||||
if err := testRateRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{
|
||||
Tenant: "cgrates.org",
|
||||
Sections: []string{config.StatSJSON},
|
||||
}, &rpl); err != nil {
|
||||
t.Error(err)
|
||||
} else if cfgStr != rpl {
|
||||
t.Errorf("\nExpected %+v ,\n received: %+v", utils.ToIJSON(cfgStr), utils.ToIJSON(rpl))
|
||||
}
|
||||
|
||||
var replyPingAf string
|
||||
if err := testRateRPC.Call(context.Background(), utils.StatSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil {
|
||||
t.Error(err)
|
||||
} else if replyPingAf != utils.Pong {
|
||||
t.Errorf("Expected OK received: %s", replyPingAf)
|
||||
}
|
||||
}
|
||||
|
||||
func testRateRPCConn(t *testing.T) {
|
||||
var err error
|
||||
testRateRPC, err = newRPCClient(testRateCfg.ListenCfg())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testRateStopCgrEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(100); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user