mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add coverage tests for suretaxcfg.go, thresholdscfg.go and xmldp.go
This commit is contained in:
committed by
Dan Christian Bogos
parent
b5dbb31163
commit
0a7ab55836
@@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -177,3 +179,225 @@ func TestSureTaxCfgAsMapInterface(t *testing.T) {
|
||||
t.Errorf("\nExpected: %+v\nReceived: %+v", utils.ToJSON(eMap), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSureTaxCFGLoadFromJsonCFG(t *testing.T) {
|
||||
|
||||
str := "test`"
|
||||
|
||||
st := SureTaxCfg{}
|
||||
|
||||
stjCT := SureTaxJsonCfg{
|
||||
Client_tracking: &str,
|
||||
}
|
||||
|
||||
stjCN := SureTaxJsonCfg{
|
||||
Customer_number: &str,
|
||||
}
|
||||
|
||||
stjON := SureTaxJsonCfg{
|
||||
Orig_number: &str,
|
||||
}
|
||||
|
||||
stjTN := SureTaxJsonCfg{
|
||||
Term_number: &str,
|
||||
}
|
||||
|
||||
stjBTN := SureTaxJsonCfg{
|
||||
Bill_to_number: &str,
|
||||
}
|
||||
|
||||
stjZ := SureTaxJsonCfg{
|
||||
Zipcode: &str,
|
||||
}
|
||||
|
||||
stjPP4 := SureTaxJsonCfg{
|
||||
P2PPlus4: &str,
|
||||
}
|
||||
|
||||
stjU := SureTaxJsonCfg{
|
||||
Units: &str,
|
||||
}
|
||||
|
||||
stjUT := SureTaxJsonCfg{
|
||||
Unit_type: &str,
|
||||
}
|
||||
|
||||
stjTI := SureTaxJsonCfg{
|
||||
Tax_included: &str,
|
||||
}
|
||||
|
||||
stjTSR := SureTaxJsonCfg{
|
||||
Tax_situs_rule: &str,
|
||||
}
|
||||
|
||||
stjTTC := SureTaxJsonCfg{
|
||||
Trans_type_code: &str,
|
||||
}
|
||||
|
||||
stjSTC := SureTaxJsonCfg{
|
||||
Sales_type_code: &str,
|
||||
}
|
||||
|
||||
stjTECL := SureTaxJsonCfg{
|
||||
Tax_exemption_code_list: &str,
|
||||
}
|
||||
|
||||
stjPPZ := SureTaxJsonCfg{
|
||||
P2PZipcode: &str,
|
||||
}
|
||||
|
||||
stjP4 := SureTaxJsonCfg{
|
||||
Plus4: &str,
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
arg *SureTaxJsonCfg
|
||||
}{
|
||||
{
|
||||
arg: &stjCT,
|
||||
},
|
||||
{
|
||||
arg: &stjCN,
|
||||
},
|
||||
{
|
||||
arg: &stjON,
|
||||
},
|
||||
{
|
||||
arg: &stjTN,
|
||||
},
|
||||
{
|
||||
arg: &stjBTN,
|
||||
},
|
||||
{
|
||||
arg: &stjZ,
|
||||
},
|
||||
{
|
||||
arg: &stjPP4,
|
||||
},
|
||||
{
|
||||
arg: &stjU,
|
||||
},
|
||||
{
|
||||
arg: &stjUT,
|
||||
},
|
||||
{
|
||||
arg: &stjTI,
|
||||
},
|
||||
{
|
||||
arg: &stjTSR,
|
||||
},
|
||||
{
|
||||
arg: &stjTTC,
|
||||
},
|
||||
{
|
||||
arg: &stjSTC,
|
||||
},
|
||||
{
|
||||
arg: &stjTECL,
|
||||
},
|
||||
{
|
||||
arg: &stjPPZ,
|
||||
},
|
||||
{
|
||||
arg: &stjP4,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run("check errors", func(t *testing.T) {
|
||||
err := st.loadFromJsonCfg(tt.arg)
|
||||
exp := fmt.Errorf("Unclosed unspilit syntax")
|
||||
|
||||
if err.Error() != exp.Error() {
|
||||
t.Fatalf("recived %s, expected %s", err, exp)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("check timezone error", func(t *testing.T) {
|
||||
str := "\\test"
|
||||
|
||||
st := SureTaxCfg{}
|
||||
|
||||
stjT := SureTaxJsonCfg{
|
||||
Timezone: &str,
|
||||
}
|
||||
|
||||
err := st.loadFromJsonCfg(&stjT)
|
||||
exp := errors.New("time: invalid location name")
|
||||
|
||||
if err.Error() != exp.Error() {
|
||||
t.Fatalf("recived %s, expected %s", err, exp)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestSureTaxCFGAsMapInterface(t *testing.T) {
|
||||
str := "test"
|
||||
rsr, _ := NewRSRParsers(str, true, "")
|
||||
|
||||
st := SureTaxCfg{
|
||||
Url: str,
|
||||
ClientNumber: str,
|
||||
ValidationKey: str,
|
||||
BusinessUnit: str,
|
||||
Timezone: &time.Location{},
|
||||
IncludeLocalCost: false,
|
||||
ReturnFileCode: str,
|
||||
ResponseGroup: str,
|
||||
ResponseType: str,
|
||||
RegulatoryCode: str,
|
||||
ClientTracking: rsr,
|
||||
CustomerNumber: rsr,
|
||||
OrigNumber: rsr,
|
||||
TermNumber: rsr,
|
||||
BillToNumber: rsr,
|
||||
Zipcode: rsr,
|
||||
Plus4: rsr,
|
||||
P2PZipcode: rsr,
|
||||
P2PPlus4: rsr,
|
||||
Units: rsr,
|
||||
UnitType: rsr,
|
||||
TaxIncluded: rsr,
|
||||
TaxSitusRule: rsr,
|
||||
TransTypeCode: rsr,
|
||||
SalesTypeCode: rsr,
|
||||
TaxExemptionCodeList: rsr,
|
||||
}
|
||||
|
||||
mp := map[string]any{
|
||||
utils.UrlCfg: st.Url,
|
||||
utils.ClientNumberCfg: st.ClientNumber,
|
||||
utils.ValidationKeyCfg: st.ValidationKey,
|
||||
utils.BusinessUnitCfg: st.BusinessUnit,
|
||||
utils.TimezoneCfg: st.Timezone.String(),
|
||||
utils.IncludeLocalCostCfg: st.IncludeLocalCost,
|
||||
utils.ReturnFileCodeCfg: st.ReturnFileCode,
|
||||
utils.ResponseGroupCfg: st.ResponseGroup,
|
||||
utils.ResponseTypeCfg: st.ResponseType,
|
||||
utils.RegulatoryCodeCfg: st.RegulatoryCode,
|
||||
utils.ClientTrackingCfg: str,
|
||||
utils.CustomerNumberCfg: str,
|
||||
utils.OrigNumberCfg: str,
|
||||
utils.TermNumberCfg: str,
|
||||
utils.BillToNumberCfg: str,
|
||||
utils.ZipcodeCfg: str,
|
||||
utils.Plus4Cfg: str,
|
||||
utils.P2PZipcodeCfg: str,
|
||||
utils.P2PPlus4Cfg: str,
|
||||
utils.UnitsCfg: str,
|
||||
utils.UnitTypeCfg: str,
|
||||
utils.TaxIncludedCfg: str,
|
||||
utils.TaxSitusRuleCfg: str,
|
||||
utils.TransTypeCodeCfg: str,
|
||||
utils.SalesTypeCodeCfg: str,
|
||||
utils.TaxExemptionCodeListCfg: str,
|
||||
}
|
||||
|
||||
rcv := st.AsMapInterface("")
|
||||
|
||||
if !reflect.DeepEqual(rcv, mp) {
|
||||
t.Errorf("recived %v, expected %v", rcv, mp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -118,3 +119,20 @@ func TestThresholdSCfgAsMapInterface(t *testing.T) {
|
||||
t.Errorf("\nExpected: %+v\nReceived: %+v", utils.ToJSON(eMap), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestThresholdCFGLoadFromJsonCFG(t *testing.T) {
|
||||
str := "test"
|
||||
|
||||
to := ThresholdSCfg{}
|
||||
|
||||
toj := ThresholdSJsonCfg{
|
||||
Store_interval: &str,
|
||||
}
|
||||
|
||||
err := to.loadFromJsonCfg(&toj)
|
||||
exp := fmt.Errorf(`time: invalid duration "test"`)
|
||||
|
||||
if err.Error() != exp.Error() {
|
||||
t.Fatalf("recived %s, expected %s", err, exp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -436,3 +438,92 @@ func TestXMLIndexes(t *testing.T) {
|
||||
t.Errorf("expecting: 37, received: <%s>", data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestXmlProviderString(t *testing.T) {
|
||||
x := XmlProvider{}
|
||||
|
||||
rcv := x.String()
|
||||
exp := utils.ToJSON(x)
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("recived %v, expected %v", rcv, exp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestXmlProviderRemoteHost(t *testing.T) {
|
||||
x := XmlProvider{}
|
||||
|
||||
rcv := x.RemoteHost()
|
||||
exp := utils.LocalAddr()
|
||||
|
||||
if rcv.String() != exp.String() {
|
||||
t.Errorf("recived %v, expected %v", rcv, exp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestXmlProviderFieldAsInterface(t *testing.T) {
|
||||
|
||||
x := XmlProvider{
|
||||
cache: utils.MapStorage{"test": "val1"},
|
||||
}
|
||||
|
||||
type exp struct {
|
||||
data any
|
||||
err error
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
arg []string
|
||||
exp exp
|
||||
}{
|
||||
{
|
||||
name: "check error not found",
|
||||
arg: []string{},
|
||||
exp: exp{data: nil, err: utils.ErrNotFound},
|
||||
},
|
||||
{
|
||||
name: "item found in cache",
|
||||
arg: []string{"test"},
|
||||
exp: exp{data: "val1", err: nil},
|
||||
},
|
||||
{
|
||||
name: "check error filter rule needs to end in ]",
|
||||
arg: []string{"test[0"},
|
||||
exp: exp{data: nil, err: fmt.Errorf("filter rule <[0> needs to end in ]")},
|
||||
},
|
||||
{
|
||||
name: "check strconv.Atoi error",
|
||||
arg: []string{"test[a]"},
|
||||
exp: exp{data: nil, err: fmt.Errorf(`strconv.Atoi: parsing "a": invalid syntax`)},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
rcv, err := x.FieldAsInterface(tt.arg)
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != tt.exp.err.Error() {
|
||||
t.Fatalf("recived %s, expected %s", err, tt.exp.err)
|
||||
}
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(rcv, tt.exp.data) {
|
||||
t.Errorf("recived %s, expected %s", rcv, tt.exp.data)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestXmlProviderFieldAsString(t *testing.T) {
|
||||
x := XmlProvider{}
|
||||
|
||||
_, err := x.FieldAsString([]string{})
|
||||
exp := utils.ErrNotFound
|
||||
|
||||
if err.Error() != exp.Error() {
|
||||
t.Fatalf("recived %d, expected %s", err, exp)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user