From fceb0688eb3fea4001e7539a06d9e1523d31c483 Mon Sep 17 00:00:00 2001 From: andronache98 Date: Mon, 10 Jan 2022 17:18:59 +0200 Subject: [PATCH] Added tests for dynamicdp --- engine/dynamicdp_test.go | 87 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/engine/dynamicdp_test.go b/engine/dynamicdp_test.go index c98cbe436..2ded4b91b 100644 --- a/engine/dynamicdp_test.go +++ b/engine/dynamicdp_test.go @@ -23,6 +23,7 @@ import ( "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" + "github.com/nyaruka/phonenumbers" ) func TestDynamicDPnewDynamicDP(t *testing.T) { @@ -133,3 +134,89 @@ func TestDynamicDPFieldAsInterface(t *testing.T) { utils.ToJSON(exp), utils.ToJSON(result)) } } + +func TestLibphonenumberDPString(t *testing.T) { + var pInt int32 + pInt = 2 + LDP := &libphonenumberDP{ + pNumber: &phonenumbers.PhoneNumber{ + CountryCode: &pInt, + }, + } + exp2 := "country_code:2 " + rcv2 := LDP.String() + if !reflect.DeepEqual(rcv2, exp2) { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", + utils.ToJSON(exp2), utils.ToJSON(rcv2)) + } +} + +func TestLibphonenumberDPFieldAsString(t *testing.T) { + var pInt int32 + pInt = 2 + LDP := &libphonenumberDP{ + pNumber: &phonenumbers.PhoneNumber{ + CountryCode: &pInt, + }, + cache: utils.MapStorage{ + "testField": "testValue", + }, + } + exp2 := "testValue" + rcv2, err := LDP.FieldAsString([]string{"testField"}) + if err != nil { + t.Error(err) + } + if !reflect.DeepEqual(rcv2, exp2) { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", + utils.ToJSON(exp2), utils.ToJSON(rcv2)) + } +} + +func TestLibphonenumberDPFieldAsStringError(t *testing.T) { + var pInt int32 + pInt = 2 + LDP := &libphonenumberDP{ + pNumber: &phonenumbers.PhoneNumber{ + CountryCode: &pInt, + }, + cache: utils.MapStorage{ + "testField": "testValue", + }, + } + _, err := LDP.FieldAsString([]string{"testField", "testField2"}) + if err == nil || err.Error() != "WRONG_PATH" { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", + "WRONG_PATH", err) + } +} + +func TestLibphonenumberDPFieldAsInterfaceLen0(t *testing.T) { + var pInt int32 + pInt = 2 + LDP := &libphonenumberDP{ + pNumber: &phonenumbers.PhoneNumber{ + CountryCode: &pInt, + }, + cache: utils.MapStorage{ + "testField": "testValue", + }, + } + exp2 := &libphonenumberDP{ + pNumber: &phonenumbers.PhoneNumber{ + CountryCode: &pInt, + }, + cache: utils.MapStorage{ + "testField": "testValue", + }} + exp2.setDefaultFields() + + rcv2, err := LDP.FieldAsInterface([]string{}) + if err != nil { + t.Error(err) + } + if !reflect.DeepEqual(rcv2, exp2.cache) { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", + exp2.cache, rcv2) + } +}