mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-21 07:08:45 +05:00
Improving covarage at /config
This commit is contained in:
committed by
Dan Christian Bogos
parent
6810efb7ef
commit
27ad99e88c
@@ -344,7 +344,7 @@ func TestActionSCloneSection(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
exp := ActionSCfg{
|
||||
exp := &ActionSCfg{
|
||||
Enabled: true,
|
||||
CDRsConns: []string{"*localhost"},
|
||||
EEsConns: []string{"*localhost"},
|
||||
@@ -366,9 +366,9 @@ func TestActionSCloneSection(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
actCfg.CloneSection()
|
||||
if !reflect.DeepEqual(exp, actCfg) {
|
||||
t.Errorf("Expected %v \n but received \n %v", exp, actCfg)
|
||||
rcv := actCfg.CloneSection()
|
||||
if !reflect.DeepEqual(exp, rcv) {
|
||||
t.Errorf("Expected %v \n but received \n %v", exp, rcv)
|
||||
}
|
||||
}
|
||||
func TestDiffActionsOptsJsonCfg(t *testing.T) {
|
||||
|
||||
@@ -187,8 +187,8 @@ func TestAdminSCloneSection(t *testing.T) {
|
||||
EEsConns: []string{"*localhost"},
|
||||
}
|
||||
|
||||
admCfg.CloneSection()
|
||||
if !reflect.DeepEqual(admCfg, exp) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(admCfg))
|
||||
rcv := admCfg.CloneSection()
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,9 +199,9 @@ func TestAnalyzerSCloneSection(t *testing.T) {
|
||||
TTL: 3 * time.Minute,
|
||||
CleanupInterval: 30 * time.Minute,
|
||||
}
|
||||
anlCfg.CloneSection()
|
||||
if !reflect.DeepEqual(anlCfg, exp) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(anlCfg))
|
||||
rcv := anlCfg.CloneSection()
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -135,8 +135,8 @@ func TestAPIBanCloneSection(t *testing.T) {
|
||||
Enabled: false,
|
||||
Keys: []string{"key1", "key2"},
|
||||
}
|
||||
apbCfg.CloneSection()
|
||||
if !reflect.DeepEqual(exp, apbCfg) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(apbCfg))
|
||||
rcv := apbCfg.CloneSection()
|
||||
if !reflect.DeepEqual(exp, rcv) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,9 +460,9 @@ func TestAttributeSCloneSection(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
attrCfg.CloneSection()
|
||||
if !reflect.DeepEqual(attrCfg, exp) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(attrCfg))
|
||||
rcv := attrCfg.CloneSection()
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -329,9 +329,9 @@ func TestCacheCloneSection(t *testing.T) {
|
||||
},
|
||||
ReplicationConns: []string{},
|
||||
}
|
||||
cacheCfg.CloneSection()
|
||||
if !reflect.DeepEqual(cacheCfg, exp) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(cacheCfg))
|
||||
rcv := cacheCfg.CloneSection()
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -542,8 +542,8 @@ func TestCdrsCfgCloneSection(t *testing.T) {
|
||||
Opts: &CdrsOpts{},
|
||||
}
|
||||
|
||||
cdrsCfg.CloneSection()
|
||||
if !reflect.DeepEqual(exp, cdrsCfg) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(cdrsCfg))
|
||||
rcv := cdrsCfg.CloneSection()
|
||||
if !reflect.DeepEqual(exp, rcv) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,8 +215,8 @@ func TestChargerSCfgCloneSection(t *testing.T) {
|
||||
NestedFields: true,
|
||||
}
|
||||
|
||||
chgrCfg.CloneSection()
|
||||
if !reflect.DeepEqual(chgrCfg, exp) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(chgrCfg))
|
||||
rcv := chgrCfg.CloneSection()
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,26 +25,8 @@ import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
type mockConfDb struct {
|
||||
GetSectionF func(*context.Context, string, interface{}) error
|
||||
SetSectionF func(*context.Context, string, interface{}) error
|
||||
}
|
||||
|
||||
func (m *mockConfDb) GetSection(ctx *context.Context, sec string, val interface{}) error {
|
||||
if m.GetSectionF != nil {
|
||||
return m.GetSectionF(ctx, sec, val)
|
||||
}
|
||||
return utils.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (m *mockConfDb) SetSection(ctx *context.Context, sec string, val interface{}) error {
|
||||
if m.SetSectionF != nil {
|
||||
return m.SetSectionF(ctx, sec, val)
|
||||
}
|
||||
return utils.ErrNotImplemented
|
||||
}
|
||||
func TestEFsCfgLoad(t *testing.T) {
|
||||
m := &mockConfDb{}
|
||||
m := &mockDb{}
|
||||
efsCfg := &EFsCfg{}
|
||||
if err := efsCfg.Load(context.Background(), m, cfg); err != utils.ErrNotImplemented {
|
||||
t.Errorf("Expected error <%v>, Received errpr <%v>", utils.ErrNotImplemented, err)
|
||||
|
||||
@@ -2330,6 +2330,12 @@ func TestDiffEventReaderOptsJsonCfg(t *testing.T) {
|
||||
NATSClientCertificateProcessed: utils.StringPointer("cc_processed_diff"),
|
||||
NATSClientKeyProcessed: utils.StringPointer("ck_processed_diff"),
|
||||
NATSJetStreamMaxWaitProcessed: utils.DurationPointer(6 * time.Second),
|
||||
KafkaTLS: utils.BoolPointer(true),
|
||||
KafkaCAPath: utils.StringPointer("/tmp/path/diff"),
|
||||
KafkaSkipTLSVerify: utils.BoolPointer(true),
|
||||
KafkaTLSProcessed: utils.BoolPointer(true),
|
||||
KafkaCAPathProcessed: utils.StringPointer("/tmp/path/diff"),
|
||||
KafkaSkipTLSVerifyProcessed: utils.BoolPointer(true),
|
||||
}
|
||||
|
||||
v2 := &EventReaderOpts{
|
||||
@@ -2392,6 +2398,12 @@ func TestDiffEventReaderOptsJsonCfg(t *testing.T) {
|
||||
NATSClientCertificateProcessed: utils.StringPointer("cc_processed"),
|
||||
NATSClientKeyProcessed: utils.StringPointer("ck_processed"),
|
||||
NATSJetStreamMaxWaitProcessed: utils.DurationPointer(2 * time.Second),
|
||||
KafkaTLS: utils.BoolPointer(false),
|
||||
KafkaCAPath: utils.StringPointer("/tmp/path"),
|
||||
KafkaSkipTLSVerify: utils.BoolPointer(false),
|
||||
KafkaTLSProcessed: utils.BoolPointer(false),
|
||||
KafkaCAPathProcessed: utils.StringPointer("/tmp/path"),
|
||||
KafkaSkipTLSVerifyProcessed: utils.BoolPointer(false),
|
||||
}
|
||||
|
||||
exp := &EventReaderOptsJson{
|
||||
@@ -2454,6 +2466,12 @@ func TestDiffEventReaderOptsJsonCfg(t *testing.T) {
|
||||
NATSClientCertificateProcessed: utils.StringPointer("cc_processed"),
|
||||
NATSClientKeyProcessed: utils.StringPointer("ck_processed"),
|
||||
NATSJetStreamMaxWaitProcessed: utils.StringPointer("2s"),
|
||||
KafkaTLS: utils.BoolPointer(false),
|
||||
KafkaCAPath: utils.StringPointer("/tmp/path"),
|
||||
KafkaSkipTLSVerify: utils.BoolPointer(false),
|
||||
KafkaTLSProcessed: utils.BoolPointer(false),
|
||||
KafkaCAPathProcessed: utils.StringPointer("/tmp/path"),
|
||||
KafkaSkipTLSVerifyProcessed: utils.BoolPointer(false),
|
||||
}
|
||||
|
||||
if rcv := diffEventReaderOptsJsonCfg(d, v1, v2); !reflect.DeepEqual(rcv, exp) {
|
||||
|
||||
61
config/fsagentcfg_test.go
Normal file
61
config/fsagentcfg_test.go
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
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"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestFsConnCfgLoadFromJSONCfg(t *testing.T) {
|
||||
fs := &FsConnCfg{
|
||||
MaxReconnectInterval: time.Duration(4),
|
||||
}
|
||||
jsnCfg := &FsConnJsonCfg{
|
||||
Max_reconnect_interval: utils.StringPointer("invalid time"),
|
||||
}
|
||||
expErr := `time: invalid duration "invalid time"`
|
||||
if err := fs.loadFromJSONCfg(jsnCfg); err.Error() != expErr {
|
||||
t.Errorf("Expected error <%v>, Received error <%v>", expErr, err.Error())
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffFsConnJsonCfgMaxReconnInterval(t *testing.T) {
|
||||
v1 := &FsConnCfg{MaxReconnectInterval: time.Duration(3)}
|
||||
|
||||
v2 := &FsConnCfg{MaxReconnectInterval: time.Duration(2)}
|
||||
|
||||
expected := &FsConnJsonCfg{Max_reconnect_interval: utils.StringPointer("2ns")}
|
||||
|
||||
rcv := diffFsConnJsonCfg(v1, v2)
|
||||
if !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
v1 = v2
|
||||
expected = &FsConnJsonCfg{}
|
||||
|
||||
rcv = diffFsConnJsonCfg(v1, v2)
|
||||
if !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/ericlagergren/decimal"
|
||||
)
|
||||
|
||||
func TestGeneralCfgloadFromJsonCfg(t *testing.T) {
|
||||
@@ -274,6 +275,11 @@ func TestDiffGeneralJsonCfg(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
MaxReconnectInterval: time.Duration(5),
|
||||
DecimalMaxScale: 5,
|
||||
DecimalMinScale: 5,
|
||||
DecimalPrecision: 5,
|
||||
DecimalRoundingMode: decimal.ToNearestAway,
|
||||
}
|
||||
|
||||
v2 := &GeneralCfg{
|
||||
@@ -302,6 +308,11 @@ func TestDiffGeneralJsonCfg(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
MaxReconnectInterval: time.Duration(2),
|
||||
DecimalMaxScale: 2,
|
||||
DecimalMinScale: 2,
|
||||
DecimalPrecision: 2,
|
||||
DecimalRoundingMode: decimal.ToNearestEven,
|
||||
}
|
||||
|
||||
expected := &GeneralJsonCfg{
|
||||
@@ -330,6 +341,11 @@ func TestDiffGeneralJsonCfg(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Max_reconnect_interval: utils.StringPointer("2ns"),
|
||||
Decimal_max_scale: utils.IntPointer(2),
|
||||
Decimal_min_scale: utils.IntPointer(2),
|
||||
Decimal_precision: utils.IntPointer(2),
|
||||
Decimal_rounding_mode: utils.StringPointer("ToNearestEven"),
|
||||
}
|
||||
|
||||
rcv := diffGeneralJsonCfg(d, v1, v2)
|
||||
@@ -398,3 +414,33 @@ func TestGeneralCfgCloneSection(t *testing.T) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeneralOptsLoadFromJSONCfgNilJson(t *testing.T) {
|
||||
generalOpts := &GeneralOpts{}
|
||||
var jsnCfg *GeneralOptsJson
|
||||
generalOptsClone := &GeneralOpts{}
|
||||
generalOpts.loadFromJSONCfg(jsnCfg)
|
||||
if !reflect.DeepEqual(generalOptsClone, generalOpts) {
|
||||
t.Errorf("Expected GeneralOpts to not change, Was <%+v>,\nNow is <%+v>",
|
||||
generalOptsClone, generalOpts)
|
||||
}
|
||||
}
|
||||
func TestGeneralCfgloadFromJsonCfgMaxReconnInterval(t *testing.T) {
|
||||
cfgJSON := &GeneralJsonCfg{Max_reconnect_interval: utils.StringPointer("invalid time")}
|
||||
|
||||
expected := `time: invalid duration "invalid time"`
|
||||
jsnCfg := NewDefaultCGRConfig()
|
||||
if err = jsnCfg.generalCfg.loadFromJSONCfg(cfgJSON); err.Error() != expected {
|
||||
t.Errorf("Expected error <%v>, Received error <%v>", expected, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeneralOptsCloneNil(t *testing.T) {
|
||||
|
||||
var generalOpts *GeneralOpts
|
||||
generalOptsClone := generalOpts.Clone()
|
||||
if !reflect.DeepEqual(generalOptsClone, generalOpts) {
|
||||
t.Errorf("Expected GeneralOpts to not change, Was <%+v>,\nNow is <%+v>",
|
||||
generalOptsClone, generalOpts)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -760,30 +760,30 @@ func TestDiffHttpAgentsJsonCfg(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// func TestHttpAgentCloneSection(t *testing.T) {
|
||||
// httpCfg := HTTPAgentCfgs{
|
||||
// {
|
||||
// ID: "http_agent",
|
||||
// URL: "http_url",
|
||||
// SessionSConns: []string{"*localhost"},
|
||||
// RequestPayload: "request_payload",
|
||||
// ReplyPayload: "reply_payload",
|
||||
// },
|
||||
// }
|
||||
func TestHttpAgentCloneSection(t *testing.T) {
|
||||
httpCfg := HTTPAgentCfgs{
|
||||
{
|
||||
ID: "http_agent",
|
||||
URL: "http_url",
|
||||
SessionSConns: []string{"*localhost"},
|
||||
RequestPayload: "request_payload",
|
||||
ReplyPayload: "reply_payload",
|
||||
},
|
||||
}
|
||||
|
||||
// exp := HTTPAgentCfgs{
|
||||
// {
|
||||
// ID: "http_agent",
|
||||
// URL: "http_url",
|
||||
// SessionSConns: []string{"*localhost"},
|
||||
// RequestPayload: "request_payload",
|
||||
// ReplyPayload: "reply_payload",
|
||||
// },
|
||||
// }
|
||||
exp := &HTTPAgentCfgs{
|
||||
{
|
||||
ID: "http_agent",
|
||||
URL: "http_url",
|
||||
SessionSConns: []string{"*localhost"},
|
||||
RequestPayload: "request_payload",
|
||||
ReplyPayload: "reply_payload",
|
||||
RequestProcessors: []*RequestProcessor{},
|
||||
},
|
||||
}
|
||||
|
||||
// rcv := httpCfg.CloneSection()
|
||||
// rcv.(*HTTPAgentCfgs)[0].RequestProcessors = nil
|
||||
// if !reflect.DeepEqual(rcv, exp) {
|
||||
// t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
// }
|
||||
// }
|
||||
rcv := httpCfg.CloneSection()
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,8 +230,9 @@ func TestDiffHTTPJsonCfg(t *testing.T) {
|
||||
AuthUsers: map[string]string{
|
||||
"User1": "passUser1",
|
||||
},
|
||||
ClientOpts: &http.Transport{},
|
||||
dialer: &net.Dialer{},
|
||||
ClientOpts: &http.Transport{},
|
||||
dialer: &net.Dialer{},
|
||||
PrometheusURL: "PrometheusURL",
|
||||
}
|
||||
|
||||
v2 := &HTTPCfg{
|
||||
@@ -247,7 +248,8 @@ func TestDiffHTTPJsonCfg(t *testing.T) {
|
||||
ClientOpts: &http.Transport{
|
||||
MaxIdleConns: 100,
|
||||
},
|
||||
dialer: &net.Dialer{},
|
||||
dialer: &net.Dialer{},
|
||||
PrometheusURL: "PrometheusURL2",
|
||||
}
|
||||
|
||||
expected := &HTTPJsonCfg{
|
||||
@@ -263,6 +265,7 @@ func TestDiffHTTPJsonCfg(t *testing.T) {
|
||||
Client_opts: &HTTPClientOptsJson{
|
||||
MaxIdleConns: utils.IntPointer(100),
|
||||
},
|
||||
Prometheus_url: utils.StringPointer("PrometheusURL2"),
|
||||
}
|
||||
|
||||
rcv := diffHTTPJsonCfg(d, v1, v2)
|
||||
@@ -318,3 +321,271 @@ func TestHttpCfgCloneSection(t *testing.T) {
|
||||
utils.ToJSON(rcv.AsMapInterface(utils.InfieldSep)))
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewDialerJsonCfgNil(t *testing.T) {
|
||||
var jsnCfg *HTTPClientOptsJson
|
||||
|
||||
nDialer := NewDefaultCGRConfig().httpCfg.dialer
|
||||
nDialer.DualStack = false
|
||||
if err := newDialer(nDialer, jsnCfg); err != nil {
|
||||
t.Errorf("Expected error <nil> \n but received error <%v>", err)
|
||||
} else if nDialer.DualStack {
|
||||
t.Errorf("Dialer DualStack shouldnt have changed, was <false>, now is <%v>",
|
||||
nDialer.DualStack)
|
||||
}
|
||||
|
||||
}
|
||||
func TestNewDialerJsonCfgDialTimeout(t *testing.T) {
|
||||
jsnCfg := &HTTPClientOptsJson{
|
||||
DialTimeout: utils.StringPointer("invalid time"),
|
||||
}
|
||||
|
||||
nDialer := NewDefaultCGRConfig().httpCfg.dialer
|
||||
expErr := `time: invalid duration "invalid time"`
|
||||
if err := newDialer(nDialer, jsnCfg); err.Error() != expErr {
|
||||
t.Errorf("Expected error <%v> \n but received error <%v>", expErr, err)
|
||||
}
|
||||
|
||||
}
|
||||
func TestNewDialerJsonCfgDialFallbackDelay(t *testing.T) {
|
||||
jsnCfg := &HTTPClientOptsJson{
|
||||
DialFallbackDelay: utils.StringPointer("invalid time"),
|
||||
}
|
||||
|
||||
nDialer := NewDefaultCGRConfig().httpCfg.dialer
|
||||
expErr := `time: invalid duration "invalid time"`
|
||||
if err := newDialer(nDialer, jsnCfg); err.Error() != expErr {
|
||||
t.Errorf("Expected error <%v> \n but received error <%v>", expErr, err)
|
||||
}
|
||||
|
||||
}
|
||||
func TestNewDialerJsonCfgDialKeepAlive(t *testing.T) {
|
||||
jsnCfg := &HTTPClientOptsJson{
|
||||
DialKeepAlive: utils.StringPointer("invalid time"),
|
||||
}
|
||||
|
||||
nDialer := NewDefaultCGRConfig().httpCfg.dialer
|
||||
expErr := `time: invalid duration "invalid time"`
|
||||
if err := newDialer(nDialer, jsnCfg); err.Error() != expErr {
|
||||
t.Errorf("Expected error <%v> \n but received error <%v>", expErr, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestLoadTransportFromJSONCfgNilJson(t *testing.T) {
|
||||
|
||||
EqualHttpOpts := func(httpOpts1, httpOpts2 *http.Transport) bool {
|
||||
if httpOpts1.TLSHandshakeTimeout != httpOpts2.TLSHandshakeTimeout {
|
||||
return false
|
||||
}
|
||||
if httpOpts1.DisableKeepAlives != httpOpts2.DisableKeepAlives {
|
||||
return false
|
||||
}
|
||||
if httpOpts1.DisableCompression != httpOpts2.DisableCompression {
|
||||
return false
|
||||
}
|
||||
if httpOpts1.MaxIdleConns != httpOpts2.MaxIdleConns {
|
||||
return false
|
||||
}
|
||||
if httpOpts1.MaxIdleConnsPerHost != httpOpts2.MaxIdleConnsPerHost {
|
||||
return false
|
||||
}
|
||||
if httpOpts1.IdleConnTimeout != httpOpts2.IdleConnTimeout {
|
||||
return false
|
||||
}
|
||||
if httpOpts1.MaxConnsPerHost != httpOpts2.MaxConnsPerHost {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
httpOpts := &http.Transport{
|
||||
TLSHandshakeTimeout: time.Duration(2),
|
||||
DisableKeepAlives: false,
|
||||
DisableCompression: false,
|
||||
MaxIdleConns: 2,
|
||||
MaxIdleConnsPerHost: 2,
|
||||
MaxConnsPerHost: 2,
|
||||
IdleConnTimeout: time.Duration(2),
|
||||
}
|
||||
|
||||
httpOptsCopy := httpOpts
|
||||
|
||||
var jsnCfg *HTTPClientOptsJson
|
||||
|
||||
if err := loadTransportFromJSONCfg(httpOpts,
|
||||
NewDefaultCGRConfig().httpCfg.dialer,
|
||||
jsnCfg); err != nil {
|
||||
t.Errorf("Expected error <nil> \n but received error <%v>", err)
|
||||
} else if !EqualHttpOpts(httpOpts, httpOptsCopy) {
|
||||
t.Errorf("Expected HttpOpts not to change, was <%+v>,\n Now is <%+v>",
|
||||
httpOpts, httpOptsCopy)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestLoadTransportFromJSONCfgTLSHandshakeTimeout(t *testing.T) {
|
||||
httpOpts := NewDefaultCGRConfig().httpCfg.ClientOpts
|
||||
|
||||
jsnCfg := &HTTPClientOptsJson{
|
||||
TLSHandshakeTimeout: utils.StringPointer("invalid time"),
|
||||
}
|
||||
expErr := `time: invalid duration "invalid time"`
|
||||
if err := loadTransportFromJSONCfg(httpOpts,
|
||||
NewDefaultCGRConfig().httpCfg.dialer,
|
||||
jsnCfg); err.Error() != expErr {
|
||||
t.Errorf("Expected error <%v> \n but received error <%v>", expErr, err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
func TestLoadTransportFromJSONCfgIdleConnTimeout(t *testing.T) {
|
||||
httpOpts := NewDefaultCGRConfig().httpCfg.ClientOpts
|
||||
|
||||
jsnCfg := &HTTPClientOptsJson{
|
||||
IdleConnTimeout: utils.StringPointer("invalid time"),
|
||||
}
|
||||
expErr := `time: invalid duration "invalid time"`
|
||||
if err := loadTransportFromJSONCfg(httpOpts,
|
||||
NewDefaultCGRConfig().httpCfg.dialer,
|
||||
jsnCfg); err.Error() != expErr {
|
||||
t.Errorf("Expected error <%v> \n but received error <%v>", expErr, err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
func TestLoadTransportFromJSONCfgResponseHeaderTimeout(t *testing.T) {
|
||||
httpOpts := NewDefaultCGRConfig().httpCfg.ClientOpts
|
||||
|
||||
jsnCfg := &HTTPClientOptsJson{
|
||||
ResponseHeaderTimeout: utils.StringPointer("invalid time"),
|
||||
}
|
||||
expErr := `time: invalid duration "invalid time"`
|
||||
if err := loadTransportFromJSONCfg(httpOpts,
|
||||
NewDefaultCGRConfig().httpCfg.dialer,
|
||||
jsnCfg); err.Error() != expErr {
|
||||
t.Errorf("Expected error <%v> \n but received error <%v>", expErr, err.Error())
|
||||
}
|
||||
}
|
||||
func TestLoadTransportFromJSONCfgExpectContinueTimeout(t *testing.T) {
|
||||
httpOpts := NewDefaultCGRConfig().httpCfg.ClientOpts
|
||||
|
||||
jsnCfg := &HTTPClientOptsJson{
|
||||
ExpectContinueTimeout: utils.StringPointer("invalid time"),
|
||||
}
|
||||
expErr := `time: invalid duration "invalid time"`
|
||||
if err := loadTransportFromJSONCfg(httpOpts,
|
||||
NewDefaultCGRConfig().httpCfg.dialer,
|
||||
jsnCfg); err.Error() != expErr {
|
||||
t.Errorf("Expected error <%v> \n but received error <%v>", expErr, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPCfgloadFromJsonCfgClientOptsErr(t *testing.T) {
|
||||
cfgJSONStr := &HTTPJsonCfg{
|
||||
Client_opts: &HTTPClientOptsJson{
|
||||
DialTimeout: utils.StringPointer("invalid value"),
|
||||
},
|
||||
}
|
||||
expErr := `time: invalid duration "invalid value"`
|
||||
cfgJsn := NewDefaultCGRConfig()
|
||||
if err = cfgJsn.httpCfg.loadFromJSONCfg(cfgJSONStr); err.Error() != expErr {
|
||||
t.Errorf("Expected error <%v>, Received error <%v>", expErr, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffHTTPClientOptsJsonCfgDialer(t *testing.T) {
|
||||
var d *HTTPClientOptsJson
|
||||
|
||||
v1 := &net.Dialer{
|
||||
Timeout: time.Duration(2),
|
||||
FallbackDelay: time.Duration(2),
|
||||
KeepAlive: time.Duration(2),
|
||||
}
|
||||
|
||||
v2 := &net.Dialer{
|
||||
Timeout: time.Duration(3),
|
||||
FallbackDelay: time.Duration(3),
|
||||
KeepAlive: time.Duration(3),
|
||||
}
|
||||
|
||||
expected := &HTTPClientOptsJson{
|
||||
DialTimeout: utils.StringPointer("3ns"),
|
||||
DialFallbackDelay: utils.StringPointer("3ns"),
|
||||
DialKeepAlive: utils.StringPointer("3ns"),
|
||||
}
|
||||
|
||||
rcv := diffHTTPClientOptsJsonCfgDialer(d, v1, v2)
|
||||
if !reflect.DeepEqual(expected, rcv) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
v2_2 := v1
|
||||
expected2 := &HTTPClientOptsJson{}
|
||||
|
||||
rcv = diffHTTPClientOptsJsonCfgDialer(d, v1, v2_2)
|
||||
if !reflect.DeepEqual(expected2, rcv) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected2), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffHTTPClientOptsJsonCfg(t *testing.T) {
|
||||
var d *HTTPClientOptsJson
|
||||
|
||||
v1 := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: false,
|
||||
},
|
||||
TLSHandshakeTimeout: time.Duration(2),
|
||||
DisableKeepAlives: false,
|
||||
DisableCompression: false,
|
||||
MaxIdleConns: 2,
|
||||
MaxIdleConnsPerHost: 2,
|
||||
MaxConnsPerHost: 2,
|
||||
IdleConnTimeout: time.Duration(2),
|
||||
ResponseHeaderTimeout: time.Duration(2),
|
||||
ExpectContinueTimeout: time.Duration(2),
|
||||
ForceAttemptHTTP2: false,
|
||||
}
|
||||
|
||||
v2 := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
TLSHandshakeTimeout: time.Duration(3),
|
||||
DisableKeepAlives: true,
|
||||
DisableCompression: true,
|
||||
MaxIdleConns: 3,
|
||||
MaxIdleConnsPerHost: 3,
|
||||
MaxConnsPerHost: 3,
|
||||
IdleConnTimeout: time.Duration(3),
|
||||
ResponseHeaderTimeout: time.Duration(3),
|
||||
ExpectContinueTimeout: time.Duration(3),
|
||||
ForceAttemptHTTP2: true,
|
||||
}
|
||||
|
||||
expected := &HTTPClientOptsJson{
|
||||
SkipTLSVerification: utils.BoolPointer(true),
|
||||
TLSHandshakeTimeout: utils.StringPointer("3ns"),
|
||||
DisableKeepAlives: utils.BoolPointer(true),
|
||||
DisableCompression: utils.BoolPointer(true),
|
||||
MaxIdleConns: utils.IntPointer(3),
|
||||
MaxIdleConnsPerHost: utils.IntPointer(3),
|
||||
MaxConnsPerHost: utils.IntPointer(3),
|
||||
IdleConnTimeout: utils.StringPointer("3ns"),
|
||||
ResponseHeaderTimeout: utils.StringPointer("3ns"),
|
||||
ExpectContinueTimeout: utils.StringPointer("3ns"),
|
||||
ForceAttemptHTTP2: utils.BoolPointer(true),
|
||||
}
|
||||
|
||||
rcv := diffHTTPClientOptsJsonCfg(d, v1, v2)
|
||||
if !reflect.DeepEqual(expected, rcv) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
v2_2 := v1
|
||||
expected2 := &HTTPClientOptsJson{}
|
||||
|
||||
rcv = diffHTTPClientOptsJsonCfg(d, v1, v2_2)
|
||||
if !reflect.DeepEqual(expected2, rcv) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected2), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package config
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
@@ -164,21 +165,24 @@ func TestKamAgentCfgClone(t *testing.T) {
|
||||
|
||||
func TestDiffKamConnJsonCfg(t *testing.T) {
|
||||
v1 := &KamConnCfg{
|
||||
Alias: "KAM",
|
||||
Address: "localhost:8080",
|
||||
Reconnects: 2,
|
||||
Alias: "KAM",
|
||||
Address: "localhost:8080",
|
||||
Reconnects: 2,
|
||||
MaxReconnectInterval: time.Duration(2),
|
||||
}
|
||||
|
||||
v2 := &KamConnCfg{
|
||||
Alias: "KAM_2",
|
||||
Address: "localhost:8037",
|
||||
Reconnects: 5,
|
||||
Alias: "KAM_2",
|
||||
Address: "localhost:8037",
|
||||
Reconnects: 5,
|
||||
MaxReconnectInterval: time.Duration(3),
|
||||
}
|
||||
|
||||
expected := &KamConnJsonCfg{
|
||||
Alias: utils.StringPointer("KAM_2"),
|
||||
Address: utils.StringPointer("localhost:8037"),
|
||||
Reconnects: utils.IntPointer(5),
|
||||
Alias: utils.StringPointer("KAM_2"),
|
||||
Address: utils.StringPointer("localhost:8037"),
|
||||
Reconnects: utils.IntPointer(5),
|
||||
Max_reconnect_interval: utils.StringPointer("3ns"),
|
||||
}
|
||||
|
||||
rcv := diffKamConnJsonCfg(v1, v2)
|
||||
@@ -327,3 +331,14 @@ func TestKamAgentCloneSection(t *testing.T) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
func TestKamConnCfgloadFromJsonCfgMaxReconnErr(t *testing.T) {
|
||||
var kamcocfg KamConnCfg
|
||||
|
||||
json := &KamConnJsonCfg{
|
||||
Max_reconnect_interval: utils.StringPointer("invalid duration"),
|
||||
}
|
||||
expErr := `time: invalid duration "invalid duration"`
|
||||
if err = kamcocfg.loadFromJSONCfg(json); err.Error() != expErr {
|
||||
t.Errorf("Expected error <%v>, Received error <%v>", expErr, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2677,3 +2677,43 @@ func TestLoaderSCloneSection(t *testing.T) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp[0]), utils.ToJSON((*rcv.(*LoaderSCfgs))[0]))
|
||||
}
|
||||
}
|
||||
func TestLoaderDataTypeLoadFromJSONId(t *testing.T) {
|
||||
lData := &LoaderDataType{}
|
||||
jsnCfg := &LoaderJsonDataType{
|
||||
Id: utils.StringPointer("IdTest"),
|
||||
}
|
||||
|
||||
if err := lData.loadFromJSONCfg(jsnCfg, nil, ""); err != nil {
|
||||
t.Errorf("Expected error <%v>, Received error <%v>", nil, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoaderSCfgloadFromJSONCfgDataId(t *testing.T) {
|
||||
l := &LoaderSCfg{}
|
||||
jsnCfg := &LoaderJsonCfg{
|
||||
Data: &[]*LoaderJsonDataType{
|
||||
{
|
||||
Id: utils.StringPointer(""),
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := l.loadFromJSONCfg(jsnCfg, nil, ""); err != nil {
|
||||
|
||||
t.Errorf("Expected error <%v>, Received error <%v>", nil, err)
|
||||
}
|
||||
}
|
||||
func TestLoaderSCfgloadFromJSONCacheErr(t *testing.T) {
|
||||
l := &LoaderSCfg{}
|
||||
jsnCfg := &LoaderJsonCfg{
|
||||
Cache: map[string]*CacheParamJsonCfg{
|
||||
"": {
|
||||
Ttl: utils.StringPointer("invalid"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expErr := `time: invalid duration "invalid"`
|
||||
if err := l.loadFromJSONCfg(jsnCfg, nil, ""); err.Error() != expErr {
|
||||
t.Errorf("Expected error <%v>, Received error <%v>", expErr, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user