Added unit tests for config

This commit is contained in:
nickolasdaniel
2021-05-17 14:56:03 +03:00
committed by Dan Christian Bogos
parent 2c8060d05d
commit d9941b095a
10 changed files with 814 additions and 0 deletions

View File

@@ -153,3 +153,110 @@ func TestAccountSCfgClone(t *testing.T) {
t.Errorf("Expected clone to not modify the cloned")
}
}
func TestDiffAccountSJsonCfg(t *testing.T) {
var d *AccountSJsonCfg
v1 := &AccountSCfg{
Enabled: true,
AttributeSConns: []string{"*localhost"},
RateSConns: []string{},
ThresholdSConns: []string{},
IndexedSelects: true,
StringIndexedFields: &[]string{"~*req.Index1"},
PrefixIndexedFields: &[]string{},
SuffixIndexedFields: &[]string{},
NestedFields: true,
MaxIterations: 1,
MaxUsage: nil,
}
v2 := &AccountSCfg{
Enabled: false,
AttributeSConns: []string{"*localhost", "*birpc"},
RateSConns: []string{"*localhost"},
ThresholdSConns: []string{"*localhost"},
IndexedSelects: false,
StringIndexedFields: &[]string{"~*req.Index1"},
PrefixIndexedFields: &[]string{},
SuffixIndexedFields: &[]string{},
NestedFields: false,
MaxIterations: 3,
MaxUsage: utils.NewDecimal(60, 0),
}
expected1 := &AccountSJsonCfg{
Enabled: utils.BoolPointer(false),
Indexed_selects: utils.BoolPointer(false),
Attributes_conns: &[]string{"*localhost", "*birpc"},
Rates_conns: &[]string{"*localhost"},
Thresholds_conns: &[]string{"*localhost"},
String_indexed_fields: nil,
Prefix_indexed_fields: nil,
Suffix_indexed_fields: nil,
Nested_fields: utils.BoolPointer(false),
Max_iterations: utils.IntPointer(3),
Max_usage: utils.StringPointer("60"),
}
rcv := diffAccountSJsonCfg(d, v1, v2)
if !reflect.DeepEqual(rcv, expected1) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected1), utils.ToJSON(rcv))
}
//MaxUsage is nil in v2
v2_2 := &AccountSCfg{
Enabled: false,
AttributeSConns: []string{"*localhost", "*birpc"},
RateSConns: []string{"*localhost"},
ThresholdSConns: []string{"*localhost"},
IndexedSelects: false,
StringIndexedFields: &[]string{"~*req.Index1"},
PrefixIndexedFields: &[]string{},
SuffixIndexedFields: &[]string{},
NestedFields: false,
MaxIterations: 3,
MaxUsage: nil,
}
expected2 := &AccountSJsonCfg{
Enabled: utils.BoolPointer(false),
Indexed_selects: utils.BoolPointer(false),
Attributes_conns: &[]string{"*localhost", "*birpc"},
Rates_conns: &[]string{"*localhost"},
Thresholds_conns: &[]string{"*localhost"},
String_indexed_fields: nil,
Prefix_indexed_fields: nil,
Suffix_indexed_fields: nil,
Nested_fields: utils.BoolPointer(false),
Max_iterations: utils.IntPointer(3),
Max_usage: nil,
}
rcv = diffAccountSJsonCfg(d, v1, v2_2)
if !reflect.DeepEqual(rcv, expected2) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected2), utils.ToJSON(rcv))
}
//Make the two Accounts equal in order to get a nil "d"
v2_3 := v1
expected3 := &AccountSJsonCfg{
Enabled: nil,
Indexed_selects: nil,
Attributes_conns: nil,
Rates_conns: nil,
Thresholds_conns: nil,
String_indexed_fields: nil,
Prefix_indexed_fields: nil,
Suffix_indexed_fields: nil,
Nested_fields: nil,
Max_iterations: nil,
Max_usage: nil,
}
rcv = diffAccountSJsonCfg(d, v1, v2_3)
if !reflect.DeepEqual(rcv, expected3) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected3), utils.ToJSON(rcv))
}
}

View File

@@ -148,3 +148,78 @@ func TestActionSCfgClone(t *testing.T) {
t.Errorf("Expected clone to not modify the cloned")
}
}
func TestDiffActionSJsonCfg(t *testing.T) {
var d *ActionSJsonCfg
v1 := &ActionSCfg{
Enabled: false,
CDRsConns: []string{},
EEsConns: []string{},
ThresholdSConns: []string{},
StatSConns: []string{},
AccountSConns: []string{},
Tenants: &[]string{},
IndexedSelects: false,
StringIndexedFields: &[]string{},
PrefixIndexedFields: &[]string{},
SuffixIndexedFields: &[]string{},
NestedFields: true,
}
v2 := &ActionSCfg{
Enabled: true,
CDRsConns: []string{"*localhost"},
EEsConns: []string{"*localhost"},
ThresholdSConns: []string{"*localhost"},
StatSConns: []string{"*localhost"},
AccountSConns: []string{"*localhost"},
Tenants: &[]string{"cgrates.org"},
IndexedSelects: true,
StringIndexedFields: &[]string{"*req.Index1"},
PrefixIndexedFields: nil,
SuffixIndexedFields: nil,
NestedFields: false,
}
expected := &ActionSJsonCfg{
Enabled: utils.BoolPointer(true),
Cdrs_conns: &[]string{"*localhost"},
Ees_conns: &[]string{"*localhost"},
Thresholds_conns: &[]string{"*localhost"},
Stats_conns: &[]string{"*localhost"},
Accounts_conns: &[]string{"*localhost"},
Tenants: &[]string{"cgrates.org"},
Indexed_selects: utils.BoolPointer(true),
String_indexed_fields: &[]string{"*req.Index1"},
Prefix_indexed_fields: nil,
Suffix_indexed_fields: nil,
Nested_fields: utils.BoolPointer(false),
}
rcv := diffActionSJsonCfg(d, v1, v2)
if !reflect.DeepEqual(rcv, expected) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
}
//The output "d" should be nil when there isn't any difference between v1 and v2_2
v2_2 := v1
expected2 := &ActionSJsonCfg{
Enabled: nil,
Cdrs_conns: nil,
Ees_conns: nil,
Thresholds_conns: nil,
Stats_conns: nil,
Accounts_conns: nil,
Tenants: nil,
Indexed_selects: nil,
String_indexed_fields: nil,
Prefix_indexed_fields: nil,
Suffix_indexed_fields: nil,
Nested_fields: nil,
}
rcv = diffActionSJsonCfg(d, v1, v2_2)
if !reflect.DeepEqual(rcv, expected2) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected2), utils.ToJSON(rcv))
}
}

View File

@@ -117,3 +117,49 @@ func TestAnalyzerSCfgClone(t *testing.T) {
t.Errorf("Expected clone to not modify the cloned")
}
}
func TestDiffAnalyzerSJsonCfg(t *testing.T) {
var d *AnalyzerSJsonCfg
v1 := &AnalyzerSCfg{
Enabled: false,
DBPath: "",
IndexType: utils.MetaPrefix,
TTL: 2 * time.Minute,
CleanupInterval: time.Hour,
}
v2 := &AnalyzerSCfg{
Enabled: true,
DBPath: "/var/spool/cgrates/analyzers",
IndexType: utils.MetaString,
TTL: 3 * time.Minute,
CleanupInterval: 30 * time.Minute,
}
expected := &AnalyzerSJsonCfg{
Enabled: utils.BoolPointer(true),
Db_path: utils.StringPointer("/var/spool/cgrates/analyzers"),
Index_type: utils.StringPointer(utils.MetaString),
Ttl: utils.StringPointer("3m0s"),
Cleanup_interval: utils.StringPointer("30m0s"),
}
rcv := diffAnalyzerSJsonCfg(d, v1, v2)
if !reflect.DeepEqual(rcv, expected) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
}
v2_2 := v1
expected2 := &AnalyzerSJsonCfg{
Enabled: nil,
Db_path: nil,
Index_type: nil,
Ttl: nil,
Cleanup_interval: nil,
}
rcv = diffAnalyzerSJsonCfg(d, v1, v2_2)
if !reflect.DeepEqual(rcv, expected2) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected2), utils.ToJSON(rcv))
}
}

View File

@@ -95,3 +95,38 @@ func TestAPIBanCfgClone(t *testing.T) {
t.Errorf("Expected clone to not modify the cloned")
}
}
func TestDiffAPIBanJsonCfg(t *testing.T) {
var d *APIBanJsonCfg
v1 := &APIBanCfg{
Enabled: false,
Keys: []string{"key1", "key2"},
}
v2 := &APIBanCfg{
Enabled: true,
Keys: []string{"key3", "key4"},
}
expected := &APIBanJsonCfg{
Enabled: utils.BoolPointer(true),
Keys: &[]string{"key3", "key4"},
}
rcv := diffAPIBanJsonCfg(d, v1, v2)
if !reflect.DeepEqual(rcv, expected) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
}
v2_2 := v1
expected2 := &APIBanJsonCfg{
Enabled: nil,
Keys: nil,
}
rcv = diffAPIBanJsonCfg(d, v1, v2_2)
if !reflect.DeepEqual(rcv, expected2) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected2), utils.ToJSON(rcv))
}
}

View File

@@ -117,3 +117,50 @@ func TestApierCfgClone(t *testing.T) {
t.Errorf("Expected clone to not modify the cloned")
}
}
func TestApierCfgDiffAdminSJsonCfg(t *testing.T) {
var d *AdminSJsonCfg
v1 := &AdminSCfg{
Enabled: false,
CachesConns: []string{"*localhost"},
ActionSConns: []string{"*localhost"},
AttributeSConns: []string{"*localhost"},
EEsConns: []string{"*localhost"},
}
v2 := &AdminSCfg{
Enabled: true,
CachesConns: []string{"*birpc"},
ActionSConns: []string{"*birpc"},
AttributeSConns: []string{"*birpc"},
EEsConns: []string{"*birpc"},
}
expected := &AdminSJsonCfg{
Enabled: utils.BoolPointer(true),
Caches_conns: &[]string{"*birpc"},
Actions_conns: &[]string{"*birpc"},
Attributes_conns: &[]string{"*birpc"},
Ees_conns: &[]string{"*birpc"},
}
rcv := diffAdminSJsonCfg(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 := &AdminSJsonCfg{
Enabled: nil,
Caches_conns: nil,
Actions_conns: nil,
Attributes_conns: nil,
Ees_conns: nil,
}
rcv = diffAdminSJsonCfg(d, v1, v2_2)
if !reflect.DeepEqual(expected2, rcv) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected2), utils.ToJSON(rcv))
}
}

View File

@@ -175,3 +175,58 @@ func TestAttributeSCfgClone(t *testing.T) {
t.Errorf("Expected clone to not modify the cloned")
}
}
func TestDiffAttributeSJsonCfg(t *testing.T) {
var d *AttributeSJsonCfg
v1 := &AttributeSCfg{
Enabled: false,
StatSConns: []string{"*localhost"},
ResourceSConns: []string{"*localhost"},
ApierSConns: []string{"*localhost"},
IndexedSelects: false,
StringIndexedFields: &[]string{},
PrefixIndexedFields: &[]string{},
SuffixIndexedFields: &[]string{},
ProcessRuns: 2,
NestedFields: true,
}
v2 := &AttributeSCfg{
Enabled: true,
StatSConns: []string{"*birpc"},
ResourceSConns: []string{"*birpc"},
ApierSConns: []string{"*birpc"},
IndexedSelects: true,
StringIndexedFields: &[]string{"*req.Field1"},
PrefixIndexedFields: nil,
SuffixIndexedFields: nil,
ProcessRuns: 3,
NestedFields: false,
}
expected := &AttributeSJsonCfg{
Enabled: utils.BoolPointer(true),
Stats_conns: &[]string{"*birpc"},
Resources_conns: &[]string{"*birpc"},
Admins_conns: &[]string{"*birpc"},
Indexed_selects: utils.BoolPointer(true),
String_indexed_fields: &[]string{"*req.Field1"},
Prefix_indexed_fields: nil,
Suffix_indexed_fields: nil,
Process_runs: utils.IntPointer(3),
Nested_fields: utils.BoolPointer(false),
}
rcv := diffAttributeSJsonCfg(d, v1, v2)
if !reflect.DeepEqual(rcv, expected) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
}
v2_2 := v1
expected2 := &AttributeSJsonCfg{}
rcv = diffAttributeSJsonCfg(d, v1, v2_2)
if !reflect.DeepEqual(rcv, expected2) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected2), utils.ToJSON(rcv))
}
}

View File

@@ -177,3 +177,170 @@ func TestCacheCfgClone(t *testing.T) {
t.Errorf("Expected clone to not modify the cloned")
}
}
func TestDiffCacheParamJsonCfg(t *testing.T) {
var d *CacheParamJsonCfg
v1 := &CacheParamCfg{
Limit: 2,
TTL: 2 * time.Minute,
StaticTTL: false,
Precache: true,
Replicate: false,
}
v2 := &CacheParamCfg{
Limit: 3,
TTL: 5 * time.Minute,
StaticTTL: true,
Precache: false,
Replicate: true,
}
expected := &CacheParamJsonCfg{
Limit: utils.IntPointer(3),
Ttl: utils.StringPointer("5m0s"),
Static_ttl: utils.BoolPointer(true),
Precache: utils.BoolPointer(false),
Replicate: utils.BoolPointer(true),
}
rcv := diffCacheParamJsonCfg(d, v1, v2)
if !reflect.DeepEqual(rcv, expected) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
}
v2_2 := v1
expected2 := &CacheParamJsonCfg{
Limit: nil,
Ttl: nil,
Static_ttl: nil,
Precache: nil,
Replicate: nil,
}
rcv = diffCacheParamJsonCfg(d, v1, v2_2)
if !reflect.DeepEqual(rcv, expected2) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected2), utils.ToJSON(rcv))
}
}
func TestDiffCacheParamsJsonCfg(t *testing.T) {
var d map[string]*CacheParamJsonCfg
v1 := map[string]*CacheParamCfg{
"CACHE_1": {
Limit: 2,
TTL: 2 * time.Minute,
StaticTTL: false,
Precache: true,
Replicate: false,
},
}
v2 := map[string]*CacheParamCfg{
"CACHE_2": {
Limit: 3,
TTL: 5 * time.Minute,
StaticTTL: true,
Precache: false,
Replicate: true,
},
}
expected := map[string]*CacheParamJsonCfg{
"CACHE_2": {
Limit: utils.IntPointer(3),
Ttl: utils.StringPointer("5m0s"),
Static_ttl: utils.BoolPointer(true),
Precache: nil,
Replicate: utils.BoolPointer(true),
},
}
rcv := diffCacheParamsJsonCfg(d, v1, v2)
if !reflect.DeepEqual(rcv, expected) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
}
v2_2 := v1
expected2 := map[string]*CacheParamJsonCfg{
"CACHE_1": {
Limit: nil,
Ttl: nil,
Static_ttl: nil,
Precache: nil,
Replicate: nil,
},
}
rcv = diffCacheParamsJsonCfg(d, v1, v2_2)
if !reflect.DeepEqual(rcv, expected2) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected2), utils.ToJSON(rcv))
}
}
func TestDiffCacheJsonCfg(t *testing.T) {
var d *CacheJsonCfg
v1 := &CacheCfg{
Partitions: map[string]*CacheParamCfg{
"CACHE_1": {
Limit: 2,
TTL: 2 * time.Minute,
StaticTTL: false,
Precache: true,
Replicate: false,
},
},
ReplicationConns: []string{},
}
v2 := &CacheCfg{
Partitions: map[string]*CacheParamCfg{
"CACHE_2": {
Limit: 3,
TTL: 5 * time.Minute,
StaticTTL: true,
Precache: false,
Replicate: true,
},
},
ReplicationConns: []string{"*repl_conn"},
}
expected := &CacheJsonCfg{
Partitions: map[string]*CacheParamJsonCfg{
"CACHE_2": {
Limit: utils.IntPointer(3),
Ttl: utils.StringPointer("5m0s"),
Static_ttl: utils.BoolPointer(true),
Precache: nil,
Replicate: utils.BoolPointer(true),
},
},
Replication_conns: &[]string{"*repl_conn"},
}
rcv := diffCacheJsonCfg(d, v1, v2)
if !reflect.DeepEqual(rcv, expected) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
}
v2_2 := v1
expected2 := &CacheJsonCfg{
Partitions: map[string]*CacheParamJsonCfg{
"CACHE_1": {
Limit: nil,
Ttl: nil,
Static_ttl: nil,
Precache: nil,
Replicate: nil,
},
},
Replication_conns: nil,
}
rcv = diffCacheJsonCfg(d, v1, v2_2)
if !reflect.DeepEqual(rcv, expected2) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected2), utils.ToJSON(rcv))
}
}

View File

@@ -176,3 +176,70 @@ func TestCdrsCfgClone(t *testing.T) {
t.Errorf("Expected clone to not modify the cloned")
}
}
func TestDiffCdrsJsonCfg(t *testing.T) {
var d *CdrsJsonCfg
v1 := &CdrsCfg{
Enabled: false,
ExtraFields: RSRParsers{
{
Rules: "Rule1",
},
},
StoreCdrs: false,
SMCostRetries: 2,
ChargerSConns: []string{"*localhost"},
AttributeSConns: []string{"*localhost"},
ThresholdSConns: []string{"*localhost"},
StatSConns: []string{"*localhost"},
OnlineCDRExports: []string{},
ActionSConns: []string{"*localhost"},
EEsConns: []string{"*localhost"},
}
v2 := &CdrsCfg{
Enabled: true,
ExtraFields: RSRParsers{
{
Rules: "Rule2",
},
},
StoreCdrs: true,
SMCostRetries: 1,
ChargerSConns: []string{"*birpc"},
AttributeSConns: []string{"*birpc"},
ThresholdSConns: []string{"*birpc"},
StatSConns: []string{"*birpc"},
OnlineCDRExports: []string{"val1"},
ActionSConns: []string{"*birpc"},
EEsConns: []string{"*birpc"},
}
expected := &CdrsJsonCfg{
Enabled: utils.BoolPointer(true),
Extra_fields: &[]string{"Rule2"},
Store_cdrs: utils.BoolPointer(true),
Session_cost_retries: utils.IntPointer(1),
Chargers_conns: &[]string{"*birpc"},
Attributes_conns: &[]string{"*birpc"},
Thresholds_conns: &[]string{"*birpc"},
Stats_conns: &[]string{"*birpc"},
Online_cdr_exports: &[]string{"val1"},
Actions_conns: &[]string{"*birpc"},
Ees_conns: &[]string{"*birpc"},
}
rcv := diffCdrsJsonCfg(d, v1, v2)
if !reflect.DeepEqual(rcv, expected) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
}
v2_2 := v1
expected2 := &CdrsJsonCfg{}
rcv = diffCdrsJsonCfg(d, v1, v2_2)
if !reflect.DeepEqual(rcv, expected2) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected2), utils.ToJSON(rcv))
}
}

View File

@@ -131,3 +131,50 @@ func TestChargerSCfgClone(t *testing.T) {
t.Errorf("Expected clone to not modify the cloned")
}
}
func TestDiffChargerSJsonCfg(t *testing.T) {
var d *ChargerSJsonCfg
v1 := &ChargerSCfg{
Enabled: false,
IndexedSelects: false,
AttributeSConns: []string{"*localhost"},
StringIndexedFields: &[]string{},
PrefixIndexedFields: &[]string{},
SuffixIndexedFields: &[]string{},
NestedFields: true,
}
v2 := &ChargerSCfg{
Enabled: true,
IndexedSelects: true,
AttributeSConns: []string{"*birpc"},
StringIndexedFields: &[]string{"*req.Account"},
PrefixIndexedFields: nil,
SuffixIndexedFields: nil,
NestedFields: false,
}
expected := &ChargerSJsonCfg{
Enabled: utils.BoolPointer(true),
Indexed_selects: utils.BoolPointer(true),
Attributes_conns: &[]string{"*birpc"},
String_indexed_fields: &[]string{"*req.Account"},
Prefix_indexed_fields: nil,
Suffix_indexed_fields: nil,
Nested_fields: utils.BoolPointer(false),
}
rcv := diffChargerSJsonCfg(d, v1, v2)
if !reflect.DeepEqual(rcv, expected) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
}
v2_2 := v1
expected2 := &ChargerSJsonCfg{}
rcv = diffChargerSJsonCfg(d, v1, v2_2)
if !reflect.DeepEqual(rcv, expected2) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected2), utils.ToJSON(rcv))
}
}

View File

@@ -841,6 +841,174 @@ func TestAsteriskAgentCfgClone(t *testing.T) {
}
}
func TestDiffAstConnJsonCfg(t *testing.T) {
v1 := &AsteriskConnCfg{
Alias: "AsteriskAlias",
Address: "localhost:8080",
User: "cgrates.org",
Password: "CGRateS.org",
ConnectAttempts: 2,
Reconnects: 2,
}
v2 := &AsteriskConnCfg{
Alias: "",
Address: "localhost:8037",
User: "itsyscom.com",
Password: "ITSysCOM.com",
ConnectAttempts: 3,
Reconnects: 3,
}
expected := &AstConnJsonCfg{
Alias: utils.StringPointer(""),
Address: utils.StringPointer("localhost:8037"),
User: utils.StringPointer("itsyscom.com"),
Password: utils.StringPointer("ITSysCOM.com"),
Connect_attempts: utils.IntPointer(3),
Reconnects: utils.IntPointer(3),
}
rcv := diffAstConnJsonCfg(v1, v2)
if !reflect.DeepEqual(rcv, expected) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
}
v2_2 := v1
expected2 := &AstConnJsonCfg{
Alias: nil,
Address: nil,
User: nil,
Password: nil,
Connect_attempts: nil,
Reconnects: nil,
}
rcv = diffAstConnJsonCfg(v1, v2_2)
if !reflect.DeepEqual(rcv, expected2) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected2), utils.ToJSON(rcv))
}
}
func TestEqualsAstConnJsonCfg(t *testing.T) {
//When not equal
v1 := []*AsteriskConnCfg{
{
Alias: "AsteriskAlias",
Address: "localhost:8080",
User: "cgrates.org",
Password: "CGRateS.org",
ConnectAttempts: 2,
Reconnects: 2,
},
}
v2 := []*AsteriskConnCfg{
{
Alias: "",
Address: "localhost:8037",
User: "itsyscom.com",
Password: "ITSysCOM.com",
ConnectAttempts: 3,
Reconnects: 3,
},
}
rcv := equalsAstConnJsonCfg(v1, v2)
if rcv {
t.Error("Cfgs should not match")
}
//When equal
v2 = v1
rcv = equalsAstConnJsonCfg(v1, v2)
if !rcv {
t.Error("Cfgs should match")
}
v2 = []*AsteriskConnCfg{
{
Alias: "",
Address: "localhost:8037",
User: "itsyscom.com",
Password: "ITSysCOM.com",
ConnectAttempts: 3,
Reconnects: 3,
},
{
Alias: "AsteriskAlias",
Address: "localhost:8080",
User: "cgrates.org",
Password: "CGRateS.org",
ConnectAttempts: 2,
Reconnects: 2,
},
}
rcv = equalsAstConnJsonCfg(v1, v2)
if rcv {
t.Error("Length of cfgs should not match")
}
}
func TestDiffAsteriskAgentJsonCfg(t *testing.T) {
var d *AsteriskAgentJsonCfg
v1 := &AsteriskAgentCfg{
Enabled: false,
SessionSConns: []string{"*localhost"},
CreateCDR: false,
AsteriskConns: []*AsteriskConnCfg{
{
Alias: "",
Address: "localhost:8037",
User: "itsyscom.com",
Password: "ITSysCOM.com",
ConnectAttempts: 3,
Reconnects: 3,
},
},
}
v2 := &AsteriskAgentCfg{
Enabled: true,
SessionSConns: []string{"*birpc"},
CreateCDR: true,
AsteriskConns: []*AsteriskConnCfg{
{
Alias: "AsteriskAlias",
Address: "localhost:8080",
User: "cgrates.org",
Password: "CGRateS.org",
ConnectAttempts: 2,
Reconnects: 2,
},
},
}
expected := &AsteriskAgentJsonCfg{
Enabled: utils.BoolPointer(true),
Sessions_conns: &[]string{"*birpc"},
Create_cdr: utils.BoolPointer(true),
Asterisk_conns: &[]*AstConnJsonCfg{
{
Alias: utils.StringPointer("AsteriskAlias"),
Address: utils.StringPointer("localhost:8080"),
User: utils.StringPointer("cgrates.org"),
Password: nil,
Connect_attempts: utils.IntPointer(2),
Reconnects: utils.IntPointer(2),
},
},
}
rcv := diffAsteriskAgentJsonCfg(d, v1, v2)
if !reflect.DeepEqual(rcv, expected) {
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
}
}
func TestFsAgentCfgClone(t *testing.T) {
ban := &FsAgentCfg{
Enabled: true,