mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 16:48:45 +05:00
Added coverage test in config
This commit is contained in:
committed by
Dan Christian Bogos
parent
def1c6f90a
commit
9960ea0c10
@@ -139,22 +139,22 @@ func TestAccountSCfgClone(t *testing.T) {
|
||||
if !reflect.DeepEqual(ban, rcv) {
|
||||
t.Errorf("\nExpected: %+v\nReceived: %+v", utils.ToJSON(ban), utils.ToJSON(rcv))
|
||||
}
|
||||
if (rcv.AttributeSConns)[0] = ""; (ban.AttributeSConns)[0] != "*req.index1" {
|
||||
if (rcv.AttributeSConns)[0] = utils.EmptyString; (ban.AttributeSConns)[0] != "*req.index1" {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if (rcv.RateSConns)[0] = ""; (ban.RateSConns)[0] != "*req.index1" {
|
||||
if (rcv.RateSConns)[0] = utils.EmptyString; (ban.RateSConns)[0] != "*req.index1" {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if (rcv.ThresholdSConns)[0] = ""; (ban.ThresholdSConns)[0] != "*req.index1" {
|
||||
if (rcv.ThresholdSConns)[0] = utils.EmptyString; (ban.ThresholdSConns)[0] != "*req.index1" {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if (*rcv.StringIndexedFields)[0] = ""; (*ban.StringIndexedFields)[0] != "*req.index1" {
|
||||
if (*rcv.StringIndexedFields)[0] = utils.EmptyString; (*ban.StringIndexedFields)[0] != "*req.index1" {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if (*rcv.PrefixIndexedFields)[0] = ""; (*ban.PrefixIndexedFields)[0] != "*req.index1" {
|
||||
if (*rcv.PrefixIndexedFields)[0] = utils.EmptyString; (*ban.PrefixIndexedFields)[0] != "*req.index1" {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if (*rcv.SuffixIndexedFields)[0] = ""; (*ban.SuffixIndexedFields)[0] != "*req.index1" {
|
||||
if (*rcv.SuffixIndexedFields)[0] = utils.EmptyString; (*ban.SuffixIndexedFields)[0] != "*req.index1" {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,6 +108,7 @@ func TestActionSCfgClone(t *testing.T) {
|
||||
CDRsConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs)},
|
||||
ThresholdSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds)},
|
||||
StatSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats)},
|
||||
AccountSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAccounts)},
|
||||
Tenants: &[]string{"itsyscom.com"},
|
||||
IndexedSelects: false,
|
||||
StringIndexedFields: &[]string{"*req.index1"},
|
||||
@@ -119,28 +120,31 @@ func TestActionSCfgClone(t *testing.T) {
|
||||
if !reflect.DeepEqual(ban, rcv) {
|
||||
t.Errorf("\nExpected: %+v\nReceived: %+v", utils.ToJSON(ban), utils.ToJSON(rcv))
|
||||
}
|
||||
if (*rcv.Tenants)[0] = ""; (*ban.Tenants)[0] != "itsyscom.com" {
|
||||
if (*rcv.Tenants)[0] = utils.EmptyString; (*ban.Tenants)[0] != "itsyscom.com" {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if (*rcv.StringIndexedFields)[0] = ""; (*ban.StringIndexedFields)[0] != "*req.index1" {
|
||||
if (*rcv.StringIndexedFields)[0] = utils.EmptyString; (*ban.StringIndexedFields)[0] != "*req.index1" {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if (*rcv.PrefixIndexedFields)[0] = ""; (*ban.PrefixIndexedFields)[0] != "*req.index1" {
|
||||
if (*rcv.PrefixIndexedFields)[0] = utils.EmptyString; (*ban.PrefixIndexedFields)[0] != "*req.index1" {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if (*rcv.SuffixIndexedFields)[0] = ""; (*ban.SuffixIndexedFields)[0] != "*req.index1" {
|
||||
if (*rcv.SuffixIndexedFields)[0] = utils.EmptyString; (*ban.SuffixIndexedFields)[0] != "*req.index1" {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if rcv.EEsConns[0] = ""; ban.EEsConns[0] != utils.ConcatenatedKey(utils.MetaInternal, utils.MetaEEs) {
|
||||
if rcv.EEsConns[0] = utils.EmptyString; ban.EEsConns[0] != utils.ConcatenatedKey(utils.MetaInternal, utils.MetaEEs) {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if rcv.CDRsConns[0] = ""; ban.CDRsConns[0] != utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs) {
|
||||
if rcv.CDRsConns[0] = utils.EmptyString; ban.CDRsConns[0] != utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs) {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if rcv.ThresholdSConns[0] = ""; ban.ThresholdSConns[0] != utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds) {
|
||||
if rcv.ThresholdSConns[0] = utils.EmptyString; ban.ThresholdSConns[0] != utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds) {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if rcv.StatSConns[0] = ""; ban.StatSConns[0] != utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats) {
|
||||
if rcv.StatSConns[0] = utils.EmptyString; ban.StatSConns[0] != utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats) {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if rcv.AccountSConns[0] = utils.EmptyString; ban.AccountSConns[0] != utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAccounts) {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestKamConnCfgloadFromJsonCfg(t *testing.T) {
|
||||
func TestKamAgentCfgAsMapInterface(t *testing.T) {
|
||||
cfgJSONStr := `{
|
||||
"kamailio_agent": {
|
||||
"sessions_conns": ["*birpc_internal", "*conn1","*conn2"],
|
||||
"sessions_conns": ["*birpc_internal", "*conn1","*conn2", "*internal"],
|
||||
"create_cdr": true,
|
||||
"timezone": "UTC",
|
||||
"evapi_conns":[
|
||||
@@ -94,7 +94,7 @@ func TestKamAgentCfgAsMapInterface(t *testing.T) {
|
||||
}`
|
||||
eMap := map[string]interface{}{
|
||||
utils.EnabledCfg: false,
|
||||
utils.SessionSConnsCfg: []string{rpcclient.BiRPCInternal, "*conn1", "*conn2"},
|
||||
utils.SessionSConnsCfg: []string{rpcclient.BiRPCInternal, "*conn1", "*conn2", utils.MetaInternal},
|
||||
utils.CreateCdrCfg: true,
|
||||
utils.TimezoneCfg: "UTC",
|
||||
utils.EvapiConnsCfg: []map[string]interface{}{
|
||||
@@ -104,7 +104,7 @@ func TestKamAgentCfgAsMapInterface(t *testing.T) {
|
||||
if cgrCfg, err := NewCGRConfigFromJSONStringWithDefaults(cfgJSONStr); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv := cgrCfg.kamAgentCfg.AsMapInterface(); !reflect.DeepEqual(rcv, eMap) {
|
||||
t.Errorf("Expected %+v \n, received %+v", eMap, rcv)
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(eMap), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -292,6 +292,39 @@ func TestSessionSCfgloadFromJsonCfgCase11(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionSCfgloadFromJsonCfgCase12(t *testing.T) {
|
||||
cfgJSON := &SessionSJsonCfg{
|
||||
Default_usage: &map[string]string{
|
||||
utils.MetaAny: "1ss",
|
||||
utils.MetaVoice: "1ss",
|
||||
utils.MetaData: "1ss",
|
||||
utils.MetaSMS: "1ss",
|
||||
},
|
||||
}
|
||||
expected := "time: unknown unit \"ss\" in duration \"1ss\""
|
||||
jsonCfg := NewDefaultCGRConfig()
|
||||
if err := jsonCfg.sessionSCfg.loadFromJSONCfg(cfgJSON); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetDefaultUsage(t *testing.T) {
|
||||
session := &SessionSCfg{
|
||||
DefaultUsage: map[string]time.Duration{
|
||||
"test": time.Hour,
|
||||
utils.MetaAny: time.Second,
|
||||
},
|
||||
}
|
||||
expected := time.Hour
|
||||
if rcv := session.GetDefaultUsage("test"); !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected %+v, received %+v", expected, rcv)
|
||||
}
|
||||
expected = time.Second
|
||||
if rcv := session.GetDefaultUsage(utils.EmptyString); !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected %+v, received %+v", expected, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionSCfgAsMapInterfaceCase1(t *testing.T) {
|
||||
cfgJSONStr := `{
|
||||
"sessions": {
|
||||
@@ -590,11 +623,12 @@ func TestFsAgentCfgAsMapInterfaceCase3(t *testing.T) {
|
||||
"freeswitch_agent": {
|
||||
"extra_fields": ["randomFields"],
|
||||
"max_wait_connection": "0",
|
||||
"sessions_conns": ["*internal"]
|
||||
}
|
||||
}`
|
||||
eMap := map[string]interface{}{
|
||||
utils.EnabledCfg: false,
|
||||
utils.SessionSConnsCfg: []string{rpcclient.BiRPCInternal},
|
||||
utils.SessionSConnsCfg: []string{utils.MetaInternal},
|
||||
utils.SubscribeParkCfg: true,
|
||||
utils.CreateCdrCfg: false,
|
||||
utils.ExtraFieldsCfg: "randomFields",
|
||||
@@ -708,11 +742,13 @@ func TestAsteriskAgentCfgloadFromJsonCfg(t *testing.T) {
|
||||
|
||||
func TestAsteriskAgentCfgAsMapInterface(t *testing.T) {
|
||||
cfgJSONStr := `{
|
||||
"asterisk_agent": {},
|
||||
"asterisk_agent": {
|
||||
"sessions_conns": ["*internal"],
|
||||
},
|
||||
}`
|
||||
eMap := map[string]interface{}{
|
||||
utils.EnabledCfg: false,
|
||||
utils.SessionSConnsCfg: []string{rpcclient.BiRPCInternal},
|
||||
utils.SessionSConnsCfg: []string{utils.MetaInternal},
|
||||
utils.CreateCdrCfg: false,
|
||||
utils.AsteriskConnsCfg: []map[string]interface{}{
|
||||
{utils.AliasCfg: "", utils.AddressCfg: "127.0.0.1:8088", utils.UserCf: "cgrates", utils.Password: "CGRateS.org", utils.ConnectAttemptsCfg: 3, utils.ReconnectsCfg: 5},
|
||||
|
||||
Reference in New Issue
Block a user