Files
cgrates/config/rpcconn_test.go
2023-06-21 11:02:39 +02:00

59 lines
1.6 KiB
Go

/*
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 config
import (
"reflect"
"testing"
"github.com/cgrates/cgrates/utils"
)
func TestRPCConnsAsMapInterface(t *testing.T) {
var cfg RPCConn
cfgJSONStr := `{
"rpc_conns": {
"*localhost": {
"conns": [{"address": "127.0.0.1:2012", "transport":"*json"}],
},
},
}`
eMap := map[string]any{
"poolSize": 0,
"strategy": "",
"conns": []map[string]any{
{
"address": "127.0.0.1:2012",
"transport": "*json",
"synchronous": false,
"tls": false,
},
},
}
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
t.Error(err)
} else if jsnRPCCfg, err := jsnCfg.RPCConnJsonCfg(); err != nil {
t.Error(err)
} else if err = cfg.loadFromJsonCfg(jsnRPCCfg["*localhost"]); err != nil {
t.Error(err)
} else if rcv := cfg.AsMapInterface(); !reflect.DeepEqual(eMap, rcv) {
t.Errorf("\nExpected: %+v\nReceived: %+v", utils.ToJSON(eMap), utils.ToJSON(rcv))
}
}