mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated unit tests
This commit is contained in:
committed by
Dan Christian Bogos
parent
13e813f848
commit
52e1ec1df2
@@ -38,6 +38,9 @@ func TestCdreCfgClone(t *testing.T) {
|
||||
Path: "runid",
|
||||
Value: runIDRsrs},
|
||||
}
|
||||
for _, v := range initContentFlds {
|
||||
v.ComputePath()
|
||||
}
|
||||
initCdreCfg := &CdreCfg{
|
||||
ExportFormat: utils.MetaFileCSV,
|
||||
ExportPath: "/var/spool/cgrates/cdre",
|
||||
@@ -56,6 +59,9 @@ func TestCdreCfgClone(t *testing.T) {
|
||||
Path: "runid",
|
||||
Value: runIDRsrs},
|
||||
}
|
||||
for _, v := range eClnContentFlds {
|
||||
v.ComputePath()
|
||||
}
|
||||
eClnCdreCfg := &CdreCfg{
|
||||
ExportFormat: utils.MetaFileCSV,
|
||||
ExportPath: "/var/spool/cgrates/cdre",
|
||||
@@ -127,6 +133,7 @@ func TestCdreCfgloadFromJsonCfg(t *testing.T) {
|
||||
Layout: time.RFC3339,
|
||||
}},
|
||||
}
|
||||
expected.Fields[0].ComputePath()
|
||||
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnCdreCfg, err := jsnCfg.CdreJsonCfgs(); err != nil {
|
||||
|
||||
@@ -563,6 +563,9 @@ func TestCgrCfgJSONDefaultsCdreProfiles(t *testing.T) {
|
||||
RoundingDecimals: utils.IntPointer(4),
|
||||
},
|
||||
}
|
||||
for _, v := range eContentFlds {
|
||||
v.ComputePath()
|
||||
}
|
||||
eCdreCfg := map[string]*CdreCfg{
|
||||
utils.MetaDefault: {
|
||||
ExportFormat: utils.MetaFileCSV,
|
||||
@@ -1597,6 +1600,13 @@ func TestCgrLoaderCfgITDefaults(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, profile := range eCfg {
|
||||
for _, fields := range profile.Data {
|
||||
for _, v := range fields.Fields {
|
||||
v.ComputePath()
|
||||
}
|
||||
}
|
||||
}
|
||||
if !reflect.DeepEqual(eCfg, cgrCfg.loaderCfg) {
|
||||
t.Errorf("received: %+v, \n expecting: %+v",
|
||||
utils.ToJSON(eCfg), utils.ToJSON(cgrCfg.loaderCfg))
|
||||
@@ -1829,6 +1839,11 @@ func TestCgrCdfEventReader(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, profile := range eCfg.Readers {
|
||||
for _, v := range profile.Fields {
|
||||
v.ComputePath()
|
||||
}
|
||||
}
|
||||
if !reflect.DeepEqual(cgrCfg.ersCfg, eCfg) {
|
||||
t.Errorf("received: %+v,\n expecting: %+v", utils.ToJSON(cgrCfg.ersCfg), utils.ToJSON(eCfg))
|
||||
}
|
||||
@@ -1961,6 +1976,11 @@ func TestCgrCdfEventExporter(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, profile := range eCfg.Exporters {
|
||||
for _, v := range profile.Fields {
|
||||
v.ComputePath()
|
||||
}
|
||||
}
|
||||
if !reflect.DeepEqual(cgrCfg.eesCfg, eCfg) {
|
||||
t.Errorf("received: %+v,\n expecting: %+v", utils.ToJSON(cgrCfg.eesCfg), utils.ToJSON(eCfg))
|
||||
}
|
||||
@@ -2006,6 +2026,9 @@ func TestCgrCfgEventReaderDefault(t *testing.T) {
|
||||
},
|
||||
CacheDumpFields: make([]*FCTemplate, 0),
|
||||
}
|
||||
for _, v := range eCfg.Fields {
|
||||
v.ComputePath()
|
||||
}
|
||||
if !reflect.DeepEqual(cgrCfg.dfltEvRdr, eCfg) {
|
||||
t.Errorf("received: %+v,\n expecting: %+v", utils.ToJSON(cgrCfg.dfltEvRdr), utils.ToJSON(eCfg))
|
||||
}
|
||||
@@ -2125,6 +2148,9 @@ func TestCgrCfgEventExporterDefault(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, v := range eCfg.Fields {
|
||||
v.ComputePath()
|
||||
}
|
||||
if !reflect.DeepEqual(cgrCfg.dfltEvExp, eCfg) {
|
||||
t.Errorf("received: %+v,\n expecting: %+v", utils.ToJSON(cgrCfg.dfltEvExp), utils.ToJSON(eCfg))
|
||||
}
|
||||
|
||||
@@ -50,6 +50,9 @@ func TestEventExporterClone(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, v := range orig.Fields {
|
||||
v.ComputePath()
|
||||
}
|
||||
cloned := orig.Clone()
|
||||
if !reflect.DeepEqual(cloned, orig) {
|
||||
t.Errorf("expected: %s \n,received: %s", utils.ToJSON(orig), utils.ToJSON(cloned))
|
||||
@@ -77,6 +80,9 @@ func TestEventExporterClone(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, v := range initialOrig.Fields {
|
||||
v.ComputePath()
|
||||
}
|
||||
orig.Filters = []string{"SingleFilter"}
|
||||
orig.Fields = []*FCTemplate{
|
||||
{
|
||||
@@ -234,7 +240,11 @@ func TestEventExporterSameID(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, profile := range expectedEEsCfg.Exporters {
|
||||
for _, v := range profile.Fields {
|
||||
v.ComputePath()
|
||||
}
|
||||
}
|
||||
cfgJSONStr := `{
|
||||
"ees": {
|
||||
"enabled": true,
|
||||
|
||||
@@ -50,6 +50,9 @@ func TestEventRedearClone(t *testing.T) {
|
||||
},
|
||||
CacheDumpFields: make([]*FCTemplate, 0),
|
||||
}
|
||||
for _, v := range orig.Fields {
|
||||
v.ComputePath()
|
||||
}
|
||||
cloned := orig.Clone()
|
||||
if !reflect.DeepEqual(cloned, orig) {
|
||||
t.Errorf("expected: %s \n,received: %s", utils.ToJSON(orig), utils.ToJSON(cloned))
|
||||
@@ -78,6 +81,9 @@ func TestEventRedearClone(t *testing.T) {
|
||||
},
|
||||
CacheDumpFields: make([]*FCTemplate, 0),
|
||||
}
|
||||
for _, v := range initialOrig.Fields {
|
||||
v.ComputePath()
|
||||
}
|
||||
orig.Filters = []string{"SingleFilter"}
|
||||
orig.Fields = []*FCTemplate{
|
||||
{
|
||||
@@ -178,7 +184,11 @@ func TestEventReaderLoadFromJSON(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, profile := range expectedERsCfg.Readers {
|
||||
for _, v := range profile.Fields {
|
||||
v.ComputePath()
|
||||
}
|
||||
}
|
||||
cfgJSONStr := `{
|
||||
"ers": {
|
||||
"enabled": true,
|
||||
@@ -291,7 +301,11 @@ func TestEventReaderSameID(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, profile := range expectedERsCfg.Readers {
|
||||
for _, v := range profile.Fields {
|
||||
v.ComputePath()
|
||||
}
|
||||
}
|
||||
cfgJSONStr := `{
|
||||
"ers": {
|
||||
"enabled": true,
|
||||
|
||||
@@ -41,6 +41,7 @@ func TestNewFCTemplateFromFCTemplateJsonCfg(t *testing.T) {
|
||||
Value: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
Layout: time.RFC3339,
|
||||
}
|
||||
expected.ComputePath()
|
||||
if rcv, err := NewFCTemplateFromFCTemplateJsonCfg(jsonCfg, utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, rcv) {
|
||||
@@ -83,6 +84,9 @@ func TestFCTemplatesFromFCTemplatesJsonCfg(t *testing.T) {
|
||||
Layout: time.RFC3339,
|
||||
},
|
||||
}
|
||||
for _, v := range expected {
|
||||
v.ComputePath()
|
||||
}
|
||||
if rcv, err := FCTemplatesFromFCTemplatesJsonCfg(jsnCfgs, utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, rcv) {
|
||||
@@ -288,6 +292,14 @@ func TestFCTemplateInflate3(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, v := range fcTmp1 {
|
||||
v.ComputePath()
|
||||
}
|
||||
for _, tmpl := range fcTmpMp {
|
||||
for _, v := range tmpl {
|
||||
v.ComputePath()
|
||||
}
|
||||
}
|
||||
if _, err := InflateTemplates(fcTmp1, fcTmpMp); err == nil ||
|
||||
err.Error() != "empty template with id: <TmpMap>" {
|
||||
t.Error(err)
|
||||
@@ -302,6 +314,7 @@ func TestFCTemplateClone(t *testing.T) {
|
||||
Filters: []string{"Filter1", "Filter2"},
|
||||
Value: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
}
|
||||
smpl.ComputePath()
|
||||
cloned := smpl.Clone()
|
||||
if !reflect.DeepEqual(cloned, smpl) {
|
||||
t.Errorf("expected: %s ,received: %s", utils.ToJSON(smpl), utils.ToJSON(cloned))
|
||||
@@ -313,6 +326,7 @@ func TestFCTemplateClone(t *testing.T) {
|
||||
Filters: []string{"Filter1", "Filter2"},
|
||||
Value: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
}
|
||||
initialSmpl.ComputePath()
|
||||
smpl.Filters = []string{"SingleFilter"}
|
||||
smpl.Value = NewRSRParsersMustCompile("cgrates.com", true, utils.INFIELD_SEP)
|
||||
if !reflect.DeepEqual(cloned, initialSmpl) {
|
||||
|
||||
@@ -84,6 +84,7 @@ func TestHttpAgentCfgsloadFromJsonCfg(t *testing.T) {
|
||||
}},
|
||||
}},
|
||||
}}
|
||||
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 {
|
||||
@@ -144,20 +145,22 @@ func TestHttpAgentCfgsloadFromJsonCfg(t *testing.T) {
|
||||
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", true, utils.INFIELD_SEP),
|
||||
Flags: utils.FlagsWithParams{"*dryrun": []string{}},
|
||||
RequestFields: []*FCTemplate{},
|
||||
ReplyFields: []*FCTemplate{{
|
||||
Tag: "Allow",
|
||||
Path: "response.Allow",
|
||||
Type: "*constant",
|
||||
Value: NewRSRParsersMustCompile("1", true, utils.INFIELD_SEP),
|
||||
Mandatory: true,
|
||||
Layout: time.RFC3339,
|
||||
}}},
|
||||
RequestProcessors: []*RequestProcessor{
|
||||
{
|
||||
ID: "OutboundAUTHDryRun",
|
||||
Filters: []string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
Flags: utils.FlagsWithParams{"*dryrun": []string{}},
|
||||
RequestFields: []*FCTemplate{},
|
||||
ReplyFields: []*FCTemplate{{
|
||||
Tag: "Allow",
|
||||
Path: "response.Allow",
|
||||
Type: "*constant",
|
||||
Value: NewRSRParsersMustCompile("1", true, utils.INFIELD_SEP),
|
||||
Mandatory: true,
|
||||
Layout: time.RFC3339,
|
||||
}},
|
||||
},
|
||||
{
|
||||
ID: "mtcall_cdr",
|
||||
Filters: []string{"*string:*req.request_type:MTCALL_CDR"},
|
||||
@@ -194,6 +197,9 @@ func TestHttpAgentCfgsloadFromJsonCfg(t *testing.T) {
|
||||
ReplyFields: []*FCTemplate{},
|
||||
}},
|
||||
}}
|
||||
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 {
|
||||
t.Error(err)
|
||||
} else if jsnhttpCfg, err := jsnCfg.HttpAgentJsonCfg(); err != nil {
|
||||
@@ -280,6 +286,7 @@ func TestHttpAgentCfgappendHttpAgntProcCfgs(t *testing.T) {
|
||||
}},
|
||||
}},
|
||||
}
|
||||
initial.RequestProcessors[0].ReplyFields[0].ComputePath()
|
||||
proceses := &[]*ReqProcessorJsnCfg{{
|
||||
ID: utils.StringPointer("OutboundAUTHDryRun1"),
|
||||
Filters: &[]string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
@@ -344,7 +351,8 @@ func TestHttpAgentCfgappendHttpAgntProcCfgs(t *testing.T) {
|
||||
}},
|
||||
}},
|
||||
}
|
||||
|
||||
expected.RequestProcessors[0].ReplyFields[0].ComputePath()
|
||||
expected.RequestProcessors[1].ReplyFields[0].ComputePath()
|
||||
if err = initial.appendHttpAgntProcCfgs(proceses, utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, initial) {
|
||||
|
||||
@@ -85,6 +85,8 @@ func TestLoaderSCfgloadFromJsonCfg(t *testing.T) {
|
||||
{
|
||||
Tag: "TenantID",
|
||||
Path: "Tenant",
|
||||
pathSlice: []string{"Tenant"},
|
||||
pathItems: utils.PathItems{{Field: "Tenant"}},
|
||||
Type: "*composed",
|
||||
Value: val,
|
||||
Mandatory: true,
|
||||
|
||||
@@ -69,44 +69,42 @@ func TestDPDynamicString(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAppendNavMapVal(t *testing.T) {
|
||||
onm := NewOrderedNavigableMap()
|
||||
nm := NavigableMap2{
|
||||
"Field1": NewNMData("1001"),
|
||||
"Field2": NewNMData("1003"),
|
||||
"Field3": NavigableMap2{"Field4": NewNMData("Val")},
|
||||
"Field5": &NMSlice{NewNMData(10), NewNMData(101)},
|
||||
}
|
||||
onm.nm = nm
|
||||
expected := NavigableMap2{
|
||||
"Field1": NewNMData("1001"),
|
||||
"Field2": NewNMData("1003"),
|
||||
"Field3": NavigableMap2{"Field4": NewNMData("Val")},
|
||||
"Field5": &NMSlice{NewNMData(10), NewNMData(101), NewNMData(18)},
|
||||
}
|
||||
if err := AppendNavMapVal(nm, PathItems{{Field: "Field5"}}, NewNMData(18)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, nm) {
|
||||
t.Errorf("Expected %v ,received: %v", expected, nm)
|
||||
}
|
||||
if err := AppendNavMapVal(nm, nil, NewNMData(18)); err != ErrWrongPath {
|
||||
if err := AppendNavMapVal(onm, &FullPath{Path: "Field5", PathItems: PathItems{{Field: "Field5"}}}, NewNMData(18)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, onm.nm) {
|
||||
t.Errorf("Expected %v ,received: %v", expected, onm.nm)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComposeNavMapVal(t *testing.T) {
|
||||
onm := NewOrderedNavigableMap()
|
||||
nm := NavigableMap2{
|
||||
"Field4": &NMSlice{},
|
||||
"Field5": &NMSlice{NewNMData(10), NewNMData(101)},
|
||||
}
|
||||
if err := ComposeNavMapVal(nm, nil, NewNMData(18)); err != ErrWrongPath {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := ComposeNavMapVal(nm, PathItems{{Field: "Field4"}}, NewNMData(18)); err != ErrWrongPath {
|
||||
onm.nm = nm
|
||||
if err := ComposeNavMapVal(onm, &FullPath{Path: "Field4", PathItems: PathItems{{Field: "Field4"}}}, NewNMData(18)); err != ErrWrongPath {
|
||||
t.Error(err)
|
||||
}
|
||||
expected := NavigableMap2{
|
||||
"Field4": &NMSlice{},
|
||||
"Field5": &NMSlice{NewNMData(10), NewNMData("10118")},
|
||||
}
|
||||
if err := ComposeNavMapVal(nm, PathItems{{Field: "Field5"}}, NewNMData(18)); err != nil {
|
||||
if err := ComposeNavMapVal(onm, &FullPath{Path: "Field5", PathItems: PathItems{{Field: "Field5"}}}, NewNMData(18)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, nm) {
|
||||
t.Errorf("Expected %v ,received: %v", expected, nm)
|
||||
@@ -117,7 +115,7 @@ func TestComposeNavMapVal(t *testing.T) {
|
||||
"Field5": &NMSlice{NewNMData(10), NewNMData("10118")},
|
||||
"Field6": &NMSlice{NewNMData(10)},
|
||||
}
|
||||
if err := ComposeNavMapVal(nm, PathItems{{Field: "Field6"}}, NewNMData(10)); err != nil {
|
||||
if err := ComposeNavMapVal(onm, &FullPath{Path: "Field6", PathItems: PathItems{{Field: "Field6"}}}, NewNMData(10)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, nm) {
|
||||
t.Errorf("Expected %v ,received: %v", expected, nm)
|
||||
@@ -127,11 +125,11 @@ func TestComposeNavMapVal(t *testing.T) {
|
||||
"Field4": NewNMData(1),
|
||||
"Field5": &NMSlice{NewNMData(10), NewNMData(101)},
|
||||
}
|
||||
if err := ComposeNavMapVal(nm, PathItems{{Field: "Field4"}}, NewNMData(10)); err != ErrNotImplemented {
|
||||
if err := ComposeNavMapVal(onm, &FullPath{Path: "Field4", PathItems: PathItems{{Field: "Field4"}}}, NewNMData(10)); err != ErrWrongPath {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err := ComposeNavMapVal(nm, PathItems{{Field: "Field5"}}, &mockNMInterface{data: 10}); err != ErrNotImplemented {
|
||||
if err := ComposeNavMapVal(onm, &FullPath{Path: "Field5", PathItems: PathItems{{Field: "Field5"}}}, &mockNMInterface{data: 10}); err != ErrNotImplemented {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,17 +91,10 @@ func (onm *OrderedNavigableMap) Remove(fullPath *FullPath) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// // Set sets the value at the given path
|
||||
// // this is the old to be capable of building the code without updating all the code
|
||||
// // will be replaced with Set2 after we decide that is the optimal solution
|
||||
// func (onm *OrderedNavigableMap) Set(fldPath PathItems, val NMInterface) (addedNew bool, err error) {
|
||||
// return onm.Set2(&FullPath{PathItems: fldPath, Path: fldPath.String()}, val)
|
||||
// }
|
||||
|
||||
// Set sets the value at the given path
|
||||
// this used with full path and the processed path to not calculate them for every set
|
||||
func (onm *OrderedNavigableMap) Set(fullPath *FullPath, val NMInterface) (addedNew bool, err error) {
|
||||
if len(fullPath.PathItems) == 0 {
|
||||
if fullPath == nil || len(fullPath.PathItems) == 0 {
|
||||
return false, ErrWrongPath
|
||||
}
|
||||
if addedNew, err = onm.nm.Set(fullPath.PathItems, val); err != nil {
|
||||
|
||||
@@ -26,7 +26,10 @@ import (
|
||||
func TestOrderedNavigableMap(t *testing.T) {
|
||||
onm := NewOrderedNavigableMap()
|
||||
|
||||
onm.Set(PathItems{{Field: "Field1"}}, NewNMData(10))
|
||||
onm.Set(&FullPath{
|
||||
Path: "Field1",
|
||||
PathItems: PathItems{{Field: "Field1"}},
|
||||
}, NewNMData(10))
|
||||
expOrder := []PathItems{
|
||||
PathItems{{Field: "Field1"}},
|
||||
}
|
||||
@@ -34,9 +37,10 @@ func TestOrderedNavigableMap(t *testing.T) {
|
||||
t.Errorf("Expected %s ,received: %s", expOrder, ToJSON(onm.GetOrder()))
|
||||
}
|
||||
|
||||
onm.Set(
|
||||
PathItems{{Field: "Field2", Index: IntPointer(0)}},
|
||||
NewNMData("1001"))
|
||||
onm.Set(&FullPath{
|
||||
Path: "Field2[0]",
|
||||
PathItems: PathItems{{Field: "Field2", Index: IntPointer(0)}},
|
||||
}, NewNMData("1001"))
|
||||
expOrder = []PathItems{
|
||||
PathItems{{Field: "Field1"}},
|
||||
PathItems{{Field: "Field2", Index: IntPointer(0)}},
|
||||
@@ -45,11 +49,12 @@ func TestOrderedNavigableMap(t *testing.T) {
|
||||
t.Errorf("Expected %s ,received: %s", expOrder, ToJSON(onm.GetOrder()))
|
||||
}
|
||||
|
||||
onm.Set(
|
||||
PathItems{
|
||||
onm.Set(&FullPath{
|
||||
Path: "Field2[1].Account[0]",
|
||||
PathItems: PathItems{
|
||||
{Field: "Field2", Index: IntPointer(1)},
|
||||
{Field: "Account", Index: IntPointer(0)}},
|
||||
NewNMData(10))
|
||||
}, NewNMData(10))
|
||||
expOrder = []PathItems{
|
||||
PathItems{{Field: "Field1"}},
|
||||
PathItems{{Field: "Field2", Index: IntPointer(0)}},
|
||||
@@ -61,11 +66,12 @@ func TestOrderedNavigableMap(t *testing.T) {
|
||||
t.Errorf("Expected %s ,received: %s", expOrder, ToJSON(onm.GetOrder()))
|
||||
}
|
||||
|
||||
onm.Set(
|
||||
PathItems{
|
||||
onm.Set(&FullPath{
|
||||
Path: "Field2[1].Account[1]",
|
||||
PathItems: PathItems{
|
||||
{Field: "Field2", Index: IntPointer(1)},
|
||||
{Field: "Account", Index: IntPointer(1)}},
|
||||
NewNMData(11))
|
||||
}, NewNMData(11))
|
||||
expOrder = []PathItems{
|
||||
PathItems{{Field: "Field1"}},
|
||||
PathItems{{Field: "Field2", Index: IntPointer(0)}},
|
||||
@@ -80,9 +86,10 @@ func TestOrderedNavigableMap(t *testing.T) {
|
||||
t.Errorf("Expected %s ,received: %s", expOrder, ToJSON(onm.GetOrder()))
|
||||
}
|
||||
|
||||
onm.Set(
|
||||
PathItems{{Field: "Field2", Index: IntPointer(2)}},
|
||||
NewNMData(111))
|
||||
onm.Set(&FullPath{
|
||||
Path: "Field2[2]",
|
||||
PathItems: PathItems{{Field: "Field2", Index: IntPointer(2)}},
|
||||
}, NewNMData(111))
|
||||
expOrder = []PathItems{
|
||||
PathItems{{Field: "Field1"}},
|
||||
PathItems{{Field: "Field2", Index: IntPointer(0)}},
|
||||
@@ -98,12 +105,13 @@ func TestOrderedNavigableMap(t *testing.T) {
|
||||
t.Errorf("Expected %s ,received: %s", expOrder, ToJSON(onm.GetOrder()))
|
||||
}
|
||||
|
||||
onm.Set(
|
||||
PathItems{
|
||||
onm.Set(&FullPath{
|
||||
Path: "Field3.Field4.Field5",
|
||||
PathItems: PathItems{
|
||||
{Field: "Field3"},
|
||||
{Field: "Field4"},
|
||||
{Field: "Field5"}},
|
||||
NewNMData(5))
|
||||
}, NewNMData(5))
|
||||
expOrder = []PathItems{
|
||||
PathItems{{Field: "Field1"}},
|
||||
PathItems{{Field: "Field2", Index: IntPointer(0)}},
|
||||
@@ -151,7 +159,7 @@ func TestOrderedNavigableMap(t *testing.T) {
|
||||
// sliceDeNM
|
||||
exp := &NMSlice{NewNMData("500"), NewNMData("502")}
|
||||
path := PathItems{{Field: "Field2"}}
|
||||
if _, err := onm.Set(path, exp); err != nil {
|
||||
if _, err := onm.Set(&FullPath{Path: path.String(), PathItems: path}, exp); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
path = PathItems{{Field: "Field2"}}
|
||||
@@ -290,11 +298,11 @@ func TestOrderedNavigableMapLen(t *testing.T) {
|
||||
|
||||
func TestOrderedNavigableMapGetSet(t *testing.T) {
|
||||
nm := NewOrderedNavigableMap()
|
||||
nm.Set2(&FullPath{
|
||||
nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Account", Index: IntPointer(0)}},
|
||||
Path: "Account",
|
||||
}, NewNMData(1001))
|
||||
nm.Set2(&FullPath{
|
||||
nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Account", Index: IntPointer(1)}},
|
||||
Path: "Account",
|
||||
}, NewNMData("account_on_new_branch"))
|
||||
@@ -340,7 +348,7 @@ func TestOrderedNavigableMapGetSet(t *testing.T) {
|
||||
}
|
||||
|
||||
path = PathItems{{Field: "Field2", Index: IntPointer(2)}}
|
||||
if _, err := nm.Set(path, NewNMData("500")); err != nil {
|
||||
if _, err := nm.Set(&FullPath{Path: path.String(), PathItems: path}, NewNMData("500")); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if val, err := nm.Field(path); err != nil {
|
||||
@@ -350,7 +358,7 @@ func TestOrderedNavigableMapGetSet(t *testing.T) {
|
||||
}
|
||||
|
||||
path = PathItems{{Field: "Field2", Index: IntPointer(1)}, {Field: "Account"}}
|
||||
if _, err := nm.Set(path, NewNMData("5")); err != nil {
|
||||
if _, err := nm.Set(&FullPath{Path: path.String(), PathItems: path}, NewNMData("5")); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
path = PathItems{{Field: "Field2", Index: IntPointer(1)}, {Field: "Account"}}
|
||||
@@ -415,10 +423,22 @@ func TestOrderedNavigableMapFieldAsString(t *testing.T) {
|
||||
|
||||
func TestOrderedNavigableMapGetOrder(t *testing.T) {
|
||||
nm := NewOrderedNavigableMap()
|
||||
nm.Set(PathItems{{Field: "Field1"}, {Field: "Field2", Index: IntPointer(0)}}, NewNMData("1003"))
|
||||
nm.Set(PathItems{{Field: "Field1"}, {Field: "Field2", Index: IntPointer(1)}}, NewNMData("Val"))
|
||||
nm.Set(PathItems{{Field: "Field3"}, {Field: "Field4"}, {Field: "Field5", Index: IntPointer(0)}}, NewNMData("1001"))
|
||||
nm.Set(PathItems{{Field: "Field1"}, {Field: "Field2", Index: IntPointer(2)}}, NewNMData(101))
|
||||
nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Field1"}, {Field: "Field2", Index: IntPointer(0)}},
|
||||
Path: "Field1.Field2[0]",
|
||||
}, NewNMData("1003"))
|
||||
nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Field1"}, {Field: "Field2", Index: IntPointer(1)}},
|
||||
Path: "Field1.Field2[1]",
|
||||
}, NewNMData("Val"))
|
||||
nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Field3"}, {Field: "Field4"}, {Field: "Field5", Index: IntPointer(0)}},
|
||||
Path: "Field3.Field4.Field5",
|
||||
}, NewNMData("1001"))
|
||||
nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Field1"}, {Field: "Field2", Index: IntPointer(2)}},
|
||||
Path: "Field1.Field2[2]",
|
||||
}, NewNMData(101))
|
||||
expected := []PathItems{
|
||||
{{Field: "Field1"}, {Field: "Field2", Index: IntPointer(0)}},
|
||||
{{Field: "Field1"}, {Field: "Field2", Index: IntPointer(1)}},
|
||||
@@ -437,14 +457,23 @@ func TestOrderedNavigableMapSet(t *testing.T) {
|
||||
if _, err := nm.Set(nil, nil); err != ErrWrongPath {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := nm.Set(PathItems{{Field: "Field1", Index: IntPointer(10)}}, NewNMData("1001")); err != ErrWrongPath {
|
||||
if _, err := nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Field1", Index: IntPointer(10)}},
|
||||
Path: "Field1[10]",
|
||||
}, NewNMData("1001")); err != ErrWrongPath {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := nm.Set(PathItems{{Field: "Field1", Index: IntPointer(10)}, {Field: "Field2"}}, NewNMData("1001")); err != ErrWrongPath {
|
||||
if _, err := nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Field1", Index: IntPointer(10)}, {Field: "Field2"}},
|
||||
Path: "Field1[10].Field2",
|
||||
}, NewNMData("1001")); err != ErrWrongPath {
|
||||
t.Error(err)
|
||||
}
|
||||
path := PathItems{{Field: "Field1", Index: IntPointer(0)}}
|
||||
if addedNew, err := nm.Set(path, NewNMData("1001")); err != nil {
|
||||
if addedNew, err := nm.Set(&FullPath{
|
||||
PathItems: path,
|
||||
Path: path.String(),
|
||||
}, NewNMData("1001")); err != nil {
|
||||
t.Error(err)
|
||||
} else if !addedNew {
|
||||
t.Error("Expected the field to be added new")
|
||||
@@ -457,23 +486,38 @@ func TestOrderedNavigableMapSet(t *testing.T) {
|
||||
if !reflect.DeepEqual(nm.GetOrder(), order) {
|
||||
t.Errorf("Expected %s ,received: %s", order, nm.GetOrder())
|
||||
}
|
||||
if _, err := nm.Set(PathItems{{Field: "Field1", Index: IntPointer(0)}, {}}, NewNMData("1001")); err != ErrWrongPath {
|
||||
if _, err := nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Field1", Index: IntPointer(0)}, {}},
|
||||
Path: "Field1[0]",
|
||||
}, NewNMData("1001")); err != ErrWrongPath {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := nm.Set(PathItems{{Field: "Field1", Index: IntPointer(10)}}, NewNMData("1001")); err != ErrWrongPath {
|
||||
if _, err := nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Field1", Index: IntPointer(10)}},
|
||||
Path: "Field1[10]",
|
||||
}, NewNMData("1001")); err != ErrWrongPath {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if _, err := nm.Set(PathItems{{Field: "Field1", Index: IntPointer(0)}, {}}, &NMSlice{}); err != ErrWrongPath {
|
||||
if _, err := nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Field1", Index: IntPointer(0)}, {}},
|
||||
Path: "Field1[0]",
|
||||
}, &NMSlice{}); err != ErrWrongPath {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := nm.Set(PathItems{{Field: "Field1", Index: IntPointer(10)}}, &NMSlice{}); err != ErrWrongPath {
|
||||
if _, err := nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Field1", Index: IntPointer(10)}},
|
||||
Path: "Field[10]",
|
||||
}, &NMSlice{}); err != ErrWrongPath {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
nMap = NavigableMap2{"Field1": &NMSlice{NewNMData("1002")}}
|
||||
order = []PathItems{path}
|
||||
if addedNew, err := nm.Set(path, NewNMData("1002")); err != nil {
|
||||
if addedNew, err := nm.Set(&FullPath{
|
||||
PathItems: path,
|
||||
Path: path.String(),
|
||||
}, NewNMData("1002")); err != nil {
|
||||
t.Error(err)
|
||||
} else if addedNew {
|
||||
t.Error("Expected the field to be only updated")
|
||||
@@ -490,7 +534,10 @@ func TestOrderedNavigableMapSet(t *testing.T) {
|
||||
"Field2": NewNMData("1002"),
|
||||
}
|
||||
order = append(order, path)
|
||||
if addedNew, err := nm.Set(path, NewNMData("1002")); err != nil {
|
||||
if addedNew, err := nm.Set(&FullPath{
|
||||
PathItems: path,
|
||||
Path: path.String(),
|
||||
}, NewNMData("1002")); err != nil {
|
||||
t.Error(err)
|
||||
} else if !addedNew {
|
||||
t.Error("Expected the field to be added new")
|
||||
@@ -507,7 +554,10 @@ func TestOrderedNavigableMapSet(t *testing.T) {
|
||||
"Field2": NewNMData("1002"),
|
||||
}
|
||||
order = append(order, path)
|
||||
if addedNew, err := nm.Set(path, NewNMData("1003")); err != nil {
|
||||
if addedNew, err := nm.Set(&FullPath{
|
||||
PathItems: path,
|
||||
Path: path.String(),
|
||||
}, NewNMData("1003")); err != nil {
|
||||
t.Error(err)
|
||||
} else if !addedNew {
|
||||
t.Error("Expected the field to be added new")
|
||||
@@ -526,7 +576,10 @@ func TestOrderedNavigableMapSet(t *testing.T) {
|
||||
"Field3": obj,
|
||||
}
|
||||
order = append(order, PathItems{{Field: "Field3", Index: IntPointer(0)}}, PathItems{{Field: "Field3", Index: IntPointer(1)}})
|
||||
if addedNew, err := nm.Set(path, obj); err != nil {
|
||||
if addedNew, err := nm.Set(&FullPath{
|
||||
PathItems: path,
|
||||
Path: path.String(),
|
||||
}, obj); err != nil {
|
||||
t.Error(err)
|
||||
} else if !addedNew {
|
||||
t.Error("Expected the field to be added new")
|
||||
@@ -550,7 +603,10 @@ func TestOrderedNavigableMapSet(t *testing.T) {
|
||||
{{Field: "Field1", Index: IntPointer(0)}},
|
||||
{{Field: "Field1", Index: IntPointer(1)}},
|
||||
}
|
||||
if addedNew, err := nm.Set(PathItems{{Field: "Field1"}}, obj); err != nil {
|
||||
if addedNew, err := nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Field1"}},
|
||||
Path: "Field1",
|
||||
}, obj); err != nil {
|
||||
t.Error(err)
|
||||
} else if addedNew {
|
||||
t.Error("Expected the field to be only updated")
|
||||
@@ -574,7 +630,10 @@ func TestOrderedNavigableMapSet(t *testing.T) {
|
||||
{{Field: "Field1", Index: IntPointer(1)}},
|
||||
{{Field: "Field3", Index: IntPointer(1)}},
|
||||
}
|
||||
if addedNew, err := nm.Set(PathItems{{Field: "Field3", Index: IntPointer(-1)}}, NewNMData("1007")); err != nil {
|
||||
if addedNew, err := nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Field3", Index: IntPointer(-1)}},
|
||||
Path: "Field3[-1]",
|
||||
}, NewNMData("1007")); err != nil {
|
||||
t.Error(err)
|
||||
} else if addedNew {
|
||||
t.Error("Expected the field to be only updated")
|
||||
@@ -589,21 +648,33 @@ func TestOrderedNavigableMapSet(t *testing.T) {
|
||||
|
||||
func TestOrderedNavigableMapRemove(t *testing.T) {
|
||||
nm := NewOrderedNavigableMap()
|
||||
nm.Set(PathItems{{Field: "Field2"}}, NewNMData("1003"))
|
||||
nm.Set(PathItems{{Field: "Field3"}, {Field: "Field4"}}, NewNMData("Val"))
|
||||
nm.Set(PathItems{{Field: "Field1"}}, NewNMData("1001"))
|
||||
nm.Set(PathItems{{Field: "Field5"}}, &NMSlice{NewNMData(10), NewNMData(101)})
|
||||
if err := nm.Remove(FullPath{}); err != ErrWrongPath {
|
||||
nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Field2"}},
|
||||
Path: "Field2",
|
||||
}, NewNMData("1003"))
|
||||
nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Field3"}, {Field: "Field4"}},
|
||||
Path: "Field3.Field4",
|
||||
}, NewNMData("Val"))
|
||||
nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Field1"}},
|
||||
Path: "Field1",
|
||||
}, NewNMData("1001"))
|
||||
nm.Set(&FullPath{
|
||||
PathItems: PathItems{{Field: "Field5"}},
|
||||
Path: "Field5",
|
||||
}, &NMSlice{NewNMData(10), NewNMData(101)})
|
||||
if err := nm.Remove(&FullPath{}); err != ErrWrongPath {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := nm.Remove(FullPath{PathItems: PathItems{}}); err != ErrWrongPath {
|
||||
if err := nm.Remove(&FullPath{PathItems: PathItems{}}); err != ErrWrongPath {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := nm.Remove(FullPath{PathItems: PathItems{{Field: "field"}}, Path: "field"}); err != nil {
|
||||
if err := nm.Remove(&FullPath{PathItems: PathItems{{Field: "field"}}, Path: "field"}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err := nm.Remove(FullPath{PathItems: PathItems{{Index: IntPointer(-1)}, {}}}); err != ErrWrongPath {
|
||||
if err := nm.Remove(&FullPath{PathItems: PathItems{{Index: IntPointer(-1)}, {}}}); err != ErrWrongPath {
|
||||
t.Error(err)
|
||||
}
|
||||
nMap := NavigableMap2{
|
||||
@@ -637,7 +708,7 @@ func TestOrderedNavigableMapRemove(t *testing.T) {
|
||||
{{Field: "Field5", Index: IntPointer(1)}},
|
||||
}
|
||||
|
||||
if err := nm.Remove(FullPath{PathItems: PathItems{{Field: "Field2"}}, Path: "Field2"}); err != nil {
|
||||
if err := nm.Remove(&FullPath{PathItems: PathItems{{Field: "Field2"}}, Path: "Field2"}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !reflect.DeepEqual(nm.nm, nMap) {
|
||||
@@ -655,7 +726,7 @@ func TestOrderedNavigableMapRemove(t *testing.T) {
|
||||
{{Field: "Field1"}},
|
||||
}
|
||||
|
||||
if err := nm.Remove(FullPath{PathItems: PathItems{{Field: "Field5"}}, Path: "Field5"}); err != nil {
|
||||
if err := nm.Remove(&FullPath{PathItems: PathItems{{Field: "Field5"}}, Path: "Field5"}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !reflect.DeepEqual(nm.nm, nMap) {
|
||||
@@ -664,7 +735,7 @@ func TestOrderedNavigableMapRemove(t *testing.T) {
|
||||
if !reflect.DeepEqual(nm.GetOrder(), order) {
|
||||
t.Errorf("Expected %s ,received: %s", order, nm.GetOrder())
|
||||
}
|
||||
if err := nm.Remove(FullPath{PathItems: PathItems{{Field: "Field1", Index: IntPointer(0)}, {}}}); err != ErrWrongPath {
|
||||
if err := nm.Remove(&FullPath{PathItems: PathItems{{Field: "Field1", Index: IntPointer(0)}, {}}}); err != ErrWrongPath {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@@ -712,7 +783,7 @@ func BenchmarkOrderdNavigableMapSet2(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
for _, data := range gen {
|
||||
if _, err := nm.Set2(&FullPath{PathItems: data.pathItems, Path: data.strPath}, NewNMData(data.data)); err != nil {
|
||||
if _, err := nm.Set(&FullPath{PathItems: data.pathItems, Path: data.strPath}, NewNMData(data.data)); err != nil {
|
||||
b.Log(err, data.path)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user