github.com/diptanu/nomad@v0.5.7-0.20170516172507-d72e86cbe3d9/nomad/status_endpoint_test.go (about)

     1  package nomad
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hashicorp/net-rpc-msgpackrpc"
     7  	"github.com/hashicorp/nomad/nomad/structs"
     8  	"github.com/hashicorp/nomad/testutil"
     9  )
    10  
    11  func TestStatusVersion(t *testing.T) {
    12  	s1 := testServer(t, nil)
    13  	defer s1.Shutdown()
    14  	codec := rpcClient(t, s1)
    15  
    16  	arg := &structs.GenericRequest{
    17  		QueryOptions: structs.QueryOptions{
    18  			Region:     "global",
    19  			AllowStale: true,
    20  		},
    21  	}
    22  	var out structs.VersionResponse
    23  	if err := msgpackrpc.CallWithCodec(codec, "Status.Version", arg, &out); err != nil {
    24  		t.Fatalf("err: %v", err)
    25  	}
    26  
    27  	if out.Build == "" {
    28  		t.Fatalf("bad: %#v", out)
    29  	}
    30  	if out.Versions[structs.ProtocolVersion] != ProtocolVersionMax {
    31  		t.Fatalf("bad: %#v", out)
    32  	}
    33  	if out.Versions[structs.APIMajorVersion] != structs.ApiMajorVersion {
    34  		t.Fatalf("bad: %#v", out)
    35  	}
    36  	if out.Versions[structs.APIMinorVersion] != structs.ApiMinorVersion {
    37  		t.Fatalf("bad: %#v", out)
    38  	}
    39  }
    40  
    41  func TestStatusPing(t *testing.T) {
    42  	s1 := testServer(t, nil)
    43  	defer s1.Shutdown()
    44  	codec := rpcClient(t, s1)
    45  
    46  	arg := struct{}{}
    47  	var out struct{}
    48  	if err := msgpackrpc.CallWithCodec(codec, "Status.Ping", arg, &out); err != nil {
    49  		t.Fatalf("err: %v", err)
    50  	}
    51  }
    52  
    53  func TestStatusLeader(t *testing.T) {
    54  	s1 := testServer(t, nil)
    55  	defer s1.Shutdown()
    56  	codec := rpcClient(t, s1)
    57  	testutil.WaitForLeader(t, s1.RPC)
    58  
    59  	arg := &structs.GenericRequest{
    60  		QueryOptions: structs.QueryOptions{
    61  			Region:     "global",
    62  			AllowStale: true,
    63  		},
    64  	}
    65  	var leader string
    66  	if err := msgpackrpc.CallWithCodec(codec, "Status.Leader", arg, &leader); err != nil {
    67  		t.Fatalf("err: %v", err)
    68  	}
    69  	if leader == "" {
    70  		t.Fatalf("unexpected leader: %v", leader)
    71  	}
    72  }
    73  
    74  func TestStatusPeers(t *testing.T) {
    75  	s1 := testServer(t, nil)
    76  	defer s1.Shutdown()
    77  	codec := rpcClient(t, s1)
    78  
    79  	arg := &structs.GenericRequest{
    80  		QueryOptions: structs.QueryOptions{
    81  			Region:     "global",
    82  			AllowStale: true,
    83  		},
    84  	}
    85  	var peers []string
    86  	if err := msgpackrpc.CallWithCodec(codec, "Status.Peers", arg, &peers); err != nil {
    87  		t.Fatalf("err: %v", err)
    88  	}
    89  	if len(peers) != 1 {
    90  		t.Fatalf("no peers: %v", peers)
    91  	}
    92  }