mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated load tests for httpagentcfg
This commit is contained in:
committed by
Dan Christian Bogos
parent
6df506e11a
commit
72fe2ee14d
@@ -26,136 +26,156 @@ import (
|
||||
)
|
||||
|
||||
func TestHttpAgentCfgsloadFromJsonCfg(t *testing.T) {
|
||||
var httpcfg, expected HttpAgentCfgs
|
||||
if err := httpcfg.loadFromJsonCfg(nil, utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(httpcfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, httpcfg)
|
||||
}
|
||||
if err := httpcfg.loadFromJsonCfg(new([]*HttpAgentJsonCfg), utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(httpcfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, httpcfg)
|
||||
}
|
||||
cfgJSONStr := `{
|
||||
"http_agent": [
|
||||
{
|
||||
"id": "conecto1",
|
||||
"url": "/conecto",
|
||||
"sessions_conns": ["*localhost"],
|
||||
"request_payload": "*url",
|
||||
"reply_payload": "*xml",
|
||||
"request_processors": [
|
||||
{
|
||||
"id": "OutboundAUTHDryRun",
|
||||
"filters": ["*string:*req.request_type:OutboundAUTH","*string:*req.Msisdn:497700056231"],
|
||||
"tenant": "cgrates.org",
|
||||
"flags": ["*dryrun"],
|
||||
"request_fields":[
|
||||
],
|
||||
"reply_fields":[
|
||||
{"tag": "Allow", "path": "response.Allow", "type": "*constant",
|
||||
"value": "1", "mandatory": true},
|
||||
],
|
||||
cfgJSON := &[]*HttpAgentJsonCfg{
|
||||
{
|
||||
Id: utils.StringPointer("RandomID"),
|
||||
Url: utils.StringPointer("/randomURL"),
|
||||
Sessions_conns: &[]string{"*internal"},
|
||||
Reply_payload: utils.StringPointer(utils.MetaXml),
|
||||
Request_payload: utils.StringPointer(utils.MetaUrl),
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{
|
||||
{
|
||||
ID: utils.StringPointer("OutboundAUTHDryRun"),
|
||||
Filters: &[]string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: utils.StringPointer("cgrates.org"),
|
||||
Flags: &[]string{utils.MetaDryRun},
|
||||
Request_fields: &[]*FcTemplateJsonCfg{},
|
||||
Reply_fields: &[]*FcTemplateJsonCfg{
|
||||
{
|
||||
Tag: utils.StringPointer("Allow"),
|
||||
Path: utils.StringPointer("response.Allow"),
|
||||
Type: utils.StringPointer(utils.META_CONSTANT),
|
||||
Value: utils.StringPointer("1"),
|
||||
Mandatory: utils.BoolPointer(true),
|
||||
Layout: utils.StringPointer("2006-01-02T15:04:05Z07:00"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}`
|
||||
expected = HttpAgentCfgs{&HttpAgentCfg{
|
||||
ID: "conecto1",
|
||||
Url: "/conecto",
|
||||
SessionSConns: []string{utils.MetaLocalHost},
|
||||
RequestPayload: "*url",
|
||||
ReplyPayload: "*xml",
|
||||
RequestProcessors: []*RequestProcessor{{
|
||||
ID: "OutboundAUTHDryRun",
|
||||
Filters: []string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", utils.INFIELD_SEP),
|
||||
Flags: utils.FlagsWithParams{"*dryrun": {}},
|
||||
RequestFields: []*FCTemplate{},
|
||||
ReplyFields: []*FCTemplate{{
|
||||
Tag: "Allow",
|
||||
Path: "response.Allow",
|
||||
Type: "*constant",
|
||||
Value: NewRSRParsersMustCompile("1", utils.INFIELD_SEP),
|
||||
Mandatory: true,
|
||||
Layout: time.RFC3339,
|
||||
},
|
||||
}
|
||||
expected := HttpAgentCfgs{
|
||||
{
|
||||
ID: "RandomID",
|
||||
Url: "/randomURL",
|
||||
SessionSConns: []string{"*internal:*sessions"},
|
||||
RequestPayload: "*url",
|
||||
ReplyPayload: "*xml",
|
||||
RequestProcessors: []*RequestProcessor{{
|
||||
ID: "OutboundAUTHDryRun",
|
||||
Filters: []string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", utils.INFIELD_SEP),
|
||||
Flags: utils.FlagsWithParams{utils.MetaDryRun: {}},
|
||||
RequestFields: []*FCTemplate{},
|
||||
ReplyFields: []*FCTemplate{{
|
||||
Tag: "Allow",
|
||||
Path: "response.Allow",
|
||||
Type: "*constant",
|
||||
Value: NewRSRParsersMustCompile("1", utils.INFIELD_SEP),
|
||||
Mandatory: true,
|
||||
Layout: time.RFC3339,
|
||||
}},
|
||||
}},
|
||||
}},
|
||||
}}
|
||||
expected[0].RequestProcessors[0].ReplyFields[0].ComputePath()
|
||||
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnhttpCfg, err := jsnCfg.HttpAgentJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = httpcfg.loadFromJsonCfg(jsnhttpCfg, utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, httpcfg) {
|
||||
t.Errorf("Expected: %+v , recived: %+v", utils.ToJSON(expected), utils.ToJSON(httpcfg))
|
||||
},
|
||||
}
|
||||
cfgJSONStr = `{
|
||||
"http_agent": [
|
||||
{
|
||||
"id": "conecto1",
|
||||
"url": "/conecto",
|
||||
"sessions_conns": ["*localhost"],
|
||||
"request_payload": "*url",
|
||||
"reply_payload": "*xml",
|
||||
"request_processors": [
|
||||
{
|
||||
"id": "mtcall_cdr",
|
||||
"filters": ["*string:*req.request_type:MTCALL_CDR"],
|
||||
"tenant": "cgrates.org",
|
||||
"flags": ["*cdrs"],
|
||||
"request_fields":[
|
||||
{"tag": "RequestType", "path": "RequestType", "type": "*constant",
|
||||
"value": "*pseudoprepaid", "mandatory": true},
|
||||
],
|
||||
"reply_fields":[
|
||||
{"tag": "CDR_ID", "path": "CDR_RESPONSE.CDR_ID", "type": "*composed",
|
||||
"value": "~*req.CDR_ID", "mandatory": true},
|
||||
],
|
||||
|
||||
expected[0].RequestProcessors[0].ReplyFields[0].ComputePath()
|
||||
if jsnCfg, err := NewDefaultCGRConfig(); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = jsnCfg.httpAgentCfg.loadFromJsonCfg(cfgJSON, jsnCfg.generalCfg.RSRSep); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(&expected, &jsnCfg.httpAgentCfg) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(jsnCfg.httpAgentCfg))
|
||||
}
|
||||
}
|
||||
|
||||
func TestHttpAgentCfgsloadFromJsonCfg1(t *testing.T) {
|
||||
cfgJSON := &[]*HttpAgentJsonCfg{
|
||||
{
|
||||
Id: utils.StringPointer("conecto1"),
|
||||
Url: utils.StringPointer("/conecto"),
|
||||
Sessions_conns: &[]string{utils.MetaLocalHost},
|
||||
Request_payload: utils.StringPointer(utils.MetaUrl),
|
||||
Reply_payload: utils.StringPointer(utils.MetaXml),
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{
|
||||
{
|
||||
ID: utils.StringPointer("OutboundAUTHDryRun"),
|
||||
Filters: &[]string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: utils.StringPointer("cgrates.org"),
|
||||
Flags: &[]string{utils.MetaDryRun},
|
||||
Request_fields: &[]*FcTemplateJsonCfg{},
|
||||
Reply_fields: &[]*FcTemplateJsonCfg{
|
||||
{
|
||||
Tag: utils.StringPointer("Allow"),
|
||||
Path: utils.StringPointer("response.Allow"),
|
||||
Type: utils.StringPointer(utils.META_CONSTANT),
|
||||
Value: utils.StringPointer("1"),
|
||||
Mandatory: utils.BoolPointer(true),
|
||||
Layout: utils.StringPointer("2006-01-02T15:04:05Z07:00"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: utils.StringPointer("mtcall_cdr"),
|
||||
Filters: &[]string{"*string:*req.request_type:MTCALL_CDR"},
|
||||
Tenant: utils.StringPointer("cgrates.org"),
|
||||
Flags: &[]string{utils.MetaCDRs},
|
||||
Request_fields: &[]*FcTemplateJsonCfg{
|
||||
{
|
||||
Tag: utils.StringPointer("RequestType"),
|
||||
Path: utils.StringPointer("RequestType"),
|
||||
Type: utils.StringPointer(utils.META_CONSTANT),
|
||||
Value: utils.StringPointer("*pseudoprepaid"),
|
||||
Mandatory: utils.BoolPointer(true),
|
||||
Layout: utils.StringPointer("2006-01-02T15:04:05Z07:00"),
|
||||
},
|
||||
},
|
||||
Reply_fields: &[]*FcTemplateJsonCfg{
|
||||
{
|
||||
Tag: utils.StringPointer("CDR_ID"),
|
||||
Path: utils.StringPointer("CDR_RESPONSE.CDR_ID"),
|
||||
Type: utils.StringPointer(utils.META_COMPOSED),
|
||||
Value: utils.StringPointer("~*req.CDR_ID"),
|
||||
Mandatory: utils.BoolPointer(true),
|
||||
Layout: utils.StringPointer("2006-01-02T15:04:05Z07:00"),
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
{
|
||||
Id: utils.StringPointer("conecto_xml"),
|
||||
Url: utils.StringPointer("/conecto_xml"),
|
||||
Sessions_conns: &[]string{utils.MetaLocalHost},
|
||||
Request_payload: utils.StringPointer("*xml"),
|
||||
Reply_payload: utils.StringPointer("*xml"),
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{
|
||||
{
|
||||
ID: utils.StringPointer("cdr_from_xml"),
|
||||
Tenant: utils.StringPointer("cgrates.org"),
|
||||
Flags: &[]string{utils.MetaCDRs},
|
||||
Request_fields: &[]*FcTemplateJsonCfg{},
|
||||
Reply_fields: &[]*FcTemplateJsonCfg{},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"id": "conecto_xml",
|
||||
"url": "/conecto_xml",
|
||||
"sessions_conns": ["*localhost"],
|
||||
"request_payload": "*xml",
|
||||
"reply_payload": "*xml",
|
||||
"request_processors": [
|
||||
{
|
||||
"id": "cdr_from_xml",
|
||||
"tenant": "cgrates.org",
|
||||
"flags": ["*cdrs"],
|
||||
"request_fields":[],
|
||||
"reply_fields":[],
|
||||
}
|
||||
],
|
||||
},
|
||||
],
|
||||
}`
|
||||
expected = HttpAgentCfgs{
|
||||
},
|
||||
}
|
||||
expected := HttpAgentCfgs{
|
||||
&HttpAgentCfg{
|
||||
ID: "conecto1",
|
||||
Url: "/conecto",
|
||||
SessionSConns: []string{utils.MetaLocalHost},
|
||||
RequestPayload: "*url",
|
||||
ReplyPayload: "*xml",
|
||||
RequestPayload: utils.MetaUrl,
|
||||
ReplyPayload: utils.MetaXml,
|
||||
RequestProcessors: []*RequestProcessor{
|
||||
{
|
||||
ID: "OutboundAUTHDryRun",
|
||||
Filters: []string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", utils.INFIELD_SEP),
|
||||
Flags: utils.FlagsWithParams{"*dryrun": {}},
|
||||
Flags: utils.FlagsWithParams{utils.MetaDryRun: {}},
|
||||
RequestFields: []*FCTemplate{},
|
||||
ReplyFields: []*FCTemplate{{
|
||||
Tag: "Allow",
|
||||
Path: "response.Allow",
|
||||
Type: "*constant",
|
||||
Type: utils.META_CONSTANT,
|
||||
Value: NewRSRParsersMustCompile("1", utils.INFIELD_SEP),
|
||||
Mandatory: true,
|
||||
Layout: time.RFC3339,
|
||||
@@ -165,11 +185,11 @@ func TestHttpAgentCfgsloadFromJsonCfg(t *testing.T) {
|
||||
ID: "mtcall_cdr",
|
||||
Filters: []string{"*string:*req.request_type:MTCALL_CDR"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", utils.INFIELD_SEP),
|
||||
Flags: utils.FlagsWithParams{"*cdrs": {}},
|
||||
Flags: utils.FlagsWithParams{utils.MetaCDRs: {}},
|
||||
RequestFields: []*FCTemplate{{
|
||||
Tag: "RequestType",
|
||||
Path: "RequestType",
|
||||
Type: "*constant",
|
||||
Type: utils.META_CONSTANT,
|
||||
Value: NewRSRParsersMustCompile("*pseudoprepaid", utils.INFIELD_SEP),
|
||||
Mandatory: true,
|
||||
Layout: time.RFC3339,
|
||||
@@ -177,7 +197,7 @@ func TestHttpAgentCfgsloadFromJsonCfg(t *testing.T) {
|
||||
ReplyFields: []*FCTemplate{{
|
||||
Tag: "CDR_ID",
|
||||
Path: "CDR_RESPONSE.CDR_ID",
|
||||
Type: "*composed",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: NewRSRParsersMustCompile("~*req.CDR_ID", utils.INFIELD_SEP),
|
||||
Mandatory: true,
|
||||
Layout: time.RFC3339,
|
||||
@@ -187,12 +207,12 @@ func TestHttpAgentCfgsloadFromJsonCfg(t *testing.T) {
|
||||
ID: "conecto_xml",
|
||||
Url: "/conecto_xml",
|
||||
SessionSConns: []string{utils.MetaLocalHost},
|
||||
RequestPayload: "*xml",
|
||||
ReplyPayload: "*xml",
|
||||
RequestPayload: utils.MetaXml,
|
||||
ReplyPayload: utils.MetaXml,
|
||||
RequestProcessors: []*RequestProcessor{{
|
||||
ID: "cdr_from_xml",
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", utils.INFIELD_SEP),
|
||||
Flags: utils.FlagsWithParams{"*cdrs": {}},
|
||||
Flags: utils.FlagsWithParams{utils.MetaCDRs: {}},
|
||||
RequestFields: []*FCTemplate{},
|
||||
ReplyFields: []*FCTemplate{},
|
||||
}},
|
||||
@@ -200,30 +220,16 @@ func TestHttpAgentCfgsloadFromJsonCfg(t *testing.T) {
|
||||
expected[0].RequestProcessors[0].ReplyFields[0].ComputePath()
|
||||
expected[0].RequestProcessors[1].ReplyFields[0].ComputePath()
|
||||
expected[0].RequestProcessors[1].RequestFields[0].ComputePath()
|
||||
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
|
||||
if cfgJsn, err := NewDefaultCGRConfig(); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnhttpCfg, err := jsnCfg.HttpAgentJsonCfg(); err != nil {
|
||||
} else if err = cfgJsn.httpAgentCfg.loadFromJsonCfg(cfgJSON, cfgJsn.generalCfg.RSRSep); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = httpcfg.loadFromJsonCfg(jsnhttpCfg, utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, httpcfg) {
|
||||
t.Errorf("Expected: %+v , recived: %+v", utils.ToJSON(expected), utils.ToJSON(httpcfg))
|
||||
} else if !reflect.DeepEqual(expected, cfgJsn.httpAgentCfg) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(cfgJsn.httpAgentCfg))
|
||||
}
|
||||
}
|
||||
|
||||
func TestHttpAgentCfgloadFromJsonCfg(t *testing.T) {
|
||||
var httpcfg, expected HttpAgentCfg
|
||||
if err := httpcfg.loadFromJsonCfg(nil, utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(httpcfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, httpcfg)
|
||||
}
|
||||
if err := httpcfg.loadFromJsonCfg(new(HttpAgentJsonCfg), utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(httpcfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, httpcfg)
|
||||
}
|
||||
|
||||
jsnhttpCfg := &HttpAgentJsonCfg{
|
||||
Id: utils.StringPointer("conecto1"),
|
||||
Url: utils.StringPointer("/conecto"),
|
||||
@@ -241,7 +247,7 @@ func TestHttpAgentCfgloadFromJsonCfg(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
expected = HttpAgentCfg{
|
||||
expected := HttpAgentCfg{
|
||||
ID: "conecto1",
|
||||
Url: "/conecto",
|
||||
SessionSConns: []string{utils.MetaLocalHost},
|
||||
@@ -256,11 +262,11 @@ func TestHttpAgentCfgloadFromJsonCfg(t *testing.T) {
|
||||
ReplyFields: []*FCTemplate{},
|
||||
}},
|
||||
}
|
||||
|
||||
var httpcfg HttpAgentCfg
|
||||
if err = httpcfg.loadFromJsonCfg(jsnhttpCfg, utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, httpcfg) {
|
||||
t.Errorf("Expected: %+v , recived: %+v", utils.ToJSON(expected), utils.ToJSON(httpcfg))
|
||||
t.Errorf("Expected: %+v \n, recived: %+v", utils.ToJSON(expected), utils.ToJSON(httpcfg))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,7 +368,6 @@ func TestHttpAgentCfgappendHttpAgntProcCfgs(t *testing.T) {
|
||||
|
||||
func TestHttpAgentCfgAsMapInterface(t *testing.T) {
|
||||
cfgJSONStr := `{
|
||||
|
||||
"http_agent": [
|
||||
{
|
||||
"id": "conecto1",
|
||||
|
||||
Reference in New Issue
Block a user