Merge pull request #1843 from adragusin/master

Updated tests in engine
This commit is contained in:
Dan Christian Bogos
2020-01-06 17:09:24 +01:00
committed by GitHub
4 changed files with 105 additions and 1 deletions

View File

@@ -2370,6 +2370,25 @@ func TestAccountClone(t *testing.T) {
}
func TestAccountGetBalanceWithID(t *testing.T){
account := &Account{
BalanceMap: map[string]Balances{
"type1" : Balances{&Balance{ID: "test1",Value: 0.7,}},
"type2" :Balances{&Balance{ID: "test2",Value: 0.8,}},
},
}
if rcv := account.GetBalanceWithID("type1","test1"); rcv.Value != 0.7{
t.Errorf("Expecting: 0.7, received: %+v",rcv)
}
if rcv := account.GetBalanceWithID("type2","test2"); rcv.Value != 0.8{
t.Errorf("Expecting: 0.8, received: %+v",rcv)
}
if rcv := account.GetBalanceWithID("unknown","unknown"); rcv != nil{
t.Errorf("Expecting: nil, received: %+v",rcv)
}
}
/*********************************** Benchmarks *******************************/
func BenchmarkGetSecondForPrefix(b *testing.B) {

View File

@@ -99,7 +99,7 @@ func (cM *ConnManager) Call(connIDs []string, biRPCClient rpcclient.ClientConnec
if conn, err = cM.getConn(connID, biRPCClient); err != nil {
continue
}
if err = conn.Call(method, arg, reply); rpcclient.IsNetworkError(err) {
if err = conn.Call(method, arg, reply); utils.IsNetworkError(err) {
continue
} else {
return

View File

@@ -240,6 +240,50 @@ func TestMapEventGetTimeIgnoreErrors(t *testing.T) {
}
}
func TestGetTimePtr(t *testing.T) {
rcv1, err := mapEv.GetTimePtr("test", utils.EmptyString)
if err == nil || err != utils.ErrNotFound {
t.Errorf("Expected: %+v, received: %+v", utils.ErrNotFound, err)
} else if rcv1 != nil {
t.Errorf("Expected: nil, received: %+v", rcv1)
}
expected := time.Date(2009, 11, 10, 23, 0, 0, 0, time.UTC)
rcv2, err := mapEv.GetTimePtr("test8", utils.EmptyString)
if err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, *rcv2) {
t.Errorf("Expecting %+v, received: %+v", expected, rcv2)
}
rcv3, err := mapEv.GetTimePtr("test9", utils.EmptyString)
if err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, *rcv3) {
t.Errorf("Expecting %+v, received: %+v", expected, rcv3)
}
if rcv1 == rcv2 || rcv2 == rcv3 || rcv1 == rcv3 {
t.Errorf("Expecting to be different adresses")
}
}
func TestGetTimePtrIgnoreErrors(t *testing.T) {
rcv1 := mapEv.GetTimePtrIgnoreErrors("test", utils.EmptyString)
if rcv1 != nil {
t.Errorf("Expected: nil, received: %+v", rcv1)
}
expected := time.Date(2009, 11, 10, 23, 0, 0, 0, time.UTC)
rcv2 := mapEv.GetTimePtrIgnoreErrors("test8", utils.EmptyString)
if rcv2 != nil && !reflect.DeepEqual(expected, *rcv2) {
t.Errorf("Expecting %+v, received: %+v", expected, rcv2)
}
rcv3 := mapEv.GetTimePtrIgnoreErrors("test9", utils.EmptyString)
if rcv3 != nil && !reflect.DeepEqual(expected, *rcv3) {
t.Errorf("Expecting %+v, received: %+v", expected, rcv3)
}
if rcv1 == rcv2 || rcv2 == rcv3 || rcv1 == rcv3 {
t.Errorf("Expecting to be different adresses")
}
}
func TestMapEventClone(t *testing.T) {
rply := mapEv.Clone()
if !reflect.DeepEqual(mapEv, rply) {

View File

@@ -18,7 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package utils
import (
"fmt"
"net"
"reflect"
"syscall"
"testing"
)
@@ -189,3 +192,41 @@ func TestErrEnvNotFound(t *testing.T) {
t.Errorf("Expecting: NOT_FOUND:ENV_VAR:test_string, received: %+v", rcv)
}
}
func TestIsNetworkError(t *testing.T) {
if IsNetworkError(nil) {
t.Errorf("Expecting: false, received: true")
}
if !IsNetworkError(ErrReqUnsynchronized) {
t.Errorf("Expecting: true, received: false")
}
var err error
if IsNetworkError(err) {
t.Errorf("Nill error should not be consider a network error")
}
err = &net.OpError{Err: syscall.ECONNRESET}
if !IsNetworkError(err) {
t.Errorf("syscall.ECONNRESET should be consider a network error")
}
err = fmt.Errorf("NOT_FOUND")
if IsNetworkError(err) {
t.Errorf("%s error should not be consider a network error", err)
}
err = ErrDisconnected
if !IsNetworkError(err) {
t.Errorf("%s error should be consider a network error", err)
}
}
func TestErrPathNotReachable(t *testing.T) {
if rcv := ErrPathNotReachable("test/path"); rcv.Error() != `path:"test/path" is not reachable` {
t.Errorf("Expecting: path:'test/path' is not reachable, received: %+v", rcv)
}
}
func TestErrNotConvertibleTF(t *testing.T) {
if rcv := ErrNotConvertibleTF("test_type1", "test_type2"); rcv.Error() != `not convertible : from: test_type1 to:test_type2` {
t.Errorf("Expecting: not convertible : from: test_type1 to:test_type2, received: %+v", rcv)
}
}