github.com/ncodes/nomad@v0.5.7-0.20170403112158-97adf4a74fb3/command/agent/operator_endpoint_test.go (about) 1 package agent 2 3 import ( 4 "bytes" 5 "net/http" 6 "net/http/httptest" 7 "strings" 8 "testing" 9 10 "github.com/ncodes/nomad/nomad/structs" 11 ) 12 13 func TestHTTP_OperatorRaftConfiguration(t *testing.T) { 14 httpTest(t, nil, func(s *TestServer) { 15 body := bytes.NewBuffer(nil) 16 req, err := http.NewRequest("GET", "/v1/operator/raft/configuration", body) 17 if err != nil { 18 t.Fatalf("err: %v", err) 19 } 20 21 resp := httptest.NewRecorder() 22 obj, err := s.Server.OperatorRaftConfiguration(resp, req) 23 if err != nil { 24 t.Fatalf("err: %v", err) 25 } 26 if resp.Code != 200 { 27 t.Fatalf("bad code: %d", resp.Code) 28 } 29 out, ok := obj.(structs.RaftConfigurationResponse) 30 if !ok { 31 t.Fatalf("unexpected: %T", obj) 32 } 33 if len(out.Servers) != 1 || 34 !out.Servers[0].Leader || 35 !out.Servers[0].Voter { 36 t.Fatalf("bad: %v", out) 37 } 38 }) 39 } 40 41 func TestHTTP_OperatorRaftPeer(t *testing.T) { 42 httpTest(t, nil, func(s *TestServer) { 43 body := bytes.NewBuffer(nil) 44 req, err := http.NewRequest("DELETE", "/v1/operator/raft/peer?address=nope", body) 45 if err != nil { 46 t.Fatalf("err: %v", err) 47 } 48 49 // If we get this error, it proves we sent the address all the 50 // way through. 51 resp := httptest.NewRecorder() 52 _, err = s.Server.OperatorRaftPeer(resp, req) 53 if err == nil || !strings.Contains(err.Error(), 54 "address \"nope\" was not found in the Raft configuration") { 55 t.Fatalf("err: %v", err) 56 } 57 }) 58 }