test: refactor TestAgent_Leave_ACLDeny to use only one server

This commit is contained in:
Frank Schroeder 2017-05-10 09:08:39 +02:00 committed by Frank Schröder
parent a60f508880
commit 5328609d59
1 changed files with 14 additions and 23 deletions

View File

@ -550,40 +550,31 @@ func TestAgent_Leave(t *testing.T) {
}
func TestAgent_Leave_ACLDeny(t *testing.T) {
t.Run("no token", func(t *testing.T) {
dir, srv := makeHTTPServerWithACLs(t)
defer os.RemoveAll(dir)
defer srv.Shutdown()
defer srv.agent.Shutdown()
dir, srv := makeHTTPServerWithACLs(t)
defer os.RemoveAll(dir)
defer srv.Shutdown()
defer srv.agent.Shutdown()
t.Run("no token", func(t *testing.T) {
req, _ := http.NewRequest("PUT", "/v1/agent/leave", nil)
if _, err := srv.AgentLeave(nil, req); !isPermissionDenied(err) {
t.Fatalf("err: %v", err)
}
})
t.Run("agent master token", func(t *testing.T) {
dir, srv := makeHTTPServerWithACLs(t)
defer os.RemoveAll(dir)
defer srv.Shutdown()
defer srv.agent.Shutdown()
req, _ := http.NewRequest("PUT", "/v1/agent/leave?token=towel", nil)
if _, err := srv.AgentLeave(nil, req); err != nil {
t.Run("read-only token", func(t *testing.T) {
ro := makeReadOnlyAgentACL(t, srv)
req, _ := http.NewRequest("PUT", fmt.Sprintf("/v1/agent/leave?token=%s", ro), nil)
if _, err := srv.AgentLeave(nil, req); !isPermissionDenied(err) {
t.Fatalf("err: %v", err)
}
})
// this test fails when all subtests share the same server.
t.Run("read-only token", func(t *testing.T) {
dir, srv := makeHTTPServerWithACLs(t)
defer os.RemoveAll(dir)
defer srv.Shutdown()
defer srv.agent.Shutdown()
ro := makeReadOnlyAgentACL(t, srv)
req, _ := http.NewRequest("PUT", fmt.Sprintf("/v1/agent/leave?token=%s", ro), nil)
if _, err := srv.AgentLeave(nil, req); !isPermissionDenied(err) {
// this sub-test will change the state so that there is no leader.
// it must therefore be the last one in this list.
t.Run("agent master token", func(t *testing.T) {
req, _ := http.NewRequest("PUT", "/v1/agent/leave?token=towel", nil)
if _, err := srv.AgentLeave(nil, req); err != nil {
t.Fatalf("err: %v", err)
}
})