updated tests in utils

This commit is contained in:
adragusin
2020-01-06 17:56:13 +02:00
parent 61b4dcd65d
commit 226618d8b8
2 changed files with 42 additions and 1 deletions

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

@@ -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)
}
}