From c9036b38cdbed93e2a4ffab05bdd8b8c07b06149 Mon Sep 17 00:00:00 2001 From: nickolasdaniel Date: Wed, 8 Sep 2021 16:59:13 +0300 Subject: [PATCH] Cover tests for ees --- ees/ee_test.go | 26 ++++++++++++++++ ees/httpjsonmap_test.go | 47 +++++++++++++++++++++++++++++ ees/httppost_test.go | 67 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) diff --git a/ees/ee_test.go b/ees/ee_test.go index a51f04b5e..5a53f691d 100644 --- a/ees/ee_test.go +++ b/ees/ee_test.go @@ -18,6 +18,7 @@ along with this program. If not, see package ees import ( + "encoding/json" "fmt" "reflect" "strings" @@ -264,3 +265,28 @@ func TestDone(t *testing.T) { t.Error("Expected length of 3") } } + +func TestEEPrepareOrderMap(t *testing.T) { + bP := new(bytePreparing) + onm := utils.NewOrderedNavigableMap() + fullPath := &utils.FullPath{ + PathSlice: []string{utils.MetaReq, utils.MetaTenant}, + Path: utils.MetaTenant, + } + val := &utils.DataLeaf{ + Data: "value1", + } + onm.Append(fullPath, val) + rcv, err := bP.PrepareOrderMap(onm) + if err != nil { + t.Error(err) + } + + valMp := map[string]interface{}{ + "*req.*tenant": "value1", + } + body, err := json.Marshal(valMp) + if !reflect.DeepEqual(rcv, body) { + t.Errorf("Expected %v \n but received \n %v", utils.IfaceAsString(body), utils.IfaceAsString(rcv)) + } +} diff --git a/ees/httpjsonmap_test.go b/ees/httpjsonmap_test.go index e32f71415..f021150ca 100644 --- a/ees/httpjsonmap_test.go +++ b/ees/httpjsonmap_test.go @@ -170,3 +170,50 @@ func TestHttpJsonMapSyncLimit(t *testing.T) { return } } + +func TestHTTPJsonMapPrepareOrderMap(t *testing.T) { + httpEE := new(HTTPjsonMapEE) + onm := utils.NewOrderedNavigableMap() + fullPath := &utils.FullPath{ + PathSlice: []string{utils.MetaReq, utils.MetaTenant}, + Path: utils.MetaTenant, + } + val := &utils.DataLeaf{ + Data: "value1", + } + onm.Append(fullPath, val) + rcv, err := httpEE.PrepareOrderMap(onm) + if err != nil { + t.Error(err) + } + valMp := map[string]interface{}{ + "*req.*tenant": "value1", + } + body, err := json.Marshal(valMp) + exp := &HTTPPosterRequest{ + Header: httpEE.hdr, + Body: body, + } + if !reflect.DeepEqual(rcv, exp) { + t.Errorf("Expected %v \n but received \n %v", utils.IfaceAsString(exp), utils.IfaceAsString(rcv)) + } +} + +func TestHTTPJsonMapPrepareMap(t *testing.T) { + httpEE := new(HTTPjsonMapEE) + valMp := map[string]interface{}{ + "*req.*tenant": "value1", + } + rcv, err := httpEE.PrepareMap(valMp) + if err != nil { + t.Error(err) + } + body, err := json.Marshal(valMp) + exp := &HTTPPosterRequest{ + Header: httpEE.hdr, + Body: body, + } + if !reflect.DeepEqual(rcv, exp) { + t.Errorf("Expected %v \n but received \n %v", utils.IfaceAsString(exp), utils.IfaceAsString(rcv)) + } +} diff --git a/ees/httppost_test.go b/ees/httppost_test.go index 919667ead..27afdf781 100644 --- a/ees/httppost_test.go +++ b/ees/httppost_test.go @@ -197,3 +197,70 @@ func TestHttpPostSyncLimit(t *testing.T) { return } } + +func TestHTTPPostPrepareOrderMap(t *testing.T) { + httpPost := new(HTTPPostEE) + onm := utils.NewOrderedNavigableMap() + fullPath := &utils.FullPath{ + PathSlice: []string{utils.MetaReq, utils.MetaTenant}, + Path: utils.MetaTenant, + } + val := &utils.DataLeaf{ + Data: "value1", + } + onm.Append(fullPath, val) + rcv, err := httpPost.PrepareOrderMap(onm) + if err != nil { + t.Error(err) + } + urlVals := url.Values{ + "*req.*tenant": {"value1"}, + } + exp := &HTTPPosterRequest{ + Header: httpPost.hdr, + Body: urlVals, + } + if !reflect.DeepEqual(rcv, exp) { + t.Errorf("Expected %v \n but received \n %v", exp, rcv) + } +} + +// func TestComposeHeader(t *testing.T) { +// // cfgJSONStr := `{ +// // "ees": { +// // "enabled": true, +// // "attributes_conns":["*internal", "*conn1"], +// // "cache": { +// // "*file_csv": {"limit": -2, "ttl": "3s", "static_ttl": true}, +// // }, +// // "exporters": [ +// // { +// // "id": "cgrates", +// // "type": "*none", +// // "export_path": "/var/spool/cgrates/ees", +// // "opts": { +// // "*default": "randomVal" +// // }, +// // "timezone": "local", +// // "filters": ["randomFiletrs"], +// // "flags": [], +// // "attribute_ids": ["randomID"], +// // "attribute_context": "", +// // "synchronous": false, +// // "attempts": 2, +// // "field_separator": ",", +// // "fields":[ +// // {"tag": "CGRID", "path": "*hdr.CGRID", "type": "*variable", "value": "~*req.CGRID"}, +// // ], +// // }, +// // ], +// // }, +// // }` +// // if jsonCfg, err := config.NewCGRConfigFromJSONStringWithDefaults(cfgJSONStr); err != nil { +// // t.Error(err) +// // } +// // httpPost := &HTTPPostEE{ +// // cfg: +// // } + +// }