github.com/SimplyVC/oasis_api_server/src@v0.0.0-20220105202803-ad2c5a67840e/rpc/rpc_test.go (about)

     1  package rpc_test
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"os"
     7  	"testing"
     8  
     9  	"github.com/SimplyVC/oasis_api_server/src/rpc"
    10  )
    11  
    12  var (
    13  	ctx                  context.Context
    14  	isocket_path         = "unix:/home/vvol/serverdir/node/internal.sock"
    15  	isocket_path_Invalid = "unix:/home/vvol/serverdir/nodes/internal.sock"
    16  )
    17  
    18  func TestMain(m *testing.M) {
    19  	setup()
    20  	code := m.Run()
    21  	teardown()
    22  	os.Exit(code)
    23  }
    24  
    25  func setup() {
    26  	ctx = context.Background()
    27  	fmt.Printf("\033[1;36m%s\033[0m", "> Setup completed\n")
    28  }
    29  
    30  func teardown() {
    31  	ctx = context.Background()
    32  
    33  	fmt.Printf("\033[1;36m%s\033[0m", "> Teardown completed")
    34  	fmt.Printf("\n")
    35  }
    36  
    37  // Testing if Scheduler Client Connects
    38  func TestSchedulerClient_Success(t *testing.T) {
    39  	_, _, err := rpc.SchedulerClient(isocket_path)
    40  	if err != nil {
    41  		t.Errorf("Failed to create SchedulerClient for socket %v got %v",
    42  			isocket_path, err)
    43  	}
    44  }
    45  
    46  // Testing if Node Controller Client Connects
    47  func TestNodeControllerClient_Success(t *testing.T) {
    48  	_, _, err := rpc.NodeControllerClient(isocket_path)
    49  	if err != nil {
    50  		t.Errorf("Failed to create SchedulerClient for socket %v got %v",
    51  			isocket_path, err)
    52  	}
    53  }
    54  
    55  // Testing if Registry Client Connects
    56  func TestRegistryClient_Success(t *testing.T) {
    57  	_, _, err := rpc.RegistryClient(isocket_path)
    58  	if err != nil {
    59  		t.Errorf("Failed to create RegistryClient for socket %v got %v",
    60  			isocket_path, err)
    61  	}
    62  }
    63  
    64  // Testing if Registry Client Connects
    65  func TestStakingClient_Success(t *testing.T) {
    66  	_, _, err := rpc.StakingClient(isocket_path)
    67  	if err != nil {
    68  		t.Errorf("Failed to create StakingClient for socket %v got %v",
    69  			isocket_path, err)
    70  	}
    71  }
    72  
    73  // Testing if Registry Client Connects
    74  func TestConsensusClient_Success(t *testing.T) {
    75  	_, _, err := rpc.ConsensusClient(isocket_path)
    76  	if err != nil {
    77  		t.Errorf("Failed to create ConsensusClient for socket %v got %v",
    78  			isocket_path, err)
    79  	}
    80  }
    81  
    82  // Testing connection function
    83  func TestConnect_Success(t *testing.T) {
    84  	_, err := rpc.Connect(isocket_path)
    85  	if err != nil {
    86  		t.Errorf("Failed to create connection for socket %v got %v",
    87  			isocket_path, err)
    88  	}
    89  }