2017-02-10 01:58:20 +00:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHTTP_OperatorRaftConfiguration(t *testing.T) {
|
2017-07-20 05:42:15 +00:00
|
|
|
t.Parallel()
|
2017-07-20 05:14:36 +00:00
|
|
|
httpTest(t, nil, func(s *TestAgent) {
|
2017-02-10 01:58:20 +00:00
|
|
|
body := bytes.NewBuffer(nil)
|
|
|
|
req, err := http.NewRequest("GET", "/v1/operator/raft/configuration", body)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp := httptest.NewRecorder()
|
|
|
|
obj, err := s.Server.OperatorRaftConfiguration(resp, req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if resp.Code != 200 {
|
|
|
|
t.Fatalf("bad code: %d", resp.Code)
|
|
|
|
}
|
|
|
|
out, ok := obj.(structs.RaftConfigurationResponse)
|
|
|
|
if !ok {
|
|
|
|
t.Fatalf("unexpected: %T", obj)
|
|
|
|
}
|
|
|
|
if len(out.Servers) != 1 ||
|
|
|
|
!out.Servers[0].Leader ||
|
|
|
|
!out.Servers[0].Voter {
|
|
|
|
t.Fatalf("bad: %v", out)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHTTP_OperatorRaftPeer(t *testing.T) {
|
2017-07-20 05:42:15 +00:00
|
|
|
t.Parallel()
|
2017-07-20 05:14:36 +00:00
|
|
|
httpTest(t, nil, func(s *TestAgent) {
|
2017-02-10 01:58:20 +00:00
|
|
|
body := bytes.NewBuffer(nil)
|
|
|
|
req, err := http.NewRequest("DELETE", "/v1/operator/raft/peer?address=nope", body)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get this error, it proves we sent the address all the
|
|
|
|
// way through.
|
|
|
|
resp := httptest.NewRecorder()
|
|
|
|
_, err = s.Server.OperatorRaftPeer(resp, req)
|
|
|
|
if err == nil || !strings.Contains(err.Error(),
|
|
|
|
"address \"nope\" was not found in the Raft configuration") {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|