github.com/marwan-at-work/consul@v1.4.5/agent/status_endpoint_test.go (about)

     1  package agent
     2  
     3  import (
     4  	"net/http"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/consul/testrpc"
     8  )
     9  
    10  func TestStatusLeader(t *testing.T) {
    11  	t.Parallel()
    12  	a := NewTestAgent(t, t.Name(), "")
    13  	defer a.Shutdown()
    14  	testrpc.WaitForLeader(t, a.RPC, "dc1")
    15  
    16  	req, _ := http.NewRequest("GET", "/v1/status/leader", nil)
    17  	obj, err := a.srv.StatusLeader(nil, req)
    18  	if err != nil {
    19  		t.Fatalf("Err: %v", err)
    20  	}
    21  	val := obj.(string)
    22  	if val == "" {
    23  		t.Fatalf("bad addr: %v", obj)
    24  	}
    25  }
    26  
    27  func TestStatusPeers(t *testing.T) {
    28  	t.Parallel()
    29  	a := NewTestAgent(t, t.Name(), "")
    30  	defer a.Shutdown()
    31  
    32  	req, _ := http.NewRequest("GET", "/v1/status/peers", nil)
    33  	obj, err := a.srv.StatusPeers(nil, req)
    34  	if err != nil {
    35  		t.Fatalf("Err: %v", err)
    36  	}
    37  
    38  	peers := obj.([]string)
    39  	if len(peers) != 1 {
    40  		t.Fatalf("bad peers: %v", peers)
    41  	}
    42  }