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