2015-06-04 11:26:16 +00:00
|
|
|
package nomad
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/net-rpc-msgpackrpc"
|
2015-08-15 19:59:10 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2015-06-04 11:26:16 +00:00
|
|
|
"github.com/hashicorp/nomad/testutil"
|
|
|
|
)
|
|
|
|
|
2015-08-15 19:59:10 +00:00
|
|
|
func TestStatusVersion(t *testing.T) {
|
2017-07-23 22:04:38 +00:00
|
|
|
t.Parallel()
|
2015-08-15 19:59:10 +00:00
|
|
|
s1 := testServer(t, nil)
|
|
|
|
defer s1.Shutdown()
|
|
|
|
codec := rpcClient(t, s1)
|
|
|
|
|
|
|
|
arg := &structs.GenericRequest{
|
|
|
|
QueryOptions: structs.QueryOptions{
|
2015-09-14 01:18:40 +00:00
|
|
|
Region: "global",
|
2015-08-15 19:59:10 +00:00
|
|
|
AllowStale: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
var out structs.VersionResponse
|
|
|
|
if err := msgpackrpc.CallWithCodec(codec, "Status.Version", arg, &out); err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if out.Build == "" {
|
|
|
|
t.Fatalf("bad: %#v", out)
|
|
|
|
}
|
|
|
|
if out.Versions[structs.ProtocolVersion] != ProtocolVersionMax {
|
|
|
|
t.Fatalf("bad: %#v", out)
|
|
|
|
}
|
2016-05-28 01:14:34 +00:00
|
|
|
if out.Versions[structs.APIMajorVersion] != structs.ApiMajorVersion {
|
2015-08-15 19:59:10 +00:00
|
|
|
t.Fatalf("bad: %#v", out)
|
|
|
|
}
|
2016-05-28 01:14:34 +00:00
|
|
|
if out.Versions[structs.APIMinorVersion] != structs.ApiMinorVersion {
|
2015-08-15 19:59:10 +00:00
|
|
|
t.Fatalf("bad: %#v", out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-04 11:26:16 +00:00
|
|
|
func TestStatusPing(t *testing.T) {
|
2017-07-23 22:04:38 +00:00
|
|
|
t.Parallel()
|
2015-06-04 11:26:16 +00:00
|
|
|
s1 := testServer(t, nil)
|
|
|
|
defer s1.Shutdown()
|
|
|
|
codec := rpcClient(t, s1)
|
|
|
|
|
|
|
|
arg := struct{}{}
|
|
|
|
var out struct{}
|
|
|
|
if err := msgpackrpc.CallWithCodec(codec, "Status.Ping", arg, &out); err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStatusLeader(t *testing.T) {
|
2017-07-23 22:04:38 +00:00
|
|
|
t.Parallel()
|
2015-06-04 11:26:16 +00:00
|
|
|
s1 := testServer(t, nil)
|
|
|
|
defer s1.Shutdown()
|
|
|
|
codec := rpcClient(t, s1)
|
2015-08-15 19:59:10 +00:00
|
|
|
testutil.WaitForLeader(t, s1.RPC)
|
2015-06-04 11:26:16 +00:00
|
|
|
|
2015-09-07 01:07:05 +00:00
|
|
|
arg := &structs.GenericRequest{
|
|
|
|
QueryOptions: structs.QueryOptions{
|
2015-09-14 01:18:40 +00:00
|
|
|
Region: "global",
|
2015-09-07 01:07:05 +00:00
|
|
|
AllowStale: true,
|
|
|
|
},
|
|
|
|
}
|
2015-06-04 11:26:16 +00:00
|
|
|
var leader string
|
|
|
|
if err := msgpackrpc.CallWithCodec(codec, "Status.Leader", arg, &leader); err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if leader == "" {
|
|
|
|
t.Fatalf("unexpected leader: %v", leader)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStatusPeers(t *testing.T) {
|
2017-07-23 22:04:38 +00:00
|
|
|
t.Parallel()
|
2015-06-04 11:26:16 +00:00
|
|
|
s1 := testServer(t, nil)
|
|
|
|
defer s1.Shutdown()
|
|
|
|
codec := rpcClient(t, s1)
|
|
|
|
|
2015-09-07 01:07:05 +00:00
|
|
|
arg := &structs.GenericRequest{
|
|
|
|
QueryOptions: structs.QueryOptions{
|
2015-09-14 01:18:40 +00:00
|
|
|
Region: "global",
|
2015-09-07 01:07:05 +00:00
|
|
|
AllowStale: true,
|
|
|
|
},
|
|
|
|
}
|
2015-06-04 11:26:16 +00:00
|
|
|
var peers []string
|
|
|
|
if err := msgpackrpc.CallWithCodec(codec, "Status.Peers", arg, &peers); err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if len(peers) != 1 {
|
|
|
|
t.Fatalf("no peers: %v", peers)
|
|
|
|
}
|
|
|
|
}
|