mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-22 23:58:44 +05:00
Added unit tests for config
This commit is contained in:
committed by
Dan Christian Bogos
parent
546c5f6035
commit
f085ba1391
@@ -738,7 +738,6 @@ func TestDiffEventExporterJsonCfg(t *testing.T) {
|
||||
AttributeSCtx: "*sessions",
|
||||
Synchronous: false,
|
||||
Attempts: 2,
|
||||
//FieldSep: "",
|
||||
Fields: []*FCTemplate{
|
||||
{
|
||||
Type: "*string",
|
||||
@@ -785,7 +784,6 @@ func TestDiffEventExporterJsonCfg(t *testing.T) {
|
||||
AttributeSCtx: "*actions",
|
||||
Synchronous: true,
|
||||
Attempts: 3,
|
||||
//FieldSep: ";",
|
||||
Fields: []*FCTemplate{
|
||||
{
|
||||
Type: "*prefix",
|
||||
@@ -823,7 +821,6 @@ func TestDiffEventExporterJsonCfg(t *testing.T) {
|
||||
Attribute_context: utils.StringPointer("*actions"),
|
||||
Synchronous: utils.BoolPointer(true),
|
||||
Attempts: utils.IntPointer(3),
|
||||
//Field_separator: utils.StringPointer(";"),
|
||||
Fields: &[]*FcTemplateJsonCfg{
|
||||
{
|
||||
Type: utils.StringPointer("*prefix"),
|
||||
@@ -923,7 +920,6 @@ func TestDiffEventExportersJsonCfg(t *testing.T) {
|
||||
AttributeSCtx: "*sessions",
|
||||
Synchronous: false,
|
||||
Attempts: 2,
|
||||
//FieldSep: "",
|
||||
Fields: []*FCTemplate{
|
||||
{
|
||||
Type: "*string",
|
||||
@@ -972,7 +968,6 @@ func TestDiffEventExportersJsonCfg(t *testing.T) {
|
||||
AttributeSCtx: "*actions",
|
||||
Synchronous: true,
|
||||
Attempts: 3,
|
||||
//FieldSep: ";",
|
||||
Fields: []*FCTemplate{
|
||||
{
|
||||
Type: "*prefix",
|
||||
@@ -1012,7 +1007,6 @@ func TestDiffEventExportersJsonCfg(t *testing.T) {
|
||||
Attribute_context: utils.StringPointer("*actions"),
|
||||
Synchronous: utils.BoolPointer(true),
|
||||
Attempts: utils.IntPointer(3),
|
||||
//Field_separator: utils.StringPointer(";"),
|
||||
Fields: &[]*FcTemplateJsonCfg{
|
||||
{
|
||||
Type: utils.StringPointer("*prefix"),
|
||||
|
||||
@@ -291,24 +291,26 @@ func (sCft FCTemplates) Clone() (cln FCTemplates) {
|
||||
func (fc *FCTemplate) Equals(fc2 *FCTemplate) bool {
|
||||
return (fc == nil && fc2 == nil) ||
|
||||
(fc != nil && fc2 != nil &&
|
||||
fc.Tag != fc2.Tag &&
|
||||
fc.Type != fc2.Type &&
|
||||
fc.Path != fc2.Path &&
|
||||
fc.Tag == fc2.Tag &&
|
||||
fc.Type == fc2.Type &&
|
||||
fc.Path == fc2.Path &&
|
||||
utils.SliceStringEqual(fc.Filters, fc2.Filters) &&
|
||||
utils.SliceStringEqual(fc.Value.AsStringSlice(), fc2.Value.AsStringSlice()) &&
|
||||
fc.Width != fc2.Width &&
|
||||
fc.Strip != fc2.Strip &&
|
||||
fc.Padding != fc2.Padding &&
|
||||
fc.Mandatory != fc2.Mandatory &&
|
||||
fc.AttributeID != fc2.AttributeID &&
|
||||
fc.NewBranch != fc2.NewBranch &&
|
||||
fc.Timezone != fc2.Timezone &&
|
||||
fc.Blocker != fc2.Blocker &&
|
||||
fc.Layout != fc2.Layout &&
|
||||
fc.CostShiftDigits != fc2.CostShiftDigits &&
|
||||
fc.RoundingDecimals != fc2.RoundingDecimals &&
|
||||
fc.MaskDestID != fc2.MaskDestID &&
|
||||
fc.MaskLen != fc2.MaskLen)
|
||||
fc.Width == fc2.Width &&
|
||||
fc.Strip == fc2.Strip &&
|
||||
fc.Padding == fc2.Padding &&
|
||||
fc.Mandatory == fc2.Mandatory &&
|
||||
fc.AttributeID == fc2.AttributeID &&
|
||||
fc.NewBranch == fc2.NewBranch &&
|
||||
fc.Timezone == fc2.Timezone &&
|
||||
fc.Blocker == fc2.Blocker &&
|
||||
fc.Layout == fc2.Layout &&
|
||||
fc.CostShiftDigits == fc2.CostShiftDigits &&
|
||||
fc.MaskDestID == fc2.MaskDestID &&
|
||||
fc.MaskLen == fc2.MaskLen &&
|
||||
((fc.RoundingDecimals == nil && fc2.RoundingDecimals == nil) ||
|
||||
(fc.RoundingDecimals != nil && fc2.RoundingDecimals != nil &&
|
||||
*fc.RoundingDecimals == *fc2.RoundingDecimals)))
|
||||
}
|
||||
|
||||
type FcTemplatesJsonCfg map[string][]*FcTemplateJsonCfg
|
||||
|
||||
@@ -515,3 +515,193 @@ func TestFCTemplatesClone(t *testing.T) {
|
||||
t.Errorf("expected: %s ,received: %s", utils.ToJSON(initialSmpl), utils.ToJSON(cloned))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFcTemplatesEqual(t *testing.T) {
|
||||
v1 := []*FCTemplate{
|
||||
{
|
||||
Tag: "TenantID",
|
||||
Type: utils.MetaVariable,
|
||||
Path: utils.Tenant,
|
||||
Value: RSRParsers{
|
||||
{
|
||||
Rules: "*req.0",
|
||||
},
|
||||
},
|
||||
Filters: []string{"*string:~*req.Account:1001"},
|
||||
Width: 2,
|
||||
Strip: "strip",
|
||||
Padding: "padding",
|
||||
Mandatory: true,
|
||||
AttributeID: "ATTR_PRF_1001",
|
||||
NewBranch: true,
|
||||
Timezone: "UTC",
|
||||
Blocker: true,
|
||||
Layout: "string",
|
||||
CostShiftDigits: 2,
|
||||
RoundingDecimals: utils.IntPointer(3),
|
||||
MaskDestID: "MK_ID",
|
||||
MaskLen: 2,
|
||||
},
|
||||
}
|
||||
|
||||
v2 := []*FCTemplate{
|
||||
{
|
||||
Tag: "TenantID",
|
||||
Type: utils.MetaVariable,
|
||||
Path: utils.Tenant,
|
||||
Value: RSRParsers{
|
||||
{
|
||||
Rules: "*req.0",
|
||||
},
|
||||
},
|
||||
Filters: []string{"*string:~*req.Account:1001"},
|
||||
Width: 2,
|
||||
Strip: "strip",
|
||||
Padding: "padding",
|
||||
Mandatory: true,
|
||||
AttributeID: "ATTR_PRF_1001",
|
||||
NewBranch: true,
|
||||
Timezone: "UTC",
|
||||
Blocker: true,
|
||||
Layout: "string",
|
||||
CostShiftDigits: 2,
|
||||
RoundingDecimals: utils.IntPointer(3),
|
||||
MaskDestID: "MK_ID",
|
||||
MaskLen: 2,
|
||||
},
|
||||
}
|
||||
|
||||
if !fcTemplatesEqual(v1, v2) {
|
||||
t.Error("Templates should match")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffFcTemplateJsonCfg(t *testing.T) {
|
||||
var d []*FcTemplateJsonCfg
|
||||
|
||||
v1 := []*FCTemplate{
|
||||
{
|
||||
Tag: "TenantID2",
|
||||
},
|
||||
}
|
||||
|
||||
v2 := []*FCTemplate{
|
||||
{
|
||||
Tag: "TenantID",
|
||||
Type: utils.MetaVariable,
|
||||
Path: utils.Tenant,
|
||||
Value: RSRParsers{
|
||||
{
|
||||
Rules: "*req.0",
|
||||
},
|
||||
},
|
||||
Filters: []string{"*string:~*req.Account:1001"},
|
||||
Width: 2,
|
||||
Strip: "strip",
|
||||
Padding: "padding",
|
||||
Mandatory: true,
|
||||
AttributeID: "ATTR_PRF_1001",
|
||||
NewBranch: true,
|
||||
Timezone: "UTC",
|
||||
Blocker: true,
|
||||
Layout: "string",
|
||||
CostShiftDigits: 2,
|
||||
RoundingDecimals: utils.IntPointer(3),
|
||||
MaskDestID: "MK_ID",
|
||||
MaskLen: 2,
|
||||
},
|
||||
}
|
||||
|
||||
expected := []*FcTemplateJsonCfg{
|
||||
{
|
||||
Tag: utils.StringPointer("TenantID"),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Path: utils.StringPointer(utils.Tenant),
|
||||
Value: utils.StringPointer("*req.0"),
|
||||
Filters: &[]string{"*string:~*req.Account:1001"},
|
||||
Width: utils.IntPointer(2),
|
||||
Strip: utils.StringPointer("strip"),
|
||||
Padding: utils.StringPointer("padding"),
|
||||
Mandatory: utils.BoolPointer(true),
|
||||
Attribute_id: utils.StringPointer("ATTR_PRF_1001"),
|
||||
New_branch: utils.BoolPointer(true),
|
||||
Timezone: utils.StringPointer("UTC"),
|
||||
Blocker: utils.BoolPointer(true),
|
||||
Layout: utils.StringPointer("string"),
|
||||
Cost_shift_digits: utils.IntPointer(2),
|
||||
Rounding_decimals: utils.IntPointer(3),
|
||||
Mask_destinationd_id: utils.StringPointer("MK_ID"),
|
||||
Mask_length: utils.IntPointer(2),
|
||||
},
|
||||
}
|
||||
|
||||
rcv := diffFcTemplateJsonCfg(d, v1, v2, ";")
|
||||
if !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffFcTemplatesJsonCfg(t *testing.T) {
|
||||
var d FcTemplatesJsonCfg
|
||||
|
||||
v1 := map[string][]*FCTemplate{}
|
||||
|
||||
v2 := FCTemplates{
|
||||
"T1": {
|
||||
{
|
||||
Tag: "TenantID",
|
||||
Type: utils.MetaVariable,
|
||||
Path: utils.Tenant,
|
||||
Value: RSRParsers{
|
||||
{
|
||||
Rules: "*req.0",
|
||||
},
|
||||
},
|
||||
Filters: []string{"*string:~*req.Account:1001"},
|
||||
Width: 2,
|
||||
Strip: "strip",
|
||||
Padding: "padding",
|
||||
Mandatory: true,
|
||||
AttributeID: "ATTR_PRF_1001",
|
||||
NewBranch: true,
|
||||
Timezone: "UTC",
|
||||
Blocker: true,
|
||||
Layout: "string",
|
||||
CostShiftDigits: 2,
|
||||
RoundingDecimals: utils.IntPointer(3),
|
||||
MaskDestID: "MK_ID",
|
||||
MaskLen: 2,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expected := FcTemplatesJsonCfg{
|
||||
"T1": {
|
||||
{
|
||||
Tag: utils.StringPointer("TenantID"),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Path: utils.StringPointer(utils.Tenant),
|
||||
Value: utils.StringPointer("*req.0"),
|
||||
Filters: &[]string{"*string:~*req.Account:1001"},
|
||||
Width: utils.IntPointer(2),
|
||||
Strip: utils.StringPointer("strip"),
|
||||
Padding: utils.StringPointer("padding"),
|
||||
Mandatory: utils.BoolPointer(true),
|
||||
Attribute_id: utils.StringPointer("ATTR_PRF_1001"),
|
||||
New_branch: utils.BoolPointer(true),
|
||||
Timezone: utils.StringPointer("UTC"),
|
||||
Blocker: utils.BoolPointer(true),
|
||||
Layout: utils.StringPointer("string"),
|
||||
Cost_shift_digits: utils.IntPointer(2),
|
||||
Rounding_decimals: utils.IntPointer(3),
|
||||
Mask_destinationd_id: utils.StringPointer("MK_ID"),
|
||||
Mask_length: utils.IntPointer(2),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
rcv := diffFcTemplatesJsonCfg(d, v1, v2, ";")
|
||||
if !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,3 +99,38 @@ func TestFilterSCfgClone(t *testing.T) {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffFilterSJsonCfg(t *testing.T) {
|
||||
var d *FilterSJsonCfg
|
||||
|
||||
v1 := &FilterSCfg{
|
||||
StatSConns: []string{},
|
||||
ResourceSConns: []string{},
|
||||
AdminSConns: []string{},
|
||||
}
|
||||
|
||||
v2 := &FilterSCfg{
|
||||
StatSConns: []string{"*localhost"},
|
||||
ResourceSConns: []string{"*localhost"},
|
||||
AdminSConns: []string{"*localhost"},
|
||||
}
|
||||
|
||||
expected := &FilterSJsonCfg{
|
||||
Stats_conns: &[]string{"*localhost"},
|
||||
Resources_conns: &[]string{"*localhost"},
|
||||
Admins_conns: &[]string{"*localhost"},
|
||||
}
|
||||
|
||||
rcv := diffFilterSJsonCfg(d, v1, v2)
|
||||
if !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
v1 = v2
|
||||
expected2 := &FilterSJsonCfg{}
|
||||
|
||||
rcv = diffFilterSJsonCfg(d, v1, v2)
|
||||
if !reflect.DeepEqual(rcv, expected2) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected2), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,3 +250,97 @@ func TestGeneralCfgClone(t *testing.T) {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffGeneralJsonCfg(t *testing.T) {
|
||||
var d *GeneralJsonCfg
|
||||
|
||||
v1 := &GeneralCfg{
|
||||
NodeID: "randomID2",
|
||||
Logger: utils.LoggerCfg,
|
||||
LogLevel: 7,
|
||||
RoundingDecimals: 1,
|
||||
DBDataEncoding: "msgpack2",
|
||||
TpExportPath: "/var/spool/cgrates/tpe/test",
|
||||
PosterAttempts: 5,
|
||||
FailedPostsDir: "/var/spool/cgrates/failed_posts/test",
|
||||
DefaultReqType: utils.MetaPrepaid,
|
||||
DefaultCategory: utils.ForcedDisconnectCfg,
|
||||
DefaultTenant: "itsyscom.com",
|
||||
DefaultTimezone: "UTC",
|
||||
ConnectAttempts: 5,
|
||||
Reconnects: 2,
|
||||
ConnectTimeout: 5 * time.Second,
|
||||
ReplyTimeout: 1 * time.Second,
|
||||
DigestSeparator: "",
|
||||
DigestEqual: "",
|
||||
MaxParallelConns: 50,
|
||||
RSRSep: "",
|
||||
DefaultCaching: utils.MetaClear,
|
||||
FailedPostsTTL: 5,
|
||||
}
|
||||
|
||||
v2 := &GeneralCfg{
|
||||
NodeID: "randomID",
|
||||
Logger: utils.MetaSysLog,
|
||||
LogLevel: 6,
|
||||
RoundingDecimals: 5,
|
||||
DBDataEncoding: "msgpack",
|
||||
TpExportPath: "/var/spool/cgrates/tpe",
|
||||
PosterAttempts: 3,
|
||||
FailedPostsDir: "/var/spool/cgrates/failed_posts",
|
||||
DefaultReqType: utils.MetaRated,
|
||||
DefaultCategory: utils.Call,
|
||||
DefaultTenant: "cgrates.org",
|
||||
DefaultTimezone: "Local",
|
||||
ConnectAttempts: 3,
|
||||
Reconnects: -1,
|
||||
ConnectTimeout: time.Second,
|
||||
ReplyTimeout: 2 * time.Second,
|
||||
DigestSeparator: ",",
|
||||
DigestEqual: ":",
|
||||
MaxParallelConns: 100,
|
||||
RSRSep: ";",
|
||||
DefaultCaching: utils.MetaReload,
|
||||
LockingTimeout: 2 * time.Second,
|
||||
FailedPostsTTL: 2,
|
||||
}
|
||||
|
||||
expected := &GeneralJsonCfg{
|
||||
Node_id: utils.StringPointer("randomID"),
|
||||
Logger: utils.StringPointer(utils.MetaSysLog),
|
||||
Log_level: utils.IntPointer(6),
|
||||
Rounding_decimals: utils.IntPointer(5),
|
||||
Dbdata_encoding: utils.StringPointer("msgpack"),
|
||||
Tpexport_dir: utils.StringPointer("/var/spool/cgrates/tpe"),
|
||||
Failed_posts_dir: utils.StringPointer("/var/spool/cgrates/failed_posts"),
|
||||
Poster_attempts: utils.IntPointer(3),
|
||||
Default_request_type: utils.StringPointer(utils.MetaRated),
|
||||
Default_category: utils.StringPointer(utils.Call),
|
||||
Default_tenant: utils.StringPointer("cgrates.org"),
|
||||
Default_timezone: utils.StringPointer("Local"),
|
||||
Default_caching: utils.StringPointer(utils.MetaReload),
|
||||
Connect_attempts: utils.IntPointer(3),
|
||||
Reconnects: utils.IntPointer(-1),
|
||||
Connect_timeout: utils.StringPointer("1s"),
|
||||
Reply_timeout: utils.StringPointer("2s"),
|
||||
Locking_timeout: utils.StringPointer("2s"),
|
||||
Digest_separator: utils.StringPointer(","),
|
||||
Rsr_separator: utils.StringPointer(";"),
|
||||
Digest_equal: utils.StringPointer(":"),
|
||||
Failed_posts_ttl: utils.StringPointer("2ns"),
|
||||
Max_parallel_conns: utils.IntPointer(100),
|
||||
}
|
||||
|
||||
rcv := diffGeneralJsonCfg(d, 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 = &GeneralJsonCfg{}
|
||||
|
||||
rcv = diffGeneralJsonCfg(d, v1, v2)
|
||||
if !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -498,3 +498,135 @@ func TestHTTPAgentCfgsClone(t *testing.T) {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEqualsHTTPAgentCfgs(t *testing.T) {
|
||||
v1 := HTTPAgentCfgs{
|
||||
{
|
||||
ID: "RANDOM_ID",
|
||||
URL: "/url",
|
||||
SessionSConns: []string{"*localhost"},
|
||||
RequestPayload: "*url",
|
||||
ReplyPayload: "*xml",
|
||||
RequestProcessors: []*RequestProcessor{
|
||||
{
|
||||
ID: "OutboundAUTHDryRun",
|
||||
Filters: []string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep),
|
||||
Flags: utils.FlagsWithParams{utils.MetaDryRun: {}},
|
||||
RequestFields: []*FCTemplate{},
|
||||
ReplyFields: []*FCTemplate{
|
||||
{
|
||||
Tag: "Allow",
|
||||
Path: "response.Allow",
|
||||
Type: "*constant",
|
||||
Value: NewRSRParsersMustCompile("1", utils.InfieldSep),
|
||||
Mandatory: true,
|
||||
Layout: time.RFC3339,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
v2 := HTTPAgentCfgs{
|
||||
{
|
||||
ID: "RANDOM_ID2",
|
||||
URL: "/url",
|
||||
SessionSConns: []string{"*localhost"},
|
||||
RequestPayload: "*url",
|
||||
ReplyPayload: "*xml",
|
||||
RequestProcessors: []*RequestProcessor{
|
||||
{
|
||||
ID: "OutboundAUTHDryRun",
|
||||
Filters: []string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep),
|
||||
Flags: utils.FlagsWithParams{utils.MetaDryRun: {}},
|
||||
RequestFields: []*FCTemplate{},
|
||||
ReplyFields: []*FCTemplate{
|
||||
{
|
||||
Tag: "Allow",
|
||||
Path: "response.Allow",
|
||||
Type: "*constant",
|
||||
Value: NewRSRParsersMustCompile("1", utils.InfieldSep),
|
||||
Mandatory: true,
|
||||
Layout: time.RFC3339,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if equalsHTTPAgentCfgs(v1, v2) {
|
||||
t.Error("HTTPAgents should not match")
|
||||
}
|
||||
|
||||
v2[0].ID = "RANDOM_ID"
|
||||
|
||||
if !equalsHTTPAgentCfgs(v1, v2) {
|
||||
t.Error("HTTPAgents should match")
|
||||
}
|
||||
|
||||
v2 = HTTPAgentCfgs{}
|
||||
if equalsHTTPAgentCfgs(v1, v2) {
|
||||
t.Error("HTTPAgents should not match")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetHttpAgentJsonCfg(t *testing.T) {
|
||||
d := []*HttpAgentJsonCfg{
|
||||
{
|
||||
Id: utils.StringPointer("ID_1"),
|
||||
Url: utils.StringPointer("/url"),
|
||||
Sessions_conns: &[]string{"*localhost"},
|
||||
},
|
||||
}
|
||||
|
||||
expected := &HttpAgentJsonCfg{
|
||||
Id: utils.StringPointer("ID_1"),
|
||||
Url: utils.StringPointer("/url"),
|
||||
Sessions_conns: &[]string{"*localhost"},
|
||||
}
|
||||
|
||||
rcv, idx := getHttpAgentJsonCfg(d, "ID_1")
|
||||
if !reflect.DeepEqual(expected, rcv) {
|
||||
t.Errorf("Expected %v \n but received \n %v", expected, rcv)
|
||||
} else if idx != 0 {
|
||||
t.Errorf("Expected %v \n but received \n %v", 0, idx)
|
||||
}
|
||||
|
||||
rcv, idx = getHttpAgentJsonCfg(d, "ID_2")
|
||||
if rcv != nil {
|
||||
t.Errorf("Expected %v \n but received \n %v", expected, rcv)
|
||||
} else if idx != -1 {
|
||||
t.Errorf("Expected %v \n but received \n %v", 0, idx)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetHttpAgentCfg(t *testing.T) {
|
||||
d := HTTPAgentCfgs{
|
||||
{
|
||||
ID: "ID_1",
|
||||
URL: "/url",
|
||||
SessionSConns: []string{"*localhost"},
|
||||
},
|
||||
}
|
||||
|
||||
expected := &HTTPAgentCfg{
|
||||
ID: "ID_1",
|
||||
URL: "/url",
|
||||
SessionSConns: []string{"*localhost"},
|
||||
}
|
||||
|
||||
rcv := getHTTPAgentCfg(d, "ID_1")
|
||||
if !reflect.DeepEqual(expected, rcv) {
|
||||
t.Errorf("Expected %v \n but received \n %v", expected, rcv)
|
||||
}
|
||||
|
||||
expected = new(HTTPAgentCfg)
|
||||
rcv = getHTTPAgentCfg(d, "ID_2")
|
||||
if !reflect.DeepEqual(expected, rcv) {
|
||||
t.Errorf("Expected %v \n but received \n %v", expected, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ func diffHTTPJsonCfg(d *HTTPJsonCfg, v1, v2 *HTTPCfg) *HTTPJsonCfg {
|
||||
if v1.UseBasicAuth != v2.UseBasicAuth {
|
||||
d.Use_basic_auth = utils.BoolPointer(v2.UseBasicAuth)
|
||||
}
|
||||
if utils.MapStringStringEqual(v1.AuthUsers, v2.AuthUsers) {
|
||||
if !utils.MapStringStringEqual(v1.AuthUsers, v2.AuthUsers) {
|
||||
d.Auth_users = &v2.AuthUsers
|
||||
}
|
||||
d.Client_opts = diffMap(d.Client_opts, v1.ClientOpts, v2.ClientOpts)
|
||||
|
||||
@@ -173,3 +173,56 @@ func TestHTTPCfgClone(t *testing.T) {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffHTTPJsonCfg(t *testing.T) {
|
||||
var d *HTTPJsonCfg
|
||||
|
||||
v1 := &HTTPCfg{
|
||||
JsonRPCURL: "JsonRpcUrl",
|
||||
RegistrarSURL: "RegistrarSUrl",
|
||||
WSURL: "WSUrl",
|
||||
FreeswitchCDRsURL: "FsCdrsUrl",
|
||||
CDRsURL: "CdrsUrl",
|
||||
UseBasicAuth: true,
|
||||
AuthUsers: map[string]string{
|
||||
"User1": "passUser1",
|
||||
},
|
||||
ClientOpts: map[string]interface{}{},
|
||||
}
|
||||
|
||||
v2 := &HTTPCfg{
|
||||
JsonRPCURL: "JsonRpcUrl2",
|
||||
RegistrarSURL: "RegistrarSUrl2",
|
||||
WSURL: "WsUrl2",
|
||||
FreeswitchCDRsURL: "FsCdrsUrl2",
|
||||
CDRsURL: "CdrsUrl2",
|
||||
UseBasicAuth: false,
|
||||
AuthUsers: map[string]string{
|
||||
"User2": "passUser2",
|
||||
},
|
||||
ClientOpts: map[string]interface{}{
|
||||
"C_OPT1": "opt",
|
||||
},
|
||||
}
|
||||
|
||||
expected := &HTTPJsonCfg{
|
||||
Json_rpc_url: utils.StringPointer("JsonRpcUrl2"),
|
||||
Registrars_url: utils.StringPointer("RegistrarSUrl2"),
|
||||
Ws_url: utils.StringPointer("WsUrl2"),
|
||||
Freeswitch_cdrs_url: utils.StringPointer("FsCdrsUrl2"),
|
||||
Http_Cdrs: utils.StringPointer("CdrsUrl2"),
|
||||
Use_basic_auth: utils.BoolPointer(false),
|
||||
Auth_users: &map[string]string{
|
||||
"User2": "passUser2",
|
||||
},
|
||||
Client_opts: map[string]interface{}{
|
||||
"C_OPT1": "opt",
|
||||
},
|
||||
}
|
||||
|
||||
rcv := diffHTTPJsonCfg(d, v1, v2)
|
||||
if !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -147,3 +147,134 @@ func TestKamAgentCfgClone(t *testing.T) {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffKamConnJsonCfg(t *testing.T) {
|
||||
v1 := &KamConnCfg{
|
||||
Alias: "KAM",
|
||||
Address: "localhost:8080",
|
||||
Reconnects: 2,
|
||||
}
|
||||
|
||||
v2 := &KamConnCfg{
|
||||
Alias: "KAM_2",
|
||||
Address: "localhost:8037",
|
||||
Reconnects: 5,
|
||||
}
|
||||
|
||||
expected := &KamConnJsonCfg{
|
||||
Alias: utils.StringPointer("KAM_2"),
|
||||
Address: utils.StringPointer("localhost:8037"),
|
||||
Reconnects: utils.IntPointer(5),
|
||||
}
|
||||
|
||||
rcv := diffKamConnJsonCfg(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 = &KamConnJsonCfg{}
|
||||
|
||||
rcv = diffKamConnJsonCfg(v1, v2)
|
||||
if !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestEqualsKamConnsCfg(t *testing.T) {
|
||||
v1 := []*KamConnCfg{
|
||||
{
|
||||
Alias: "KAM",
|
||||
Address: "localhost:8080",
|
||||
Reconnects: 2,
|
||||
},
|
||||
}
|
||||
|
||||
v2 := []*KamConnCfg{
|
||||
{
|
||||
Alias: "KAM_2",
|
||||
Address: "localhost:8037",
|
||||
Reconnects: 5,
|
||||
},
|
||||
}
|
||||
|
||||
if equalsKamConnsCfg(v1, v2) {
|
||||
t.Error("Conns should not match")
|
||||
}
|
||||
|
||||
v2 = []*KamConnCfg{
|
||||
{
|
||||
Alias: "KAM",
|
||||
Address: "localhost:8080",
|
||||
Reconnects: 2,
|
||||
},
|
||||
}
|
||||
|
||||
if !equalsKamConnsCfg(v1, v2) {
|
||||
t.Error("Conns should match")
|
||||
}
|
||||
|
||||
v2 = []*KamConnCfg{}
|
||||
if equalsKamConnsCfg(v1, v2) {
|
||||
t.Error("Conns should not match")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffKamAgentJsonCfg(t *testing.T) {
|
||||
var d *KamAgentJsonCfg
|
||||
|
||||
v1 := &KamAgentCfg{
|
||||
Enabled: false,
|
||||
SessionSConns: []string{"*localhost"},
|
||||
CreateCdr: false,
|
||||
EvapiConns: []*KamConnCfg{
|
||||
{
|
||||
Alias: "KAM_2",
|
||||
Address: "localhost:8037",
|
||||
Reconnects: 5,
|
||||
},
|
||||
},
|
||||
Timezone: "UTC",
|
||||
}
|
||||
|
||||
v2 := &KamAgentCfg{
|
||||
Enabled: true,
|
||||
SessionSConns: []string{"*birpc"},
|
||||
CreateCdr: true,
|
||||
EvapiConns: []*KamConnCfg{
|
||||
{
|
||||
Alias: "KAM_1",
|
||||
Address: "localhost:8080",
|
||||
Reconnects: 2,
|
||||
},
|
||||
},
|
||||
Timezone: "EEST",
|
||||
}
|
||||
|
||||
expected := &KamAgentJsonCfg{
|
||||
Enabled: utils.BoolPointer(true),
|
||||
Sessions_conns: &[]string{"*birpc"},
|
||||
Create_cdr: utils.BoolPointer(true),
|
||||
Evapi_conns: &[]*KamConnJsonCfg{
|
||||
{
|
||||
Alias: utils.StringPointer("KAM_1"),
|
||||
Address: utils.StringPointer("localhost:8080"),
|
||||
Reconnects: utils.IntPointer(2),
|
||||
},
|
||||
},
|
||||
Timezone: utils.StringPointer("EEST"),
|
||||
}
|
||||
|
||||
rcv := diffKamAgentJsonCfg(d, 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 = &KamAgentJsonCfg{}
|
||||
|
||||
rcv = diffKamAgentJsonCfg(d, v1, v2)
|
||||
if !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,3 +110,47 @@ func TestListenCfgClone(t *testing.T) {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffListenJsonCfg(t *testing.T) {
|
||||
var d *ListenJsonCfg
|
||||
|
||||
v1 := &ListenCfg{
|
||||
RPCJSONListen: "localhost:8080",
|
||||
RPCGOBListen: "localhost:8081",
|
||||
HTTPListen: "localhost:8082",
|
||||
RPCJSONTLSListen: "localhost:8083",
|
||||
RPCGOBTLSListen: "localhost:8084",
|
||||
HTTPTLSListen: "localhost:8085",
|
||||
}
|
||||
|
||||
v2 := &ListenCfg{
|
||||
RPCJSONListen: "localhost:7080",
|
||||
RPCGOBListen: "localhost:7081",
|
||||
HTTPListen: "localhost:7082",
|
||||
RPCJSONTLSListen: "localhost:7083",
|
||||
RPCGOBTLSListen: "localhost:7084",
|
||||
HTTPTLSListen: "localhost:7085",
|
||||
}
|
||||
|
||||
expected := &ListenJsonCfg{
|
||||
Rpc_json: utils.StringPointer("localhost:7080"),
|
||||
Rpc_gob: utils.StringPointer("localhost:7081"),
|
||||
Http: utils.StringPointer("localhost:7082"),
|
||||
Rpc_json_tls: utils.StringPointer("localhost:7083"),
|
||||
Rpc_gob_tls: utils.StringPointer("localhost:7084"),
|
||||
Http_tls: utils.StringPointer("localhost:7085"),
|
||||
}
|
||||
|
||||
rcv := diffListenJsonCfg(d, 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 = &ListenJsonCfg{}
|
||||
|
||||
rcv = diffListenJsonCfg(d, v1, v2)
|
||||
if !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,3 +440,222 @@ func TestLoaderSCfgsClone(t *testing.T) {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEqualsLoaderDatasType(t *testing.T) {
|
||||
v1 := []*LoaderDataType{
|
||||
{
|
||||
Type: "*json",
|
||||
Filename: "file.json",
|
||||
Flags: utils.FlagsWithParams{
|
||||
"FLAG_1": {
|
||||
"PARAM_1": []string{"param1"},
|
||||
},
|
||||
},
|
||||
Fields: []*FCTemplate{
|
||||
{
|
||||
Type: "Type",
|
||||
Tag: "Tag",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
v2 := []*LoaderDataType{
|
||||
{
|
||||
Type: "*xml",
|
||||
Filename: "file.xml",
|
||||
Flags: utils.FlagsWithParams{
|
||||
"FLAG_2": {
|
||||
"PARAM_2": []string{"param2"},
|
||||
},
|
||||
},
|
||||
Fields: []*FCTemplate{
|
||||
{
|
||||
Type: "Type2",
|
||||
Tag: "Tag2",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if equalsLoaderDatasType(v1, v2) {
|
||||
t.Error("Loaders should not match")
|
||||
}
|
||||
|
||||
v1 = v2
|
||||
if !equalsLoaderDatasType(v1, v2) {
|
||||
t.Error("Loaders should match")
|
||||
}
|
||||
|
||||
v2 = []*LoaderDataType{}
|
||||
if equalsLoaderDatasType(v1, v2) {
|
||||
t.Error("Loaders should not match")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffLoaderJsonCfg(t *testing.T) {
|
||||
|
||||
v1 := &LoaderSCfg{
|
||||
ID: "LoaderID",
|
||||
Enabled: true,
|
||||
Tenant: RSRParsers{
|
||||
{
|
||||
Rules: "cgrates.org",
|
||||
},
|
||||
},
|
||||
DryRun: false,
|
||||
RunDelay: 1 * time.Millisecond,
|
||||
LockFileName: "lockFileName",
|
||||
CacheSConns: []string{"*localhost"},
|
||||
FieldSeparator: ";",
|
||||
TpInDir: "/tp/in/dir",
|
||||
TpOutDir: "/tp/out/dir",
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
v2 := &LoaderSCfg{
|
||||
ID: "LoaderID2",
|
||||
Enabled: false,
|
||||
Tenant: RSRParsers{
|
||||
{
|
||||
Rules: "itsyscom.com",
|
||||
},
|
||||
},
|
||||
DryRun: true,
|
||||
RunDelay: 2 * time.Millisecond,
|
||||
LockFileName: "lockFileName2",
|
||||
CacheSConns: []string{"*birpc"},
|
||||
FieldSeparator: ":",
|
||||
TpInDir: "/tp/in/dir/2",
|
||||
TpOutDir: "/tp/out/dir/2",
|
||||
Data: []*LoaderDataType{
|
||||
{
|
||||
Type: "*xml",
|
||||
Filename: "file.xml",
|
||||
Flags: utils.FlagsWithParams{
|
||||
"FLAG_2": {
|
||||
"PARAM_2": []string{"param2"},
|
||||
},
|
||||
},
|
||||
Fields: []*FCTemplate{
|
||||
{
|
||||
Type: "Type2",
|
||||
Tag: "Tag2",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expected := &LoaderJsonCfg{
|
||||
ID: utils.StringPointer("LoaderID2"),
|
||||
Enabled: utils.BoolPointer(false),
|
||||
Tenant: utils.StringPointer("itsyscom.com"),
|
||||
Dry_run: utils.BoolPointer(true),
|
||||
Run_delay: utils.StringPointer("2ms"),
|
||||
Lock_filename: utils.StringPointer("lockFileName2"),
|
||||
Caches_conns: &[]string{"*birpc"},
|
||||
Field_separator: utils.StringPointer(":"),
|
||||
Tp_in_dir: utils.StringPointer("/tp/in/dir/2"),
|
||||
Tp_out_dir: utils.StringPointer("/tp/out/dir/2"),
|
||||
Data: &[]*LoaderJsonDataType{
|
||||
{
|
||||
Type: utils.StringPointer("*xml"),
|
||||
File_name: utils.StringPointer("file.xml"),
|
||||
Flags: &[]string{"FLAG_2:PARAM_2:param2"},
|
||||
Fields: &[]*FcTemplateJsonCfg{
|
||||
{
|
||||
Type: utils.StringPointer("Type2"),
|
||||
Tag: utils.StringPointer("Tag2"),
|
||||
Layout: utils.StringPointer(""),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
rcv := diffLoaderJsonCfg(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 = &LoaderJsonCfg{}
|
||||
rcv = diffLoaderJsonCfg(v1, v2, ";")
|
||||
if !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestEqualsLoadersJsonCfg(t *testing.T) {
|
||||
v1 := LoaderSCfgs{
|
||||
{
|
||||
ID: "LoaderID",
|
||||
Enabled: true,
|
||||
Tenant: RSRParsers{
|
||||
{
|
||||
Rules: "cgrates.org",
|
||||
},
|
||||
},
|
||||
DryRun: false,
|
||||
RunDelay: 1 * time.Millisecond,
|
||||
LockFileName: "lockFileName",
|
||||
CacheSConns: []string{"*localhost"},
|
||||
FieldSeparator: ";",
|
||||
TpInDir: "/tp/in/dir",
|
||||
TpOutDir: "/tp/out/dir",
|
||||
Data: nil,
|
||||
},
|
||||
}
|
||||
|
||||
v2 := LoaderSCfgs{
|
||||
{
|
||||
ID: "LoaderID2",
|
||||
Enabled: false,
|
||||
Tenant: RSRParsers{
|
||||
{
|
||||
Rules: "itsyscom.com",
|
||||
},
|
||||
},
|
||||
DryRun: true,
|
||||
RunDelay: 2 * time.Millisecond,
|
||||
LockFileName: "lockFileName2",
|
||||
CacheSConns: []string{"*birpc"},
|
||||
FieldSeparator: ":",
|
||||
TpInDir: "/tp/in/dir/2",
|
||||
TpOutDir: "/tp/out/dir/2",
|
||||
Data: []*LoaderDataType{
|
||||
{
|
||||
Type: "*xml",
|
||||
Filename: "file.xml",
|
||||
Flags: utils.FlagsWithParams{
|
||||
"FLAG_2": {
|
||||
"PARAM_2": []string{"param2"},
|
||||
},
|
||||
},
|
||||
Fields: []*FCTemplate{
|
||||
{
|
||||
Type: "Type2",
|
||||
Tag: "Tag2",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if equalsLoadersJsonCfg(v1, v2) {
|
||||
t.Error("Loaders shouldn't match")
|
||||
}
|
||||
|
||||
v2 = v1
|
||||
if !equalsLoadersJsonCfg(v1, v2) {
|
||||
t.Error("Loaders shouldn't match")
|
||||
}
|
||||
|
||||
v2 = LoaderSCfgs{}
|
||||
if equalsLoadersJsonCfg(v1, v2) {
|
||||
t.Error("Loaders shouldn't match")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1037,6 +1037,157 @@ func TestFsAgentCfgClone(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffFsConnJsonCfg(t *testing.T) {
|
||||
v1 := &FsConnCfg{
|
||||
Address: "localhost:8080",
|
||||
Password: "FsPassword",
|
||||
Reconnects: 3,
|
||||
Alias: "FS",
|
||||
}
|
||||
|
||||
v2 := &FsConnCfg{
|
||||
Address: "localhost:8037",
|
||||
Password: "AnotherFsPassword",
|
||||
Reconnects: 1,
|
||||
Alias: "FS_AGENT",
|
||||
}
|
||||
|
||||
expected := &FsConnJsonCfg{
|
||||
Address: utils.StringPointer("localhost:8037"),
|
||||
Password: utils.StringPointer("AnotherFsPassword"),
|
||||
Reconnects: utils.IntPointer(1),
|
||||
Alias: utils.StringPointer("FS_AGENT"),
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestEqualsFsConnsJsonCfg(t *testing.T) {
|
||||
v1 := []*FsConnCfg{
|
||||
{
|
||||
Address: "localhost:8080",
|
||||
Password: "FsPassword",
|
||||
Reconnects: 3,
|
||||
Alias: "FS",
|
||||
},
|
||||
}
|
||||
|
||||
v2 := []*FsConnCfg{
|
||||
{
|
||||
Address: "localhost:8037",
|
||||
Password: "AnotherFsPassword",
|
||||
Reconnects: 1,
|
||||
Alias: "FS_AGENT",
|
||||
},
|
||||
}
|
||||
|
||||
if equalsFsConnsJsonCfg(v1, v2) {
|
||||
t.Error("Conns should not match")
|
||||
}
|
||||
|
||||
v2 = []*FsConnCfg{
|
||||
{
|
||||
Address: "localhost:8080",
|
||||
Password: "FsPassword",
|
||||
Reconnects: 3,
|
||||
Alias: "FS",
|
||||
},
|
||||
}
|
||||
|
||||
if !equalsFsConnsJsonCfg(v1, v2) {
|
||||
t.Error("Conns should match")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffFreeswitchAgentJsonCfg(t *testing.T) {
|
||||
var d *FreeswitchAgentJsonCfg
|
||||
|
||||
v1 := &FsAgentCfg{
|
||||
Enabled: false,
|
||||
SessionSConns: []string{},
|
||||
SubscribePark: false,
|
||||
CreateCdr: false,
|
||||
ExtraFields: RSRParsers{
|
||||
{
|
||||
Rules: "ExtraField",
|
||||
},
|
||||
},
|
||||
LowBalanceAnnFile: "LBAF",
|
||||
EmptyBalanceContext: "EBC",
|
||||
EmptyBalanceAnnFile: "EBAF",
|
||||
MaxWaitConnection: 5 * time.Second,
|
||||
EventSocketConns: []*FsConnCfg{},
|
||||
}
|
||||
|
||||
v2 := &FsAgentCfg{
|
||||
Enabled: true,
|
||||
SessionSConns: []string{"*localhost"},
|
||||
SubscribePark: true,
|
||||
CreateCdr: true,
|
||||
ExtraFields: RSRParsers{
|
||||
{
|
||||
Rules: "ExtraField2",
|
||||
},
|
||||
},
|
||||
LowBalanceAnnFile: "LBAF2",
|
||||
EmptyBalanceContext: "EBC2",
|
||||
EmptyBalanceAnnFile: "EBAF2",
|
||||
MaxWaitConnection: 3 * time.Second,
|
||||
EventSocketConns: []*FsConnCfg{
|
||||
{
|
||||
Address: "localhost:8080",
|
||||
Password: "FsPassword",
|
||||
Reconnects: 3,
|
||||
Alias: "FS",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expected := &FreeswitchAgentJsonCfg{
|
||||
Enabled: utils.BoolPointer(true),
|
||||
Sessions_conns: &[]string{"*localhost"},
|
||||
Subscribe_park: utils.BoolPointer(true),
|
||||
Create_cdr: utils.BoolPointer(true),
|
||||
Extra_fields: &[]string{"ExtraField2"},
|
||||
Low_balance_ann_file: utils.StringPointer("LBAF2"),
|
||||
Empty_balance_context: utils.StringPointer("EBC2"),
|
||||
Empty_balance_ann_file: utils.StringPointer("EBAF2"),
|
||||
Max_wait_connection: utils.StringPointer("3s"),
|
||||
Event_socket_conns: &[]*FsConnJsonCfg{
|
||||
{
|
||||
Address: utils.StringPointer("localhost:8080"),
|
||||
Password: utils.StringPointer("FsPassword"),
|
||||
Reconnects: utils.IntPointer(3),
|
||||
Alias: utils.StringPointer("FS"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
rcv := diffFreeswitchAgentJsonCfg(d, 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 = &FreeswitchAgentJsonCfg{}
|
||||
|
||||
rcv = diffFreeswitchAgentJsonCfg(d, v1, v2)
|
||||
if !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionSCfgClone(t *testing.T) {
|
||||
ban := &SessionSCfg{
|
||||
Enabled: true,
|
||||
|
||||
Reference in New Issue
Block a user