Updated utils tests

This commit is contained in:
Trial97
2021-03-25 12:09:41 +02:00
committed by Dan Christian Bogos
parent 59340fd4a4
commit b8437f4a7d
25 changed files with 647 additions and 1015 deletions

View File

@@ -453,7 +453,7 @@ func TestAPAccountProfiles(t *testing.T) {
},
Weights: nil,
Balances: map[string]*Balance{
"testBalance1": &Balance{
"testBalance1": {
ID: "testBalance1",
Type: MetaAbstract,
Units: &Decimal{decimal.New(0, 0)},
@@ -474,7 +474,7 @@ func TestAPAccountProfiles(t *testing.T) {
},
Weights: nil,
Balances: map[string]*Balance{
"testBalance2": &Balance{
"testBalance2": {
ID: "testBalance2",
Type: MetaAbstract,
Units: &Decimal{decimal.New(0, 0)},
@@ -510,7 +510,7 @@ func TestAPLockIDs(t *testing.T) {
},
Weights: nil,
Balances: map[string]*Balance{
"testBalance1": &Balance{
"testBalance1": {
ID: "testBalance1",
Type: MetaAbstract,
Units: &Decimal{decimal.New(0, 0)},
@@ -531,7 +531,7 @@ func TestAPLockIDs(t *testing.T) {
},
Weights: nil,
Balances: map[string]*Balance{
"testBalance2": &Balance{
"testBalance2": {
ID: "testBalance2",
Type: MetaAbstract,
Units: &Decimal{decimal.New(0, 0)},
@@ -567,7 +567,7 @@ func TestAPTenantIDs(t *testing.T) {
},
Weights: nil,
Balances: map[string]*Balance{
"testBalance1": &Balance{
"testBalance1": {
ID: "testBalance1",
Type: MetaAbstract,
Units: &Decimal{decimal.New(0, 0)},
@@ -588,7 +588,7 @@ func TestAPTenantIDs(t *testing.T) {
},
Weights: nil,
Balances: map[string]*Balance{
"testBalance2": &Balance{
"testBalance2": {
ID: "testBalance2",
Type: MetaAbstract,
Units: &Decimal{decimal.New(0, 0)},

View File

@@ -69,12 +69,7 @@ func (pgnt *Paginator) PaginateStringSlice(in []string) (out []string) {
if limit == 0 || limit > len(in) {
limit = len(in)
}
ret := in[offset:limit]
out = make([]string, len(ret))
for i, itm := range ret {
out[i] = itm
}
return
return CloneStringSlice(in[offset:limit])
}
// Clone creates a clone of the object
@@ -647,8 +642,8 @@ func (fltr *CDRsFilter) Prepare() {
// sort.Strings(fltr.DestinationPrefixes)
// sort.Strings(fltr.NotDestinationPrefixes)
sort.Sort(sort.Float64Slice(fltr.Costs))
sort.Sort(sort.Float64Slice(fltr.NotCosts))
sort.Float64s(fltr.Costs)
sort.Float64s(fltr.NotCosts)
}

View File

@@ -111,7 +111,7 @@ func TestNewRateSlot(t *testing.T) {
t.Errorf("Expected: %+v ,received: %+v ", eOut, rcv)
}
eOut.RateUnit = "a"
rcv, err = NewRateSlot(eOut.ConnectFee, eOut.Rate, eOut.RateUnit, eOut.RateIncrement, eOut.GroupIntervalStart)
_, err = NewRateSlot(eOut.ConnectFee, eOut.Rate, eOut.RateUnit, eOut.RateIncrement, eOut.GroupIntervalStart)
//must receive from time an error: "invalid duration a"
if err == nil || err.Error() != "time: invalid duration \"a\"" {
t.Error(err)
@@ -409,20 +409,20 @@ func TestAttrGetCdrsAsCDRsFilter(t *testing.T) {
t.Errorf("Nil struct expected")
}
//check with wrong time-zone
rcv, err = attrGetCdrs.AsCDRsFilter("wrongtimezone")
_, err = attrGetCdrs.AsCDRsFilter("wrongtimezone")
if err == nil {
t.Errorf("ParseTimeDetectLayout error")
}
//check with wrong TimeStart
attrGetCdrs.TimeStart = "wrongtimeStart"
rcv, err = attrGetCdrs.AsCDRsFilter("")
_, err = attrGetCdrs.AsCDRsFilter("")
if err == nil {
t.Errorf("Wrong AnswerTimeStart not processed")
}
//check with wrong TimeEnd
attrGetCdrs.TimeStart = "2020-04-04T11:45:26.371Z"
attrGetCdrs.TimeEnd = "wrongtimeEnd"
rcv, err = attrGetCdrs.AsCDRsFilter("")
_, err = attrGetCdrs.AsCDRsFilter("")
if err == nil {
t.Errorf("Wrong AnswerTimeEnd not processed")
}
@@ -482,7 +482,7 @@ func TestNewTAFromAccountKey(t *testing.T) {
t.Errorf("Expected: %s ,received: %s ", ToJSON(eOut), ToJSON(rcv))
}
//check with wrong TenantAccount
rcv, err = NewTAFromAccountKey("")
_, err = NewTAFromAccountKey("")
if err == nil {
t.Errorf("Unsupported format not processed")
}
@@ -600,53 +600,53 @@ func TestRPCCDRsFilterAsCDRsFilter(t *testing.T) {
}
rpcCDRsFilter.ExtraArgs[MaxCost] = "notFloat64"
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
if _, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
t.Errorf("MaxCost should not be processed")
}
rpcCDRsFilter.ExtraArgs[MinCost] = "notFloat64"
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
if _, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
t.Errorf("MinCost should not be processed")
}
rpcCDRsFilter.ExtraArgs[OrderIDEnd] = "notInt64"
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
if _, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
t.Errorf("OrderIDEnd should not be processed")
}
rpcCDRsFilter.ExtraArgs[OrderIDStart] = "notInt64"
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
if _, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
t.Errorf("OrderIDStart should not be processed")
}
rpcCDRsFilter.UpdatedAtEnd = "wrongUpdatedAtEnd"
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
if _, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
t.Errorf("UpdatedAtEnd should not be processed")
}
rpcCDRsFilter.UpdatedAtStart = "wrongUpdatedAtStart"
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
if _, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
t.Errorf("UpdatedAtStart should not be processed")
}
rpcCDRsFilter.CreatedAtEnd = "wrongCreatedAtEnd"
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
if _, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
t.Errorf("CreatedAtEnd should not be processed")
}
rpcCDRsFilter.CreatedAtStart = "wrongCreatedAtStart"
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
if _, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
t.Errorf("CreatedAtStart should not be processed")
}
rpcCDRsFilter.AnswerTimeEnd = "wrongAnswerTimeEnd"
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
if _, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
t.Errorf("AnswerTimeEnd should not be processed")
}
rpcCDRsFilter.AnswerTimeStart = "wrongAnswerTimeStart"
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
if _, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
t.Errorf("AnswerTimeStart should not be processed")
}
rpcCDRsFilter.SetupTimeEnd = "wrongSetupTimeEnd"
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
if _, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
t.Errorf("SetupTimeEnd should not be processed")
}
rpcCDRsFilter.SetupTimeStart = "wrongSetupTimeStart"
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
if _, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
t.Errorf("SetupTimeStart should not be processed")
}
}
@@ -719,12 +719,12 @@ func TestTPActivationIntervalAsActivationInterval(t *testing.T) {
}
//check with wrong time
tPActivationInterval.ExpiryTime = "wrongExpiryTime"
rcv, err = tPActivationInterval.AsActivationInterval("")
_, err = tPActivationInterval.AsActivationInterval("")
if err == nil {
t.Errorf("Wrong ExpiryTime not processed")
}
tPActivationInterval.ActivationTime = "wrongActivationTime"
rcv, err = tPActivationInterval.AsActivationInterval("")
_, err = tPActivationInterval.AsActivationInterval("")
if err == nil {
t.Errorf("Wrong ActivationTimes not processed")
}

View File

@@ -23,7 +23,6 @@ import (
"testing"
"github.com/cenkalti/rpc2"
"github.com/cgrates/rpcclient"
)
func TestNewBiJSONrpcClient(t *testing.T) {
@@ -43,23 +42,9 @@ func TestNewBiJSONrpcClient(t *testing.T) {
"": func(*rpc2.Client, *struct{}, *string) error { return nil },
}
rcv, err = NewBiJSONrpcClient(addr, handlers)
_, err = NewBiJSONrpcClient(addr, handlers)
if err != nil {
t.Error(err)
}
l.Close()
}
type testBiRPCServer struct {
metod string
args interface{}
reply interface{}
}
func (*testBiRPCServer) Call(string, interface{}, interface{}) error { return nil }
func (t *testBiRPCServer) CallBiRPC(_ rpcclient.ClientConnector, metod string, args interface{}, reply interface{}) error {
t.metod = metod
t.args = args
t.reply = reply
return nil
}

View File

@@ -121,7 +121,7 @@ func TestLibRoutesUsage(t *testing.T) {
if answ != se.Event[Usage] {
t.Errorf("Expecting: %+v, received: %+v", se.Event[Usage], answ)
}
answ, err = seErr.FieldAsDuration(Usage)
_, err = seErr.FieldAsDuration(Usage)
if err != ErrNotFound {
t.Error(err)
}

View File

@@ -51,6 +51,4 @@ func (rw *CgrIORecordWriter) Write(record []string) error {
// Flush only to implement CgrRecordWriter
// ToDo: make sure we properly handle this method
func (*CgrIORecordWriter) Flush() {
return
}
func (*CgrIORecordWriter) Flush() {}

View File

@@ -651,11 +651,7 @@ func (h HierarchyPath) Clone() (cln HierarchyPath) {
if h == nil {
return
}
cln = make(HierarchyPath, len(h))
for i, p := range h {
cln[i] = p
}
return
return CloneStringSlice(h)
}
// Mask a number of characters in the suffix of the destination
@@ -728,7 +724,7 @@ func GetCGRVersion() (vers string, err error) {
}
func NewTenantID(tntID string) *TenantID {
if strings.Index(tntID, ConcatenatedKeySep) == -1 { // no :, ID without Tenant
if !strings.Contains(tntID, ConcatenatedKeySep) { // no :, ID without Tenant
return &TenantID{ID: tntID}
}
tIDSplt := strings.SplitN(tntID, ConcatenatedKeySep, 2)

View File

@@ -333,7 +333,7 @@ func TestParseTimeDetectLayout(t *testing.T) {
}
if nowTm, err := ParseTimeDetectLayout(MetaNow, ""); err != nil {
t.Error(err)
} else if time.Now().Sub(nowTm) > 10*time.Millisecond {
} else if time.Since(nowTm) > 10*time.Millisecond {
t.Errorf("Unexpected time parsed: %v", nowTm)
}
eamonTmStr := "31/05/2015 14:46:00"
@@ -1286,8 +1286,8 @@ func (tRPC *TestRPC) Call(args interface{}, reply interface{}) error {
return nil
}
func (tRPC *TestRPC) V1Error2(args interface{}, reply interface{}) (error, int) {
return nil, 0
func (tRPC *TestRPC) V1Error2(args interface{}, reply interface{}) (int, error) {
return 0, nil
}
func (tRPC *TestRPC) V1Error3(args interface{}, reply interface{}) int {
@@ -1334,8 +1334,8 @@ func (tRPC *TestRPC2) Call(args interface{}, reply interface{}) error {
return nil
}
func (tRPC *TestRPC2) Error2(args interface{}, reply interface{}) (error, int) {
return nil, 0
func (tRPC *TestRPC2) Error2(args interface{}, reply interface{}) (int, error) {
return 0, nil
}
func (tRPC *TestRPC2) Error3(args interface{}, reply interface{}) int {

View File

@@ -97,7 +97,7 @@ func TestNewDataConverter(t *testing.T) {
if !reflect.DeepEqual(a, b) {
t.Error("Error reflect")
}
if a, err = NewDataConverter(MetaMultiply); err == nil || err != ErrMandatoryIeMissingNoCaps {
if _, err = NewDataConverter(MetaMultiply); err == nil || err != ErrMandatoryIeMissingNoCaps {
t.Error(err)
}
a, err = NewDataConverter("*multiply:3.3")
@@ -111,7 +111,7 @@ func TestNewDataConverter(t *testing.T) {
if !reflect.DeepEqual(a, b) {
t.Error("Error reflect")
}
if a, err = NewDataConverter(MetaDivide); err == nil || err != ErrMandatoryIeMissingNoCaps {
if _, err = NewDataConverter(MetaDivide); err == nil || err != ErrMandatoryIeMissingNoCaps {
t.Error(err)
}
a, err = NewDataConverter("*divide:3.3")
@@ -125,7 +125,7 @@ func TestNewDataConverter(t *testing.T) {
if !reflect.DeepEqual(a, b) {
t.Error("Error reflect")
}
if a, err = NewDataConverter(MetaLibPhoneNumber); err == nil || err.Error() != "unsupported *libphonenumber converter parameters: <>" {
if _, err = NewDataConverter(MetaLibPhoneNumber); err == nil || err.Error() != "unsupported *libphonenumber converter parameters: <>" {
t.Error(err)
}
a, err = NewDataConverter("*libphonenumber:US")
@@ -139,7 +139,8 @@ func TestNewDataConverter(t *testing.T) {
if !reflect.DeepEqual(a, b) {
t.Error("Error reflect")
}
if _, err := NewDataConverter("unsupported"); err == nil || err.Error() != "unsupported converter definition: <unsupported>" {
if _, err = NewDataConverter("unsupported"); err == nil || err.Error() != "unsupported converter definition: <unsupported>" {
t.Error(err)
}
hex, err := NewDataConverter(MetaString2Hex)
@@ -244,7 +245,6 @@ func TestNewRoundConverter(t *testing.T) {
} else if !reflect.DeepEqual(rcv, eOut) {
t.Errorf("Expected %+v received: %+v", eOut, rcv)
}
eOut = &RoundConverter{}
if rcv, err := NewRoundConverter("12:*middle:wrong_length"); err == nil || err.Error() != "unsupported *round converter parameters: <12:*middle:wrong_length>" {
t.Error(err)
} else if !reflect.DeepEqual(rcv, nil) {

View File

@@ -234,8 +234,8 @@ func (n *DataNode) Set(path []string, val interface{}) (addedNew bool, err error
// IsEmpty return if the node is empty/ has no data
func (n DataNode) IsEmpty() bool {
return n.Value == nil ||
len(n.Map) == 0 ||
return n.Value == nil &&
len(n.Map) == 0 &&
len(n.Slice) == 0
}

View File

@@ -23,11 +23,11 @@ import (
)
func TestDPDynamicInterface(t *testing.T) {
nm := NavigableMap{
"Field1": NewNMData("1001"),
"Field2": NewNMData("1003"),
"Field3": NavigableMap{"Field4": NewNMData("Val")},
"Field5": &NMSlice{NewNMData(10), NewNMData(101)},
nm := MapStorage{
"Field1": "1001",
"Field2": "1003",
"Field3": MapStorage{"Field4": "Val"},
"Field5": []interface{}{10, 101},
}
var expected interface{} = "Field5[1]"
if rply, err := DPDynamicInterface("Field5[1]", nm); err != nil {
@@ -46,11 +46,11 @@ func TestDPDynamicInterface(t *testing.T) {
}
func TestDPDynamicString(t *testing.T) {
nm := NavigableMap{
"Field1": NewNMData("1001"),
"Field2": NewNMData("1003"),
"Field3": NavigableMap{"Field4": NewNMData("Val")},
"Field5": &NMSlice{NewNMData(10), NewNMData(101)},
nm := MapStorage{
"Field1": "1001",
"Field2": "1003",
"Field3": MapStorage{"Field4": "Val"},
"Field5": []interface{}{10, 101},
}
var expected interface{} = "Field5[1]"
if rply, err := DPDynamicString("Field5[1]", nm); err != nil {
@@ -70,127 +70,67 @@ func TestDPDynamicString(t *testing.T) {
func TestAppendNavMapVal(t *testing.T) {
onm := NewOrderedNavigableMap()
nm := NavigableMap{
"Field1": NewNMData("1001"),
"Field2": NewNMData("1003"),
"Field3": NavigableMap{"Field4": NewNMData("Val")},
"Field5": &NMSlice{NewNMData(10), NewNMData(101)},
}
nm := &DataNode{Type: NMMapType, Map: map[string]*DataNode{
"Field1": NewLeafNode("1001"),
"Field2": NewLeafNode("1003"),
"Field3": {Type: NMMapType, Map: map[string]*DataNode{"Field4": NewLeafNode("Val")}},
"Field5": {Type: NMSliceType, Slice: []*DataNode{NewLeafNode(10), NewLeafNode(101)}},
}}
onm.nm = nm
expected := NavigableMap{
"Field1": NewNMData("1001"),
"Field2": NewNMData("1003"),
"Field3": NavigableMap{"Field4": NewNMData("Val")},
"Field5": &NMSlice{NewNMData(10), NewNMData(101), NewNMData(18)},
}
if err := AppendNavMapVal(onm, &FullPath{Path: "Field5", PathItems: PathItems{{Field: "Field5"}}}, NewNMData(18)); err != nil {
expected := &DataNode{Type: NMMapType, Map: map[string]*DataNode{
"Field1": NewLeafNode("1001"),
"Field2": NewLeafNode("1003"),
"Field3": {Type: NMMapType, Map: map[string]*DataNode{"Field4": NewLeafNode("Val")}},
"Field5": {Type: NMSliceType, Slice: []*DataNode{NewLeafNode(10), NewLeafNode(101), NewLeafNode(18)}},
}}
if err := onm.Append(&FullPath{Path: "Field5", PathItems: []string{"Field5"}}, NewLeafNode(18).Value); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, onm.nm) {
t.Errorf("Expected %v ,received: %v", expected, onm.nm)
}
if err := AppendNavMapVal(onm, &FullPath{}, NewNMData(18)); err != ErrWrongPath {
if err := onm.Append(&FullPath{}, NewLeafNode(18).Value); err != ErrWrongPath {
t.Errorf("Expected error: %s received: %v", ErrWrongPath, err)
}
}
func TestComposeNavMapVal(t *testing.T) {
onm := NewOrderedNavigableMap()
nm := NavigableMap{
"Field4": &NMSlice{},
"Field5": &NMSlice{NewNMData(10), NewNMData(101)},
}
nm := &DataNode{Type: NMMapType, Map: map[string]*DataNode{
"Field4": {Type: NMSliceType, Slice: []*DataNode{}},
"Field5": {Type: NMSliceType, Slice: []*DataNode{NewLeafNode(10), NewLeafNode(101)}},
}}
onm.nm = nm
if err := ComposeNavMapVal(onm, &FullPath{Path: "Field4", PathItems: PathItems{{Field: "Field4"}}}, NewNMData(18)); err != ErrWrongPath {
if err := onm.Compose(&FullPath{Path: "Field4", PathItems: []string{"Field4", "10"}}, NewLeafNode(18).Value); err != ErrNotFound {
t.Error(err)
}
expected := NavigableMap{
"Field4": &NMSlice{},
"Field5": &NMSlice{NewNMData(10), NewNMData("10118")},
}
if err := ComposeNavMapVal(onm, &FullPath{Path: "Field5", PathItems: PathItems{{Field: "Field5"}}}, NewNMData(18)); err != nil {
expected := &DataNode{Type: NMMapType, Map: map[string]*DataNode{
"Field4": {Type: NMSliceType, Slice: []*DataNode{}},
"Field5": {Type: NMSliceType, Slice: []*DataNode{NewLeafNode(10), NewLeafNode("10118")}},
}}
if err := onm.Compose(&FullPath{Path: "Field5", PathItems: []string{"Field5"}}, NewLeafNode(18).Value); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, nm) {
t.Errorf("Expected %v ,received: %v", expected, nm)
}
expected = NavigableMap{
"Field4": &NMSlice{},
"Field5": &NMSlice{NewNMData(10), NewNMData("10118")},
"Field6": &NMSlice{NewNMData(10)},
}
if err := ComposeNavMapVal(onm, &FullPath{Path: "Field6", PathItems: PathItems{{Field: "Field6"}}}, NewNMData(10)); err != nil {
expected = &DataNode{Type: NMMapType, Map: map[string]*DataNode{
"Field4": {Type: NMSliceType, Slice: []*DataNode{}},
"Field5": {Type: NMSliceType, Slice: []*DataNode{NewLeafNode(10), NewLeafNode("10118")}},
"Field6": {Type: NMSliceType, Slice: []*DataNode{NewLeafNode(10)}},
}}
if err := onm.Compose(&FullPath{Path: "Field6", PathItems: []string{"Field6"}}, NewLeafNode(10).Value); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, nm) {
t.Errorf("Expected %v ,received: %v", expected, nm)
}
onm.nm = NavigableMap{
"Field4": NewNMData(1),
"Field5": &NMSlice{NewNMData(10), NewNMData(101)},
}
if err := ComposeNavMapVal(onm, &FullPath{Path: "Field4", PathItems: PathItems{{Field: "Field4"}}}, NewNMData(10)); err != ErrNotImplemented {
t.Error(err)
}
onm.nm = &DataNode{Type: NMMapType, Map: map[string]*DataNode{
"Field4": NewLeafNode(1),
"Field5": {Type: NMSliceType, Slice: []*DataNode{NewLeafNode(10), NewLeafNode(101)}},
}}
if err := ComposeNavMapVal(onm, &FullPath{Path: "Field5", PathItems: PathItems{{Field: "Field5"}}}, &mockNMInterface{data: 10}); err != ErrNotImplemented {
t.Error(err)
}
if err := ComposeNavMapVal(onm, &FullPath{}, NewNMData(18)); err != ErrWrongPath {
if err := onm.Compose(&FullPath{}, NewLeafNode(18).Value); err != ErrWrongPath {
t.Errorf("Expected error: %s received: %v", ErrWrongPath, err)
}
}
// mock NMInterface structure
type mockNMInterface struct{ data interface{} }
func (nmi *mockNMInterface) String() string {
return IfaceAsString(nmi.data)
}
// Interface returns the wraped interface
func (nmi *mockNMInterface) Interface() interface{} {
return nmi.data
}
// Field not implemented only used in order to implement the NM interface
func (nmi *mockNMInterface) Field(path PathItems) (val NMInterface, err error) {
return nil, ErrNotImplemented
}
// Set not implemented
func (nmi *mockNMInterface) Set(path PathItems, val NMInterface) (a bool, err error) {
return false, ErrNotImplemented
}
// Remove not implemented only used in order to implement the NM interface
func (nmi *mockNMInterface) Remove(path PathItems) (err error) {
return ErrNotImplemented
}
// Type returns the type of the NM interface
func (nmi *mockNMInterface) Type() NMType {
return NMDataType
}
// Empty returns true if the NM is empty(no data)
func (nmi *mockNMInterface) Empty() bool {
return nmi == nil || nmi.data == nil
}
// GetField not implemented only used in order to implement the NM interface
func (nmi *mockNMInterface) GetField(path PathItem) (val NMInterface, err error) {
return nil, ErrNotImplemented
}
// SetField not implemented
func (nmi *mockNMInterface) SetField(path PathItem, val NMInterface) (err error) {
return ErrNotImplemented
}
// Len not implemented only used in order to implement the NM interface
func (nmi *mockNMInterface) Len() int {
return 0
}

View File

@@ -73,7 +73,6 @@ func TestUnmarshalMarshalBinary(t *testing.T) {
}
dec = nil
expected = NewDecimal(10, 0)
if err := dec.UnmarshalBinary([]byte(`10`)); err != nil {
t.Error(err)
}

View File

@@ -111,8 +111,7 @@ func TestDynamicWeightString(t *testing.T) {
}
func TestCloneDynamicWeights(t *testing.T) {
dynWeigh := DynamicWeights{}
dynWeigh = nil
var dynWeigh DynamicWeights
if rcv := dynWeigh.Clone(); len(rcv) != 0 {
t.Errorf("Expected empty slice")
}

View File

@@ -151,7 +151,9 @@ func TestLibratesRunTimes(t *testing.T) {
}
eTime = sTime.Add(24 * time.Hour)
received, err = rt.RunTimes(sTime, eTime, verbosity)
if received, err = rt.RunTimes(sTime, eTime, verbosity); err != nil {
t.Error(err)
}
aT1, err := time.Parse(time.RFC3339, "2022-03-12T00:00:00Z")
if err != nil {
@@ -167,10 +169,6 @@ func TestLibratesRunTimes(t *testing.T) {
aTsl = append(aTsl, aT1, aT2)
expected = append(expected, aTsl)
if err != nil {
t.Errorf("\ndidn't expect error, got %v", err)
}
if !reflect.DeepEqual(received, expected) {
t.Errorf("\nExpected: <%+v>, \nReceived: <%+v>", expected, received)
}

View File

@@ -302,8 +302,7 @@ func TestCloseLogger(t *testing.T) {
if err != nil {
t.Error(err)
}
x := newLogger.GetSyslog()
x = newWriter
x := newWriter
newLogger.SetSyslog(x)
if err := newLogger.Close(); err != nil {

View File

@@ -87,7 +87,7 @@ func (sm StringMap) Slice() []string {
func (sm StringMap) IsEmpty() bool {
return sm == nil ||
len(sm) == 0 ||
sm[MetaAny] == true
sm[MetaAny]
}
func StringMapFromSlice(s []string) StringMap {
@@ -180,15 +180,14 @@ func (fWp FlagParams) ParamValue(opt string) (ps string) {
// Add adds the options to the flag
func (fWp FlagParams) Add(opts []string) {
switch len(opts) {
case 0:
case 1:
fWp[opts[0]] = []string{}
default: // just in case we call this function with more elements than needed
fallthrough
case 2:
fWp[opts[0]] = strings.Split(opts[1], ANDSep)
case 0:
case 1:
fWp[opts[0]] = []string{}
}
return
}
// ParamsSlice returns the list of profiles for the subsystem
@@ -217,10 +216,7 @@ func (fWp FlagParams) Clone() (cln FlagParams) {
for flg, params := range fWp {
var cprm []string
if params != nil {
cprm = make([]string, len(params))
for i, p := range params {
cprm[i] = p
}
cprm = CloneStringSlice(params)
}
cln[flg] = cprm
}

View File

@@ -90,7 +90,7 @@ func TestDecodeServerRequest(t *testing.T) {
if !reflect.DeepEqual(req, rcvReq) {
t.Errorf("Expecting: %+v, received: %+v", req, rcvReq)
}
if !reflect.DeepEqual(err, rcvErr) {
if err != rcvErr {
t.Errorf("Expecting: %+v, received: %+v", err, rcvErr)
}
}

View File

@@ -98,17 +98,6 @@ func (onm *OrderedNavigableMap) Set(fullPath *FullPath, val interface{}) (err er
}
path := stripIdxFromLastPathElm(fullPath.Path)
if !addedNew { // cleanup old references since the value is being overwritten
for idxPath, slcIdx := range onm.orderRef {
if !strings.HasPrefix(idxPath, path) {
continue
}
for _, el := range slcIdx {
onm.orderIdx.Remove(el)
}
delete(onm.orderRef, idxPath)
}
}
_, hasRef := onm.orderRef[path]
if addedNew || !hasRef {
onm.orderRef[path] = append(onm.orderRef[path], onm.orderIdx.PushBack(fullPath.PathItems))
@@ -147,14 +136,10 @@ func (onm *OrderedNavigableMap) SetAsSlice(fullPath *FullPath, vals []*DataNode)
}
delete(onm.orderRef, idxPath)
}
}
_, hasRef := onm.orderRef[path]
for _, pathItms := range pathItmsSet {
if addedNew || !hasRef {
onm.orderRef[path] = append(onm.orderRef[path], onm.orderIdx.PushBack(pathItms))
} else {
onm.orderIdx.MoveToBack(onm.orderRef[path][len(onm.orderRef[path])-1])
}
onm.orderRef[path] = append(onm.orderRef[path], onm.orderIdx.PushBack(pathItms))
}
return
}
@@ -192,7 +177,7 @@ func (onm *OrderedNavigableMap) OrderedFields() (flds []interface{}) {
flds = make([]interface{}, 0, len(onm.nm.Map))
for el := onm.GetFirstElement(); el != nil; el = el.Next() {
fld, _ := onm.Field(el.Value)
flds = append(flds, fld)
flds = append(flds, fld.Data)
}
return
}

File diff suppressed because it is too large Load Diff

View File

@@ -89,19 +89,3 @@ func GetPathIndexString(spath string) (opath string, idx *string) {
opath = spath[:idxStart]
return opath, &idxVal
}
// GetPathIndexSlice returns the path and index as string if index present
// path[index]=>path,[index1,index2]
// path=>path,nil
func GetPathIndexSlice(spath string) (opath string, idx []string) {
idxStart := strings.Index(spath, IdxStart)
if idxStart == -1 || !strings.HasSuffix(spath, IdxEnd) {
return spath, nil
}
idxVal := spath[idxStart+1 : len(spath)-1]
opath = spath[:idxStart]
if strings.Index(idxVal, IdxCombination) == -1 {
return opath, []string{idxVal}
}
return opath, strings.Split(idxVal, IdxCombination)
}

View File

@@ -19,7 +19,6 @@ package utils
import (
"reflect"
"strings"
"testing"
)
@@ -54,83 +53,6 @@ func TestStripIdxFromLastPathElm(t *testing.T) {
}
}
func TestNewPathItems(t *testing.T) {
pathSlice := strings.Split("*req.Field1[0].Account", NestingSep)
expected := PathItems{{Field: MetaReq}, {Field: "Field1", Index: []string{"0"}}, {Field: AccountField}}
if rply := NewPathItems(pathSlice); !reflect.DeepEqual(expected, rply) {
t.Errorf("Expected: %s, received: %s", ToJSON(expected), ToJSON(rply))
}
pathSlice = []string{}
expected = PathItems{}
if rply := NewPathItems(pathSlice); !reflect.DeepEqual(expected, rply) {
t.Errorf("Expected: %s, received: %s", ToJSON(expected), ToJSON(rply))
}
pathSlice = strings.Split("*req.Field1[*raw][0].Account", NestingSep)
expected = PathItems{{Field: MetaReq}, {Field: "Field1", Index: []string{"*raw", "0"}}, {Field: AccountField}}
if rply := NewPathItems(pathSlice); !reflect.DeepEqual(expected, rply) {
t.Errorf("Expected: %s, received: %s", ToJSON(expected), ToJSON(rply))
}
}
func TestPathItemString(t *testing.T) {
path := PathItem{Field: MetaReq}
expected := MetaReq
if rply := path.String(); expected != rply {
t.Errorf("Expected: %q, received: %q", expected, rply)
}
path = PathItem{Field: MetaReq, Index: []string{"10"}}
expected = MetaReq + "[10]"
if rply := path.String(); expected != rply {
t.Errorf("Expected: %q, received: %q", expected, rply)
}
}
func TestPathItemClone(t *testing.T) {
path := PathItem{Field: MetaReq, Index: []string{"0"}}
expected := PathItem{Field: MetaReq, Index: []string{"0"}}
rply := path.Clone()
path.Index[0] = "1"
if !reflect.DeepEqual(expected, rply) {
t.Errorf("Expected: %s, received: %s", ToJSON(expected), ToJSON(rply))
}
var path2 PathItem
expected = PathItem{}
rply = path2.Clone()
if !reflect.DeepEqual(expected, rply) {
t.Errorf("Expected: %s, received: %s", ToJSON(expected), ToJSON(rply))
}
}
func TestPathItemsString(t *testing.T) {
expected := "*req.Field1[0].Account"
path := NewPathItems(strings.Split(expected, NestingSep))
if rply := path.String(); expected != rply {
t.Errorf("Expected: %q, received: %q", expected, rply)
}
expected = ""
path = nil
if rply := path.String(); expected != rply {
t.Errorf("Expected: %q, received: %q", expected, rply)
}
}
func TestPathItemsClone(t *testing.T) {
path := NewPathItems(strings.Split("*req.Field1[0].Account", NestingSep))
expected := NewPathItems(strings.Split("*req.Field1[0].Account", NestingSep))
rply := path.Clone()
path[0] = PathItem{}
if !reflect.DeepEqual(expected, rply) {
t.Errorf("Expected: %s, received: %s", ToJSON(expected), ToJSON(rply))
}
expected = nil
path = nil
rply = path.Clone()
if !reflect.DeepEqual(expected, rply) {
t.Errorf("Expected: %s, received: %s", ToJSON(expected), ToJSON(rply))
}
}
func TestGetPathWithoutIndex(t *testing.T) {
expected := "field"
if rply := GetPathWithoutIndex("field[index]"); expected != rply {
@@ -142,27 +64,12 @@ func TestGetPathWithoutIndex(t *testing.T) {
}
}
func TestPathItemsSlice(t *testing.T) {
expected := []string{"*req", "Field1[0]", "Account"}
path := NewPathItems(expected)
if rply := path.Slice(); !reflect.DeepEqual(expected, rply) {
t.Errorf("Expected: %q, received: %q", expected, rply)
}
}
func TestNewFullPath(t *testing.T) {
expected := &FullPath{
PathItems: []PathItem{
{
Field: "test",
},
{
Field: "path",
},
},
Path: "test.path",
PathItems: []string{"test", "path"},
Path: "test.path",
}
if rcv := NewFullPath("test.path", NestingSep); !reflect.DeepEqual(rcv, expected) {
if rcv := NewFullPath("test.path"); !reflect.DeepEqual(rcv, expected) {
t.Errorf("Expected %+v \n, received %+v", ToJSON(expected), ToJSON(rcv))
}
}

View File

@@ -27,14 +27,14 @@ import (
func TestPathItemListNext(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node3 := NewPathItems([]string{"path3"})
node1 := []string{"path1"}
node2 := []string{"path2"}
node3 := []string{"path3"}
list.PushFront(node3)
list.PushFront(node2)
list.PushFront(node1)
if !reflect.DeepEqual("path2", list.Front().Next().Value.String()) {
t.Errorf("Expecting: <path2>, received: <%+v>", list.Front().Next().Value.String())
if !reflect.DeepEqual("path2", strings.Join(list.Front().Next().Value, NestingSep)) {
t.Errorf("Expecting: <path2>, received: <%+v>", strings.Join(list.Front().Next().Value, NestingSep))
}
}
@@ -49,14 +49,14 @@ func TestPathItemListNextNil(t *testing.T) {
func TestPathItemListPrev(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node3 := NewPathItems([]string{"path3"})
node1 := []string{"path1"}
node2 := []string{"path2"}
node3 := []string{"path3"}
list.PushFront(node3)
list.PushFront(node2)
list.PushFront(node1)
if !reflect.DeepEqual("path2", list.Back().Prev().Value.String()) {
t.Errorf("Expecting: <path2>, received: <%+v>", list.Back().Prev().Value.String())
if !reflect.DeepEqual("path2", strings.Join(list.Back().Prev().Value, NestingSep)) {
t.Errorf("Expecting: <path2>, received: <%+v>", strings.Join(list.Back().Prev().Value, NestingSep))
}
}
@@ -72,9 +72,9 @@ func TestPathItemListPrevNil(t *testing.T) {
func TestPathItemListInit(t *testing.T) {
list := NewPathItemList()
list2 := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node3 := NewPathItems([]string{"path3"})
node1 := []string{"path1"}
node2 := []string{"path2"}
node3 := []string{"path3"}
list.PushFront(node3)
list.PushFront(node2)
list.PushFront(node1)
@@ -93,9 +93,9 @@ func TestPathItemListNewPathItemList(t *testing.T) {
func TestPathItemListLen(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node3 := NewPathItems([]string{"path3"})
node1 := []string{"path1"}
node2 := []string{"path2"}
node3 := []string{"path3"}
list.PushFront(node3)
list.PushFront(node2)
list.PushFront(node1)
@@ -106,12 +106,12 @@ func TestPathItemListLen(t *testing.T) {
func TestPathItemListFront(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node1 := []string{"path1"}
node2 := []string{"path2"}
list.PushBack(node1)
list.PushBack(node2)
if !reflect.DeepEqual("path1", list.Front().Value.String()) {
t.Errorf("Expecting: <path1>, received: <%+v>", list.Front().Value.String())
if !reflect.DeepEqual("path1", strings.Join(list.Front().Value, NestingSep)) {
t.Errorf("Expecting: <path1>, received: <%+v>", strings.Join(list.Front().Value, NestingSep))
}
}
@@ -126,12 +126,12 @@ func TestPathItemListFrontNil(t *testing.T) {
func TestPathItemListBack(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node1 := []string{"path1"}
node2 := []string{"path2"}
list.PushBack(node1)
list.PushBack(node2)
if !reflect.DeepEqual("path2", list.Back().Value.String()) {
t.Errorf("Expecting: <path2>, received: <%+v>", list.Back().Value.String())
if !reflect.DeepEqual("path2", strings.Join(list.Back().Value, NestingSep)) {
t.Errorf("Expecting: <path2>, received: <%+v>", strings.Join(list.Back().Value, NestingSep))
}
}
@@ -156,143 +156,143 @@ func TestPathItemListLazyInit(t *testing.T) {
func TestPathItemListInsert(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node1 := []string{"path1"}
node2 := []string{"path2"}
list.PushBack(node1)
list.PushBack(node2)
list.insert(list.Front(), list.Back())
if !reflect.DeepEqual("path1", list.Back().Value.String()) {
t.Errorf("Expecting: <path1>, received: <%+v>", list.Back().Value.String())
if !reflect.DeepEqual("path1", strings.Join(list.Back().Value, NestingSep)) {
t.Errorf("Expecting: <path1>, received: <%+v>", strings.Join(list.Back().Value, NestingSep))
}
}
func TestPathItemListInsertValue(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node1 := []string{"path1"}
node2 := []string{"path2"}
list.PushBack(node1)
list.PushBack(node2)
list.insertValue(PathItems{{Field: "path3"}}, list.Back())
if !reflect.DeepEqual("path3", list.Back().Value.String()) {
t.Errorf("Expecting: <path3>, received: <%+v>", list.Back().Value.String())
list.insertValue([]string{"path3"}, list.Back())
if !reflect.DeepEqual("path3", strings.Join(list.Back().Value, NestingSep)) {
t.Errorf("Expecting: <path3>, received: <%+v>", strings.Join(list.Back().Value, NestingSep))
}
}
func TestPathItemListRemoveLowerCase(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node3 := NewPathItems([]string{"path3"})
node1 := []string{"path1"}
node2 := []string{"path2"}
node3 := []string{"path3"}
list.PushBack(node1)
list.PushBack(node2)
list.PushBack(node3)
list.remove(list.Back())
if !reflect.DeepEqual("path2", list.Back().Value.String()) {
t.Errorf("Expecting: <path2>, received: <%+v>", list.Back().Value.String())
if !reflect.DeepEqual("path2", strings.Join(list.Back().Value, NestingSep)) {
t.Errorf("Expecting: <path2>, received: <%+v>", strings.Join(list.Back().Value, NestingSep))
}
}
func TestPathItemListRemoveUpperCase1(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node3 := NewPathItems([]string{"path3"})
node1 := []string{"path1"}
node2 := []string{"path2"}
node3 := []string{"path3"}
list.PushBack(node1)
list.PushBack(node2)
list.PushBack(node3)
list.Remove(list.Front().Next())
if !reflect.DeepEqual("path3", list.Front().Next().Value.String()) {
t.Errorf("Expecting: <path3>, received: <%+v>", list.Front().Next().Value.String())
if !reflect.DeepEqual("path3", strings.Join(list.Front().Next().Value, NestingSep)) {
t.Errorf("Expecting: <path3>, received: <%+v>", strings.Join(list.Front().Next().Value, NestingSep))
}
}
func TestPathItemListRemoveUpperCase2(t *testing.T) {
list1 := NewPathItemList()
list2 := NewPathItemList()
node1 := NewPathItems([]string{"pathA"})
node2 := NewPathItems([]string{"pathB"})
node1 := []string{"pathA"}
node2 := []string{"pathB"}
list1.PushBack(node1)
list2.PushBack(node2)
list1.Remove(list2.Front())
if !reflect.DeepEqual("pathA", list1.Front().Value.String()) {
t.Errorf("Expecting: <pathA>, received: <%+v>", list1.Front().Value.String())
if !reflect.DeepEqual("pathA", strings.Join(list1.Front().Value, NestingSep)) {
t.Errorf("Expecting: <pathA>, received: <%+v>", strings.Join(list1.Front().Value, NestingSep))
}
}
func TestPathItemListMoveEqual(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node3 := NewPathItems([]string{"path3"})
node1 := []string{"path1"}
node2 := []string{"path2"}
node3 := []string{"path3"}
list.PushBack(node1)
list.PushBack(node2)
list.PushBack(node3)
list.move(list.Back(), list.Back())
if !reflect.DeepEqual("path3", list.Back().Value.String()) {
t.Errorf("Expecting: <path3>, received: <%+v>", list.Back().Value.String())
if !reflect.DeepEqual("path3", strings.Join(list.Back().Value, NestingSep)) {
t.Errorf("Expecting: <path3>, received: <%+v>", strings.Join(list.Back().Value, NestingSep))
}
}
func TestPathItemListMove(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node3 := NewPathItems([]string{"path3"})
node1 := []string{"path1"}
node2 := []string{"path2"}
node3 := []string{"path3"}
list.PushBack(node1)
list.PushBack(node2)
list.PushBack(node3)
list.move(list.Front(), list.Back())
if !reflect.DeepEqual("path3", list.Front().next.Value.String()) {
t.Errorf("Expecting: <path3>, received: <%+v>", list.Front().next.Value.String())
if !reflect.DeepEqual("path3", strings.Join(list.Front().next.Value, NestingSep)) {
t.Errorf("Expecting: <path3>, received: <%+v>", strings.Join(list.Front().next.Value, NestingSep))
}
if !reflect.DeepEqual("path1", list.Back().Value.String()) {
t.Errorf("Expecting: <path1>, received: <%+v>", list.Back().Value.String())
if !reflect.DeepEqual("path1", strings.Join(list.Back().Value, NestingSep)) {
t.Errorf("Expecting: <path1>, received: <%+v>", strings.Join(list.Back().Value, NestingSep))
}
if !reflect.DeepEqual("path2", list.Front().Value.String()) {
t.Errorf("Expecting: <path2>, received: <%+v>", list.Front().Value.String())
if !reflect.DeepEqual("path2", strings.Join(list.Front().Value, NestingSep)) {
t.Errorf("Expecting: <path2>, received: <%+v>", strings.Join(list.Front().Value, NestingSep))
}
}
func TestPathItemListPushFront(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node3 := NewPathItems([]string{"path3"})
node1 := []string{"path1"}
node2 := []string{"path2"}
node3 := []string{"path3"}
list.PushBack(node1)
list.PushBack(node2)
list.PushBack(node3)
list.PushFront(PathItems{{Field: "path4"}})
if !reflect.DeepEqual("path4", list.Front().Value.String()) {
t.Errorf("Expecting: <path4>, received: <%+v>", list.Front().Value.String())
list.PushFront([]string{"path4"})
if !reflect.DeepEqual("path4", strings.Join(list.Front().Value, NestingSep)) {
t.Errorf("Expecting: <path4>, received: <%+v>", strings.Join(list.Front().Value, NestingSep))
}
}
func TestPathItemListPushBack(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node3 := NewPathItems([]string{"path3"})
node1 := []string{"path1"}
node2 := []string{"path2"}
node3 := []string{"path3"}
list.PushBack(node1)
list.PushBack(node2)
list.PushBack(node3)
list.PushBack(PathItems{{Field: "path4"}})
if !reflect.DeepEqual("path4", list.Back().Value.String()) {
t.Errorf("Expecting: <path4>, received: <%+v>", list.Back().Value.String())
list.PushBack([]string{"path4"})
if !reflect.DeepEqual("path4", strings.Join(list.Back().Value, NestingSep)) {
t.Errorf("Expecting: <path4>, received: <%+v>", strings.Join(list.Back().Value, NestingSep))
}
}
func TestPathItemListInsertBefore(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node3 := NewPathItems([]string{"path3"})
node1 := []string{"path1"}
node2 := []string{"path2"}
node3 := []string{"path3"}
list.PushBack(node1)
list.PushBack(node2)
list.PushBack(node3)
list.InsertBefore(PathItems{{Field: "path4"}}, list.Back())
if !reflect.DeepEqual("path4", list.Back().Prev().Value.String()) {
t.Errorf("Expecting: <path4>, received: <%+v>", list.Back().Prev().Value.String())
list.InsertBefore([]string{"path4"}, list.Back())
if !reflect.DeepEqual("path4", strings.Join(list.Back().Prev().Value, NestingSep)) {
t.Errorf("Expecting: <path4>, received: <%+v>", strings.Join(list.Back().Prev().Value, NestingSep))
}
}
@@ -301,11 +301,11 @@ func TestPathItemListInsertBeforeNil(t *testing.T) {
list1 := NewPathItemList()
list2 := NewPathItemList()
var received *PathItemElement
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node1 := []string{"path1"}
node2 := []string{"path2"}
list1.PushBack(node1)
list2.PushBack(node2)
received = list1.InsertBefore(PathItems{{Field: "path4"}}, list2.Back())
received = list1.InsertBefore([]string{"path4"}, list2.Back())
if received != nil {
t.Errorf("Expecting: <%+v>, received: <%+v>", nil, received)
}
@@ -313,15 +313,15 @@ func TestPathItemListInsertBeforeNil(t *testing.T) {
func TestPathItemListInsertAfter(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node3 := NewPathItems([]string{"path3"})
node1 := []string{"path1"}
node2 := []string{"path2"}
node3 := []string{"path3"}
list.PushBack(node1)
list.PushBack(node2)
list.PushBack(node3)
list.InsertAfter(PathItems{{Field: "path4"}}, list.Front())
if !reflect.DeepEqual("path4", list.Front().Next().Value.String()) {
t.Errorf("Expecting: <path4>, received: <%+v>", list.Front().Next().Value.String())
list.InsertAfter([]string{"path4"}, list.Front())
if !reflect.DeepEqual("path4", strings.Join(list.Front().Next().Value, NestingSep)) {
t.Errorf("Expecting: <path4>, received: <%+v>", strings.Join(list.Front().Next().Value, NestingSep))
}
}
@@ -329,11 +329,11 @@ func TestPathItemListInsertAfterNil(t *testing.T) {
list1 := NewPathItemList()
list2 := NewPathItemList()
var received *PathItemElement
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node1 := []string{"path1"}
node2 := []string{"path2"}
list1.PushBack(node1)
list2.PushBack(node2)
received = list1.InsertAfter(PathItems{{Field: "path4"}}, list2.Back())
received = list1.InsertAfter([]string{"path4"}, list2.Back())
if received != nil {
t.Errorf("Expecting: <%+v>, received: <%+v>", nil, received)
}
@@ -342,84 +342,84 @@ func TestPathItemListInsertAfterNil(t *testing.T) {
func TestPathItemListMoveToFrontCase1(t *testing.T) {
list1 := NewPathItemList()
list2 := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node1 := []string{"path1"}
node2 := []string{"path2"}
list1.PushBack(node1)
list2.PushBack(node2)
list1.MoveToFront(list2.Back())
if !reflect.DeepEqual("path1", list1.Front().Value.String()) {
t.Errorf("Expecting: <path3>, received: <%+v>", list1.Front().Value.String())
if !reflect.DeepEqual("path1", strings.Join(list1.Front().Value, NestingSep)) {
t.Errorf("Expecting: <path3>, received: <%+v>", strings.Join(list1.Front().Value, NestingSep))
}
}
func TestPathItemListMoveToFrontCase2(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node3 := NewPathItems([]string{"path3"})
node1 := []string{"path1"}
node2 := []string{"path2"}
node3 := []string{"path3"}
list.PushBack(node1)
list.PushBack(node2)
list.PushBack(node3)
list.MoveToFront(list.Back())
if !reflect.DeepEqual("path3", list.Front().Value.String()) {
t.Errorf("Expecting: <path3>, received: <%+v>", list.Front().Value.String())
if !reflect.DeepEqual("path3", strings.Join(list.Front().Value, NestingSep)) {
t.Errorf("Expecting: <path3>, received: <%+v>", strings.Join(list.Front().Value, NestingSep))
}
}
func TestPathItemListMoveToBackCase1(t *testing.T) {
list1 := NewPathItemList()
list2 := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node1 := []string{"path1"}
node2 := []string{"path2"}
list1.PushBack(node1)
list2.PushBack(node2)
list1.MoveToBack(list2.Back())
if !reflect.DeepEqual("path1", list1.Back().Value.String()) {
t.Errorf("Expecting: <path1>, received: <%+v>", list1.Back().Value.String())
if !reflect.DeepEqual("path1", strings.Join(list1.Back().Value, NestingSep)) {
t.Errorf("Expecting: <path1>, received: <%+v>", strings.Join(list1.Back().Value, NestingSep))
}
}
func TestPathItemListMoveToBackCase2(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node3 := NewPathItems([]string{"path3"})
node1 := []string{"path1"}
node2 := []string{"path2"}
node3 := []string{"path3"}
list.PushBack(node1)
list.PushBack(node2)
list.PushBack(node3)
list.MoveToBack(list.Front())
if !reflect.DeepEqual("path1", list.Back().Value.String()) {
t.Errorf("Expecting: <path1>, received: <%+v>", list.Front().Value.String())
if !reflect.DeepEqual("path1", strings.Join(list.Back().Value, NestingSep)) {
t.Errorf("Expecting: <path1>, received: <%+v>", strings.Join(list.Front().Value, NestingSep))
}
}
func TestPathItemListMoveBeforeCase1(t *testing.T) {
list1 := NewPathItemList()
list2 := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node1 := []string{"path1"}
node2 := []string{"path2"}
list1.PushBack(node1)
list2.PushBack(node2)
list1.MoveBefore(list2.Front(), list1.Back())
if !reflect.DeepEqual("path1", list1.Front().Value.String()) {
t.Errorf("Expecting: <path1>, received: <%+v>", list1.Front().Value.String())
if !reflect.DeepEqual("path1", strings.Join(list1.Front().Value, NestingSep)) {
t.Errorf("Expecting: <path1>, received: <%+v>", strings.Join(list1.Front().Value, NestingSep))
}
}
func TestPathItemListMoveBeforeCase2(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node3 := NewPathItems([]string{"path3"})
node1 := []string{"path1"}
node2 := []string{"path2"}
node3 := []string{"path3"}
list.PushBack(node1)
list.PushBack(node2)
list.PushBack(node3)
list.MoveBefore(list.Front(), list.Back())
if !reflect.DeepEqual("path1", list.Back().Prev().Value.String()) {
t.Errorf("Expecting: <path1>, received: <%+v>", list.Back().Prev().Value.String())
if !reflect.DeepEqual("path1", strings.Join(list.Back().Prev().Value, NestingSep)) {
t.Errorf("Expecting: <path1>, received: <%+v>", strings.Join(list.Back().Prev().Value, NestingSep))
}
}
@@ -427,28 +427,28 @@ func TestPathItemListMoveBeforeCase2(t *testing.T) {
func TestPathItemListMoveAfterCase1(t *testing.T) {
list1 := NewPathItemList()
list2 := NewPathItemList()
node1 := NewPathItems([]string{"pathA"})
node2 := NewPathItems([]string{"pathB"})
node1 := []string{"pathA"}
node2 := []string{"pathB"}
list1.PushBack(node1)
list2.PushBack(node2)
list1.MoveAfter(list2.Front(), list1.Back())
if !reflect.DeepEqual("pathA", list1.Back().Value.String()) {
t.Errorf("Expecting: <pathA>, received: <%+v>", list1.Back().Value.String())
if !reflect.DeepEqual("pathA", strings.Join(list1.Back().Value, NestingSep)) {
t.Errorf("Expecting: <pathA>, received: <%+v>", strings.Join(list1.Back().Value, NestingSep))
}
}
func TestPathItemListMoveAfterCase2(t *testing.T) {
list := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
node3 := NewPathItems([]string{"path3"})
node1 := []string{"path1"}
node2 := []string{"path2"}
node3 := []string{"path3"}
list.PushBack(node1)
list.PushBack(node2)
list.PushBack(node3)
list.MoveAfter(list.Front(), list.Back())
if !reflect.DeepEqual("path1", list.Back().Value.String()) {
t.Errorf("Expecting: <path1>, received: <%+v>", list.Back().Value.String())
if !reflect.DeepEqual("path1", strings.Join(list.Back().Value, NestingSep)) {
t.Errorf("Expecting: <path1>, received: <%+v>", strings.Join(list.Back().Value, NestingSep))
}
}
@@ -456,40 +456,40 @@ func TestPathItemListMoveAfterCase2(t *testing.T) {
func TestPathItemListPushBackList(t *testing.T) {
list1 := NewPathItemList()
list2 := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
nodeA := NewPathItems([]string{"pathA"})
nodeB := NewPathItems([]string{"pathB"})
node1 := []string{"path1"}
node2 := []string{"path2"}
nodeA := []string{"pathA"}
nodeB := []string{"pathB"}
list1.PushBack(node1)
list1.PushBack(node2)
list2.PushBack(nodeA)
list2.PushBack(nodeB)
list1.PushBackList(list2)
if !reflect.DeepEqual("pathB", list1.Back().Value.String()) {
t.Errorf("Expecting: <pathB>, received: <%+v>", list1.Back().Value.String())
if !reflect.DeepEqual("pathB", strings.Join(list1.Back().Value, NestingSep)) {
t.Errorf("Expecting: <pathB>, received: <%+v>", strings.Join(list1.Back().Value, NestingSep))
}
if !reflect.DeepEqual("pathA", list1.Back().Prev().Value.String()) {
t.Errorf("Expecting: <pathA>, received: <%+v>", list1.Back().Prev().Value.String())
if !reflect.DeepEqual("pathA", strings.Join(list1.Back().Prev().Value, NestingSep)) {
t.Errorf("Expecting: <pathA>, received: <%+v>", strings.Join(list1.Back().Prev().Value, NestingSep))
}
}
func TestPathItemListPushFrontList(t *testing.T) {
list1 := NewPathItemList()
list2 := NewPathItemList()
node1 := NewPathItems([]string{"path1"})
node2 := NewPathItems([]string{"path2"})
nodeA := NewPathItems([]string{"pathA"})
nodeB := NewPathItems([]string{"pathB"})
node1 := []string{"path1"}
node2 := []string{"path2"}
nodeA := []string{"pathA"}
nodeB := []string{"pathB"}
list1.PushBack(node1)
list1.PushBack(node2)
list2.PushBack(nodeA)
list2.PushBack(nodeB)
list1.PushFrontList(list2)
if !reflect.DeepEqual("pathA", list1.Front().Value.String()) {
t.Errorf("Expecting: <pathA>, received: <%+v>", list1.Front().Value.String())
if !reflect.DeepEqual("pathA", strings.Join(list1.Front().Value, NestingSep)) {
t.Errorf("Expecting: <pathA>, received: <%+v>", strings.Join(list1.Front().Value, NestingSep))
}
if !reflect.DeepEqual("pathB", list1.Front().Next().Value.String()) {
t.Errorf("Expecting: <pathB>, received: <%+v>", list1.Front().Next().Value.String())
if !reflect.DeepEqual("pathB", strings.Join(list1.Front().Next().Value, NestingSep)) {
t.Errorf("Expecting: <pathB>, received: <%+v>", strings.Join(list1.Front().Next().Value, NestingSep))
}
}
@@ -572,11 +572,12 @@ func BenchmarkGetPathIndexSlice(b *testing.B) {
}
}
/*
func BenchmarkGetPathIndexSliceSplit(b *testing.B) {
for i := 0; i < b.N; i++ {
GetPathIndexSlice(benchPath)
}
}
}*/
func BenchmarkGetPathIndexSliceStringsIndex(b *testing.B) {
for i := 0; i < b.N; i++ {
GetPathIndexSliceStringsIndex(benchPath)

View File

@@ -117,11 +117,11 @@ func ReflectFieldAsString(intf interface{}, fldName, extraFieldsLabel string) (s
}
func IfaceAsTime(itm interface{}, timezone string) (t time.Time, err error) {
switch itm.(type) {
switch v := itm.(type) {
case time.Time:
return itm.(time.Time), nil
return v, nil
case string:
return ParseTimeDetectLayout(itm.(string), timezone)
return ParseTimeDetectLayout(v, timezone)
default:
err = fmt.Errorf("cannot convert field: %+v to time.Time", itm)
}
@@ -279,17 +279,17 @@ func IfaceAsFloat64(itm interface{}) (f float64, err error) {
}
func IfaceAsBool(itm interface{}) (b bool, err error) {
switch itm.(type) {
switch v := itm.(type) {
case bool:
return itm.(bool), nil
return v, nil
case string:
return strconv.ParseBool(itm.(string))
return strconv.ParseBool(v)
case int:
return itm.(int) > 0, nil
return v > 0, nil
case int64:
return itm.(int64) > 0, nil
return v > 0, nil
case float64:
return itm.(float64) > 0, nil
return v > 0, nil
default:
err = fmt.Errorf("cannot convert field: %+v to bool", itm)
}

View File

@@ -733,18 +733,18 @@ type TestA struct {
type TestASlice []*TestA
func (_ *TestA) TestFunc() string {
func (*TestA) TestFunc() string {
return "This is a test function on a structure"
}
func (_ *TestA) TestFuncWithParam(param string) string {
func (*TestA) TestFuncWithParam(param string) string {
return "Invalid"
}
func (_ *TestA) TestFuncWithError() (string, error) {
func (*TestA) TestFuncWithError() (string, error) {
return "TestFuncWithError", nil
}
func (_ *TestA) TestFuncWithError2() (string, error) {
func (*TestA) TestFuncWithError2() (string, error) {
return "TestFuncWithError2", ErrPartiallyExecuted
}
@@ -756,7 +756,7 @@ func TestReflectFieldMethodInterface(t *testing.T) {
} else if ifValue != "TestStructField" {
t.Errorf("Expecting: TestStructField, received: %+v", ifValue)
}
ifValue, err = ReflectFieldMethodInterface(a, "InexistentField")
_, err = ReflectFieldMethodInterface(a, "InexistentField")
if err != ErrNotFound {
t.Error(err)
}
@@ -772,7 +772,7 @@ func TestReflectFieldMethodInterface(t *testing.T) {
} else if ifValue != "TestFuncWithError" {
t.Errorf("Expecting: TestFuncWithError, received: %+v", ifValue)
}
ifValue, err = ReflectFieldMethodInterface(a, "TestFuncWithError2")
_, err = ReflectFieldMethodInterface(a, "TestFuncWithError2")
if err == nil || err != ErrPartiallyExecuted {
t.Error(err)
}
@@ -988,8 +988,7 @@ func TestIfaceAsDurationDefaultError(t *testing.T) {
}
func TestIfaceAsDurationCaseUInt(t *testing.T) {
var test uint
test = 127
var test uint = 127
response, _ := IfaceAsDuration(test)
if !reflect.DeepEqual(response.String(), "127ns") {
t.Errorf("Expected <127ns> ,received: <%+v>", response)
@@ -997,8 +996,7 @@ func TestIfaceAsDurationCaseUInt(t *testing.T) {
}
func TestIfaceAsDurationCaseInt8(t *testing.T) {
var test int8
test = 127
var test int8 = 127
response, _ := IfaceAsDuration(test)
if !reflect.DeepEqual(response.String(), "127ns") {
t.Errorf("Expected <127ns> ,received: <%+v>", response)
@@ -1006,8 +1004,7 @@ func TestIfaceAsDurationCaseInt8(t *testing.T) {
}
func TestIfaceAsDurationCaseNegInt8(t *testing.T) {
var test int8
test = -127
var test int8 = -127
response, _ := IfaceAsDuration(test)
if !reflect.DeepEqual(response.String(), "-127ns") {
t.Errorf("Expected <-127ns> ,received: <%+v>", response)
@@ -1015,8 +1012,7 @@ func TestIfaceAsDurationCaseNegInt8(t *testing.T) {
}
func TestIfaceAsDurationCaseUInt8(t *testing.T) {
var test uint8
test = 127
var test uint8 = 127
response, _ := IfaceAsDuration(test)
if !reflect.DeepEqual(response.String(), "127ns") {
t.Errorf("Expected <127ns> ,received: <%+v>", response)
@@ -1024,8 +1020,7 @@ func TestIfaceAsDurationCaseUInt8(t *testing.T) {
}
func TestIfaceAsDurationCaseInt16(t *testing.T) {
var test int16
test = 32767
var test int16 = 32767
response, _ := IfaceAsDuration(test)
if !reflect.DeepEqual(response.String(), "32.767µs") {
t.Errorf("Expected <32.767µs> ,received: <%+v>", response)
@@ -1033,8 +1028,7 @@ func TestIfaceAsDurationCaseInt16(t *testing.T) {
}
func TestIfaceAsDurationCaseNegInt16(t *testing.T) {
var test int16
test = -32767
var test int16 = -32767
response, _ := IfaceAsDuration(test)
if !reflect.DeepEqual(response.String(), "-32.767µs") {
t.Errorf("Expected <-32.767µs> ,received: <%+v>", response)
@@ -1042,8 +1036,7 @@ func TestIfaceAsDurationCaseNegInt16(t *testing.T) {
}
func TestIfaceAsDurationCaseUInt16(t *testing.T) {
var test uint16
test = 32767
var test uint16 = 32767
response, _ := IfaceAsDuration(test)
if !reflect.DeepEqual(response.String(), "32.767µs") {
t.Errorf("Expected <32.767µs> ,received: <%+v>", response)
@@ -1051,8 +1044,7 @@ func TestIfaceAsDurationCaseUInt16(t *testing.T) {
}
func TestIfaceAsDurationCaseInt32(t *testing.T) {
var test int32
test = 2147483647
var test int32 = 2147483647
response, _ := IfaceAsDuration(test)
if !reflect.DeepEqual(response.String(), "2.147483647s") {
t.Errorf("Expected <2.147483647s> ,received: <%+v>", response)
@@ -1060,8 +1052,7 @@ func TestIfaceAsDurationCaseInt32(t *testing.T) {
}
func TestIfaceAsDurationCaseNegInt32(t *testing.T) {
var test int32
test = -2147483647
var test int32 = -2147483647
response, _ := IfaceAsDuration(test)
if !reflect.DeepEqual(response.String(), "-2.147483647s") {
t.Errorf("Expected <-2.147483647s> ,received: <%+v>", response)
@@ -1069,8 +1060,7 @@ func TestIfaceAsDurationCaseNegInt32(t *testing.T) {
}
func TestIfaceAsDurationCaseUInt32(t *testing.T) {
var test uint32
test = 2147483647
var test uint32 = 2147483647
response, _ := IfaceAsDuration(test)
if !reflect.DeepEqual(response.String(), "2.147483647s") {
t.Errorf("Expected <2.147483647s> ,received: <%+v>", response)
@@ -1078,8 +1068,7 @@ func TestIfaceAsDurationCaseUInt32(t *testing.T) {
}
func TestIfaceAsDurationCaseInt64(t *testing.T) {
var test int64
test = 9223372036854775807
var test int64 = 9223372036854775807
response, _ := IfaceAsDuration(test)
if !reflect.DeepEqual(response.String(), "2562047h47m16.854775807s") {
t.Errorf("Expected <2562047h47m16.854775807s> ,received: <%+v>", response)
@@ -1087,8 +1076,7 @@ func TestIfaceAsDurationCaseInt64(t *testing.T) {
}
func TestIfaceAsDurationCaseNegInt64(t *testing.T) {
var test int64
test = -9223372036854775807
var test int64 = -9223372036854775807
response, _ := IfaceAsDuration(test)
if !reflect.DeepEqual(response.String(), "-2562047h47m16.854775807s") {
t.Errorf("Expected <-2562047h47m16.854775807s> ,received: <%+v>", response)
@@ -1096,8 +1084,7 @@ func TestIfaceAsDurationCaseNegInt64(t *testing.T) {
}
func TestIfaceAsDurationCaseUInt64(t *testing.T) {
var test uint64
test = 9223372036854775807
var test uint64 = 9223372036854775807
response, _ := IfaceAsDuration(test)
if !reflect.DeepEqual(response.String(), "2562047h47m16.854775807s") {
t.Errorf("Expected <2562047h47m16.854775807s> ,received: <%+v>", response)
@@ -1105,8 +1092,7 @@ func TestIfaceAsDurationCaseUInt64(t *testing.T) {
}
func TestIfaceAsDurationCaseFloat32(t *testing.T) {
var test float32
test = 9.5555555
var test float32 = 9.5555555
response, _ := IfaceAsDuration(test)
if !reflect.DeepEqual(response.String(), "9ns") {
t.Errorf("Expected <9ns> ,received: <%+v>", response)
@@ -1114,10 +1100,8 @@ func TestIfaceAsDurationCaseFloat32(t *testing.T) {
}
func TestIfaceAsInt6432to64(t *testing.T) {
var test int32
var expected int64
test = 2147483647
expected = 2147483647
var test int32 = 2147483647
var expected int64 = 2147483647
response, _ := IfaceAsInt64(test)
if !reflect.DeepEqual(response, expected) {
t.Errorf("Expected <%+v> ,received: <%+v>", expected, response)
@@ -1125,8 +1109,7 @@ func TestIfaceAsInt6432to64(t *testing.T) {
}
func TestIfaceAsInt64Default(t *testing.T) {
var test bool
test = true
var test bool = true
_, err := IfaceAsInt64(test)
if err == nil || err.Error() != "cannot convert field: true to int" {
t.Errorf("Expecting <cannot convert field: true to int> ,received: <%+v>", err)
@@ -1134,8 +1117,7 @@ func TestIfaceAsInt64Default(t *testing.T) {
}
func TestIfaceAsInt64Nanosecs(t *testing.T) {
var test time.Duration
test = 2147483647
var test time.Duration = 2147483647
response, _ := IfaceAsInt64(test)
if !reflect.DeepEqual(response, test.Nanoseconds()) {
t.Errorf("Expected <%+v> ,received: <%+v>", test.Nanoseconds(), response)
@@ -1143,8 +1125,7 @@ func TestIfaceAsInt64Nanosecs(t *testing.T) {
}
func TestIfaceAsTInt64Default(t *testing.T) {
var test bool
test = true
var test bool = true
_, err := IfaceAsTInt64(test)
if err == nil || err.Error() != "cannot convert field<bool>: true to int" {
t.Errorf("Expecting <cannot convert field<bool>: true to int> ,received: <%+v>", err)
@@ -1152,8 +1133,7 @@ func TestIfaceAsTInt64Default(t *testing.T) {
}
func TestIfaceAsTInt64Nanosecs(t *testing.T) {
var test time.Duration
test = 2147483647
var test time.Duration = 2147483647
response, _ := IfaceAsTInt64(test)
if !reflect.DeepEqual(response, test.Nanoseconds()) {
t.Errorf("Expected <%+v> ,received: <%+v>", test.Nanoseconds(), response)
@@ -1161,8 +1141,7 @@ func TestIfaceAsTInt64Nanosecs(t *testing.T) {
}
func TestIfaceAsBoolInt64(t *testing.T) {
var test int64
test = 2147483647
var test int64 = 2147483647
response, _ := IfaceAsBool(test)
if !reflect.DeepEqual(response, true) {
t.Errorf("Expected <%+v> ,received: <%+v>", true, response)
@@ -1170,8 +1149,7 @@ func TestIfaceAsBoolInt64(t *testing.T) {
}
func TestIfaceAsBoolDefault(t *testing.T) {
var test uint64
test = 2147483647
var test uint64 = 2147483647
_, err := IfaceAsBool(test)
if err == nil || err.Error() != "cannot convert field: 2147483647 to bool" {
t.Errorf("Expecting <cannot convert field: 2147483647 to bool> ,received: <%+v>", err)
@@ -1179,10 +1157,8 @@ func TestIfaceAsBoolDefault(t *testing.T) {
}
func TestIfaceAsStringInt32(t *testing.T) {
var test int32
var expected string
test = 2147483647
expected = "2147483647"
var test int32 = 2147483647
expected := "2147483647"
response := IfaceAsString(test)
if !reflect.DeepEqual(response, expected) {
t.Errorf("Expected <%+v> ,received: <%+v>", expected, response)
@@ -1190,10 +1166,8 @@ func TestIfaceAsStringInt32(t *testing.T) {
}
func TestIfaceAsStringInt32Neg(t *testing.T) {
var test int32
var expected string
test = -2147483647
expected = "-2147483647"
var test int32 = -2147483647
expected := "-2147483647"
response := IfaceAsString(test)
if !reflect.DeepEqual(response, expected) {
t.Errorf("Expected <%+v> ,received: <%+v>", expected, response)
@@ -1201,10 +1175,8 @@ func TestIfaceAsStringInt32Neg(t *testing.T) {
}
func TestIfaceAsStringInt64Neg(t *testing.T) {
var test int64
var expected string
test = -9223372036854775807
expected = "-9223372036854775807"
var test int64 = -9223372036854775807
expected := "-9223372036854775807"
response := IfaceAsString(test)
if !reflect.DeepEqual(response, expected) {
t.Errorf("Expected <%+v> ,received: <%+v>", expected, response)
@@ -1212,10 +1184,8 @@ func TestIfaceAsStringInt64Neg(t *testing.T) {
}
func TestIfaceAsStringUInt32(t *testing.T) {
var test uint32
var expected string
test = 2147483647
expected = "2147483647"
var test uint32 = 2147483647
expected := "2147483647"
response := IfaceAsString(test)
if !reflect.DeepEqual(response, expected) {
t.Errorf("Expected <%+v> ,received: <%+v>", expected, response)
@@ -1223,10 +1193,8 @@ func TestIfaceAsStringUInt32(t *testing.T) {
}
func TestIfaceAsStringUInt64(t *testing.T) {
var test uint64
var expected string
test = 9223372036854775807
expected = "9223372036854775807"
var test uint64 = 9223372036854775807
expected := "9223372036854775807"
response := IfaceAsString(test)
if !reflect.DeepEqual(response, expected) {
t.Errorf("Expected <%+v> ,received: <%+v>", expected, response)
@@ -1234,10 +1202,8 @@ func TestIfaceAsStringUInt64(t *testing.T) {
}
func TestIfaceAsStringFloat32(t *testing.T) {
var test float32
var expected string
test = 2.5
expected = "2.5"
var test float32 = 2.5
expected := "2.5"
response := IfaceAsString(test)
if !reflect.DeepEqual(response, expected) {
t.Errorf("Expected <%+v> ,received: <%+v>", expected, response)
@@ -1245,27 +1211,16 @@ func TestIfaceAsStringFloat32(t *testing.T) {
}
func TestIfaceAsStringFloat32Neg(t *testing.T) {
var test float32
var expected string
test = -2.5
expected = "-2.5"
var test float32 = -2.5
expected := "-2.5"
response := IfaceAsString(test)
if !reflect.DeepEqual(response, expected) {
t.Errorf("Expected <%+v> ,received: <%+v>", expected, response)
}
}
func TestIfaceAsStringNMInterface(t *testing.T) {
var test NMInterface = NewNMData("1001")
response := IfaceAsString(test)
if !reflect.DeepEqual(response, "1001") {
t.Errorf("Expected <1001> ,received: <%+v>", response)
}
}
func TestGetBasicTypeUint(t *testing.T) {
var test interface{}
test = uint8(123)
var test interface{} = uint8(123)
valItm := reflect.ValueOf(test)
response := GetBasicType(test)
if !reflect.DeepEqual(valItm.Uint(), response) {
@@ -1389,8 +1344,7 @@ func TestEqualToError(t *testing.T) {
}
func TestIfaceAsStringDefault(t *testing.T) {
var test int8
test = 2
var test int8 = 2
response := IfaceAsString(test)
if !reflect.DeepEqual(response, "2") {
t.Errorf("Expected <2> ,received: <%+v>", response)
@@ -1606,7 +1560,7 @@ func TestReflectFieldMethodInterfaceArrayDefault(t *testing.T) {
}
}
func (_ *TestA) TestFuncWithParamError2() (string, string, string) {
func (*TestA) TestFuncWithParamError2() (string, string, string) {
return "Invalid", "invalid2", "invalid3"
}
@@ -1626,7 +1580,7 @@ func TestReflectFieldMethodInterfaceElseError2(t *testing.T) {
}
}
func (_ *TestA) TestFuncWithParamError3() (string, string) {
func (*TestA) TestFuncWithParamError3() (string, string) {
return "Invalid", "invalid2"
}

View File

@@ -127,7 +127,7 @@ func (rsrFltr *RSRFilter) Pass(val string) bool {
}
return gt != rsrFltr.negative
}
return (strings.Index(val, rsrFltr.filterRule) != -1) != rsrFltr.negative // default is string index
return strings.Contains(val, rsrFltr.filterRule) != rsrFltr.negative // default is string index
}
func ParseRSRFilters(fldsStr, sep string) (RSRFilters, error) {