Add coverage tests for config

This commit is contained in:
NikolasPetriti
2023-09-04 16:46:55 +02:00
committed by Dan Christian Bogos
parent 05ede32f0f
commit 23494cd156
2 changed files with 317 additions and 0 deletions

View File

@@ -652,3 +652,55 @@ func TestFCTemplateAsMapInterface(t *testing.T) {
})
}
}
func TestFCTemplateInflateTemplatesError(t *testing.T) {
mc := utils.MultiplyConverter{
Value: 1.2,
}
nm := 1
bl := false
str := "test)"
slc := []string{str}
fcts := []*FCTemplate{{
Tag: str,
Type: utils.MetaTemplate,
Path: str,
Filters: slc,
Value: RSRParsers{{
Rules: str,
AllFiltersMatch: bl,
path: str,
converters: utils.DataConverters{&mc},
}},
Width: nm,
Strip: str,
Padding: str,
Mandatory: bl,
AttributeID: str,
NewBranch: bl,
Timezone: str,
Blocker: bl,
BreakOnSuccess: bl,
Layout: str,
CostShiftDigits: nm,
RoundingDecimals: &nm,
MaskDestID: str,
MaskLen: nm,
pathItems: utils.PathItems{},
pathSlice: slc,
}}
msgTpls := map[string][]*FCTemplate{str: fcts}
rcv, err := InflateTemplates(fcts, msgTpls)
if err != nil {
if err.Error() != `strconv.ParseFloat: parsing "": invalid syntax` {
t.Error(err)
}
} else {
t.Error("was expecting an error")
}
if rcv != nil {
t.Error(rcv)
}
}

View File

@@ -425,3 +425,268 @@ func TestHttpAgentCfgAsMapInterface(t *testing.T) {
t.Errorf("Expected: %+v,\nReceived: %+v", utils.ToJSON(eMap), utils.ToJSON(rcv))
}
}
func TestHttpAgentCfgappendHttpAgntProcCfgsError(t *testing.T) {
nm := 1
str := "test`"
bl := true
ca := HttpAgentCfg{
ID: str,
Url: str,
SessionSConns: []string{str},
RequestPayload: str,
ReplyPayload: str,
RequestProcessors: []*RequestProcessor{{
ID: str,
Tenant: RSRParsers{},
Filters: []string{str},
Flags: utils.FlagsWithParams{},
Timezone: str,
RequestFields: []*FCTemplate{},
ReplyFields: []*FCTemplate{},
}},
}
hps := &[]*ReqProcessorJsnCfg{{
ID: &str,
Filters: &[]string{str},
Tenant: &str,
Timezone: &str,
Flags: &[]string{str},
Request_fields: &[]*FcTemplateJsonCfg{{
Tag: &str,
Type: &str,
Path: &str,
Attribute_id: &str,
Filters: &[]string{str},
Value: &str,
Width: &nm,
Strip: &str,
Padding: &str,
Mandatory: &bl,
New_branch: &bl,
Timezone: &str,
Blocker: &bl,
Break_on_success: &bl,
Layout: &str,
Cost_shift_digits: &nm,
Rounding_decimals: &nm,
Mask_destinationd_id: &str,
Mask_length: &nm,
}},
Reply_fields: &[]*FcTemplateJsonCfg{{
Tag: &str,
Type: &str,
Path: &str,
Attribute_id: &str,
Filters: &[]string{str},
Value: &str,
Width: &nm,
Strip: &str,
Padding: &str,
Mandatory: &bl,
New_branch: &bl,
Timezone: &str,
Blocker: &bl,
Break_on_success: &bl,
Layout: &str,
Cost_shift_digits: &nm,
Rounding_decimals: &nm,
Mask_destinationd_id: &str,
Mask_length: &nm,
}},
}}
err := ca.appendHttpAgntProcCfgs(hps, "")
if err != nil {
if err.Error() != "Unclosed unspilit syntax" {
t.Error(err)
}
} else {
t.Error("was expecting an error")
}
}
func TestHttpAgentCfgloadFromJsonCfgError(t *testing.T) {
nm := 1
str := "test`"
bl := true
ca := HttpAgentCfg{
ID: str,
Url: str,
SessionSConns: []string{str},
RequestPayload: str,
ReplyPayload: str,
RequestProcessors: []*RequestProcessor{{
ID: str,
Tenant: RSRParsers{},
Filters: []string{str},
Flags: utils.FlagsWithParams{},
Timezone: str,
RequestFields: []*FCTemplate{},
ReplyFields: []*FCTemplate{},
}},
}
hps := &[]*ReqProcessorJsnCfg{{
ID: &str,
Filters: &[]string{str},
Tenant: &str,
Timezone: &str,
Flags: &[]string{str},
Request_fields: &[]*FcTemplateJsonCfg{{
Tag: &str,
Type: &str,
Path: &str,
Attribute_id: &str,
Filters: &[]string{str},
Value: &str,
Width: &nm,
Strip: &str,
Padding: &str,
Mandatory: &bl,
New_branch: &bl,
Timezone: &str,
Blocker: &bl,
Break_on_success: &bl,
Layout: &str,
Cost_shift_digits: &nm,
Rounding_decimals: &nm,
Mask_destinationd_id: &str,
Mask_length: &nm,
}},
Reply_fields: &[]*FcTemplateJsonCfg{{
Tag: &str,
Type: &str,
Path: &str,
Attribute_id: &str,
Filters: &[]string{str},
Value: &str,
Width: &nm,
Strip: &str,
Padding: &str,
Mandatory: &bl,
New_branch: &bl,
Timezone: &str,
Blocker: &bl,
Break_on_success: &bl,
Layout: &str,
Cost_shift_digits: &nm,
Rounding_decimals: &nm,
Mask_destinationd_id: &str,
Mask_length: &nm,
}},
}}
jsnCfg := &HttpAgentJsonCfg{
Id: &str,
Url: &str,
Sessions_conns: &[]string{str},
Request_payload: &str,
Reply_payload: &str,
Request_processors: hps,
}
err := ca.loadFromJsonCfg(jsnCfg, "")
if err != nil {
if err.Error() != "Unclosed unspilit syntax" {
t.Error(err)
}
} else {
t.Error("was expecting an error")
}
}
func TestHttpAgentCfgloadFromJsonCfgErrorSlice(t *testing.T) {
nm := 1
str := "test`"
bl := true
ca := HttpAgentCfgs{{
ID: str,
Url: str,
SessionSConns: []string{str},
RequestPayload: str,
ReplyPayload: str,
RequestProcessors: []*RequestProcessor{{
ID: str,
Tenant: RSRParsers{},
Filters: []string{str},
Flags: utils.FlagsWithParams{},
Timezone: str,
RequestFields: []*FCTemplate{},
ReplyFields: []*FCTemplate{},
}},
}}
hps := &[]*ReqProcessorJsnCfg{{
ID: &str,
Filters: &[]string{str},
Tenant: &str,
Timezone: &str,
Flags: &[]string{str},
Request_fields: &[]*FcTemplateJsonCfg{{
Tag: &str,
Type: &str,
Path: &str,
Attribute_id: &str,
Filters: &[]string{str},
Value: &str,
Width: &nm,
Strip: &str,
Padding: &str,
Mandatory: &bl,
New_branch: &bl,
Timezone: &str,
Blocker: &bl,
Break_on_success: &bl,
Layout: &str,
Cost_shift_digits: &nm,
Rounding_decimals: &nm,
Mask_destinationd_id: &str,
Mask_length: &nm,
}},
Reply_fields: &[]*FcTemplateJsonCfg{{
Tag: &str,
Type: &str,
Path: &str,
Attribute_id: &str,
Filters: &[]string{str},
Value: &str,
Width: &nm,
Strip: &str,
Padding: &str,
Mandatory: &bl,
New_branch: &bl,
Timezone: &str,
Blocker: &bl,
Break_on_success: &bl,
Layout: &str,
Cost_shift_digits: &nm,
Rounding_decimals: &nm,
Mask_destinationd_id: &str,
Mask_length: &nm,
}},
}}
jsnCfg := &HttpAgentJsonCfg{
Id: &str,
Url: &str,
Sessions_conns: &[]string{str},
Request_payload: &str,
Reply_payload: &str,
Request_processors: hps,
}
jsnHttpAgntCfg := &[]*HttpAgentJsonCfg{jsnCfg}
err := ca.loadFromJsonCfg(jsnHttpAgntCfg, "")
if err != nil {
if err.Error() != "Unclosed unspilit syntax" {
t.Error(err)
}
} else {
t.Error("was expecting an error")
}
}