github.com/aporeto-inc/trireme-lib@v10.358.0+incompatible/controller/internal/enforcer/utils/rpcwrapper/rpc_handletest.go (about)

     1  package rpcwrapper
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  )
     7  
     8  //Not mocking system libraries
     9  //Will create actual rpc client server without using wrapper to test our implementations
    10  
    11  const (
    12  	defaultchannel = "/tmp/test.sock"
    13  )
    14  
    15  // TestNewRPCClient mocks an RPC client test
    16  func TestNewRPCClient(t *testing.T) {
    17  
    18  	//Test without  a rpc server
    19  	rpchdl := NewRPCWrapper()
    20  	resp := make(chan error, 1)
    21  	go asyncRpcclient(resp, rpchdl)
    22  	select {
    23  	case r := <-resp:
    24  		if r == nil {
    25  			t.Errorf("SUCCESS in the absence of rpc server")
    26  		}
    27  	case <-time.After(1 * time.Second):
    28  		t.Errorf("RPCClient blocked and does not return")
    29  
    30  	}
    31  	err := rpchdl.NewRPCClient("12345", defaultchannel, "mysecret")
    32  	if err == nil {
    33  		t.Errorf("No error returned when there is not server")
    34  	}
    35  
    36  }