Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First big step towards solving issues 2217 and 2465 #3037

Merged
merged 61 commits into from
May 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
2a39c48
test: capture stderr in test.log
magiconair May 21, 2017
eded493
test: sanitize temp dir names since subtest names have slashes
magiconair May 19, 2017
1d5b56e
test: shutdown server properly
magiconair May 19, 2017
c47db2c
agent: drop config argument
magiconair May 11, 2017
8f381d6
agent: drop logOutput parameter
magiconair May 11, 2017
327401e
agent: inline uiDir field
magiconair May 11, 2017
c44e41a
agent: replace goto with local function
magiconair May 11, 2017
b42916e
agent: simplify socket address helper
magiconair May 11, 2017
74be791
agent: fix comment
magiconair May 19, 2017
82650f7
agent: move http/dns endpoints into agent
magiconair May 19, 2017
3865f14
agent: simplify agent creation
magiconair May 19, 2017
b5b3aa1
agent: add TestAgent to replace other mechanisms
magiconair May 21, 2017
23a6ff3
agent: refactor tests for TestAgent
magiconair May 21, 2017
308f992
test: run agent tests in parallel
magiconair May 21, 2017
0be63d7
test: refactor httpTest with TestAgent
magiconair May 21, 2017
0c905a0
test: a.config -> a.Config
magiconair May 21, 2017
4750130
test: use system temp dir for TestAgent
magiconair May 21, 2017
0667770
test: use less aggressive retry for agent startup
magiconair May 21, 2017
141efd9
test: rename *Config vars to 'cfg'
magiconair May 22, 2017
e86d346
agent: rename *Command vars to 'cmd'
magiconair May 22, 2017
659d7db
agent: rename *Config vars to 'cfg'
magiconair May 22, 2017
24eec37
test: retry a bit more often
magiconair May 22, 2017
53c1c86
test: refactor command tests to use TestAgent
magiconair May 22, 2017
bc47972
test: allocate ports in blocks of 10
magiconair May 22, 2017
0f912c8
test: remove ACL options from default test config
magiconair May 22, 2017
3658d4d
test: address pull request comments
magiconair May 22, 2017
9509ab4
test: run command tests in parallel
magiconair May 22, 2017
53fd150
build: add target for running tests with race detector
magiconair May 22, 2017
3caadb3
vendor: update github.com/mitchellh/cli
magiconair May 23, 2017
d5f87a2
vendor: fix data race in github.com/armon/go-metrics/start.go
magiconair May 22, 2017
5846934
test: fix data race in MockNotify
magiconair May 22, 2017
8c1a668
test: Shutdown half-started agent before retrying
magiconair May 22, 2017
632f837
agent: shutdown dns servers on error
magiconair May 22, 2017
e16589c
agent: shutdown delegate if created
magiconair May 22, 2017
0325a42
test: fix data race with endpoints
magiconair May 22, 2017
b56ffc9
test: run consul tests in parallel
magiconair May 22, 2017
8f94354
test: use cli.NewMockUi instead of new(cli.MockUi)
magiconair May 22, 2017
c5f565e
test: remove output to stdout
magiconair May 22, 2017
72c214b
test: fix failing test
magiconair May 22, 2017
ebc0c80
test: parallelize dns test
magiconair May 23, 2017
28ed8f1
test: perform blocking query on agent
magiconair May 23, 2017
5b5566d
test: add test name to output
magiconair May 23, 2017
2e14c09
test: start sync after agent start
magiconair May 23, 2017
f15e90b
consul: use correct shutdownCh for Router
magiconair May 23, 2017
1df74e3
agent: print more useful shutdown message
magiconair May 23, 2017
3e39f04
dns: do not log socket close during shutdown
magiconair May 23, 2017
fe77785
test: call t.Fatal() from main go routine
magiconair May 23, 2017
10540f8
agent: fix logging
magiconair May 23, 2017
0a31094
test: improve TestAgent
magiconair May 23, 2017
7c5892a
test: use UniqueID prefix for check tests to unify log output
magiconair May 23, 2017
56cf015
test: add test for starting/stopping lots of agents
magiconair May 23, 2017
6148910
test: skip tests that use cmd.Run until signal handling is fixed
magiconair May 23, 2017
eea16e1
test: run mock dns recursors on random ports
magiconair May 23, 2017
f498f24
test: allow tests to control anti-entropy syncs
magiconair May 23, 2017
aa92adc
test: increase sleep time for test
magiconair May 23, 2017
205cbe5
build: update makefile
magiconair May 24, 2017
c068066
vendor: patch github.com/mitchellh/cli until help output is fixed
magiconair May 24, 2017
f4aa2ad
test: fail if there is no leader
magiconair May 24, 2017
b6c69eb
agent: refactor DNS and HTTP server
magiconair May 24, 2017
2620092
agent: start HTTPS only if there is a cert and key
magiconair May 24, 2017
ec72969
Address review comments
magiconair May 30, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ cov:

test: dev
go test -tags "$(GOTAGS)" -i -run '^$$' ./...
( set -o pipefail ; go test -tags "$(GOTAGS)" -v ./... | tee test.log )
go test -tags "$(GOTAGS)" -v $$(go list ./... | egrep -v '(consul/consul|vendor)') > test.log 2>&1 || true
go test -tags "$(GOTAGS)" -v github.com/hashicorp/consul/consul >> test.log 2>&1 || true
@if [ "$$TRAVIS" == "true" ] ; then cat test.log ; fi
@if grep -q 'FAIL:' test.log ; then grep 'FAIL:' test.log ; exit 1 ; else echo 'PASS' ; fi

test-race: dev
go test -tags "$(GOTAGS)" -i -run '^$$' ./...
( set -o pipefail ; go test -race -tags "$(GOTAGS)" -v ./... 2>&1 | tee test-race.log )

cover:
go test $(GOFILES) --cover
Expand Down
301 changes: 160 additions & 141 deletions command/agent/acl_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,126 +30,138 @@ func makeTestACL(t *testing.T, srv *HTTPServer) string {
return aclResp.ID
}

func TestACLUpdate(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
id := makeTestACL(t, srv)

body := bytes.NewBuffer(nil)
enc := json.NewEncoder(body)
raw := map[string]interface{}{
"ID": id,
"Name": "User Token 2",
"Type": "client",
"Rules": "",
}
enc.Encode(raw)
func TestACL_Update(t *testing.T) {
t.Parallel()
a := NewTestAgent(t.Name(), TestACLConfig())
defer a.Shutdown()

req, _ := http.NewRequest("PUT", "/v1/acl/update?token=root", body)
resp := httptest.NewRecorder()
obj, err := srv.ACLUpdate(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
aclResp := obj.(aclCreateResponse)
if aclResp.ID != id {
t.Fatalf("bad: %v", aclResp)
}
})
id := makeTestACL(t, a.srv)

body := bytes.NewBuffer(nil)
enc := json.NewEncoder(body)
raw := map[string]interface{}{
"ID": id,
"Name": "User Token 2",
"Type": "client",
"Rules": "",
}
enc.Encode(raw)

req, _ := http.NewRequest("PUT", "/v1/acl/update?token=root", body)
resp := httptest.NewRecorder()
obj, err := a.srv.ACLUpdate(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
aclResp := obj.(aclCreateResponse)
if aclResp.ID != id {
t.Fatalf("bad: %v", aclResp)
}
}

func TestACLUpdate_Upsert(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
body := bytes.NewBuffer(nil)
enc := json.NewEncoder(body)
raw := map[string]interface{}{
"ID": "my-old-id",
"Name": "User Token 2",
"Type": "client",
"Rules": "",
}
enc.Encode(raw)
func TestACL_UpdateUpsert(t *testing.T) {
t.Parallel()
a := NewTestAgent(t.Name(), TestACLConfig())
defer a.Shutdown()

req, _ := http.NewRequest("PUT", "/v1/acl/update?token=root", body)
resp := httptest.NewRecorder()
obj, err := srv.ACLUpdate(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
aclResp := obj.(aclCreateResponse)
if aclResp.ID != "my-old-id" {
t.Fatalf("bad: %v", aclResp)
}
})
body := bytes.NewBuffer(nil)
enc := json.NewEncoder(body)
raw := map[string]interface{}{
"ID": "my-old-id",
"Name": "User Token 2",
"Type": "client",
"Rules": "",
}
enc.Encode(raw)

req, _ := http.NewRequest("PUT", "/v1/acl/update?token=root", body)
resp := httptest.NewRecorder()
obj, err := a.srv.ACLUpdate(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
aclResp := obj.(aclCreateResponse)
if aclResp.ID != "my-old-id" {
t.Fatalf("bad: %v", aclResp)
}
}

func TestACLDestroy(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
id := makeTestACL(t, srv)
req, _ := http.NewRequest("PUT", "/v1/acl/destroy/"+id+"?token=root", nil)
resp := httptest.NewRecorder()
obj, err := srv.ACLDestroy(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
if resp, ok := obj.(bool); !ok || !resp {
t.Fatalf("should work")
}
func TestACL_Destroy(t *testing.T) {
t.Parallel()
a := NewTestAgent(t.Name(), TestACLConfig())
defer a.Shutdown()

req, _ = http.NewRequest("GET", "/v1/acl/info/"+id, nil)
resp = httptest.NewRecorder()
obj, err = srv.ACLGet(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
respObj, ok := obj.(structs.ACLs)
if !ok {
t.Fatalf("should work")
}
if len(respObj) != 0 {
t.Fatalf("bad: %v", respObj)
}
})
id := makeTestACL(t, a.srv)
req, _ := http.NewRequest("PUT", "/v1/acl/destroy/"+id+"?token=root", nil)
resp := httptest.NewRecorder()
obj, err := a.srv.ACLDestroy(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
if resp, ok := obj.(bool); !ok || !resp {
t.Fatalf("should work")
}

req, _ = http.NewRequest("GET", "/v1/acl/info/"+id, nil)
resp = httptest.NewRecorder()
obj, err = a.srv.ACLGet(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
respObj, ok := obj.(structs.ACLs)
if !ok {
t.Fatalf("should work")
}
if len(respObj) != 0 {
t.Fatalf("bad: %v", respObj)
}
}

func TestACLClone(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
id := makeTestACL(t, srv)
func TestACL_Clone(t *testing.T) {
t.Parallel()
a := NewTestAgent(t.Name(), TestACLConfig())
defer a.Shutdown()

req, _ := http.NewRequest("PUT", "/v1/acl/clone/"+id+"?token=root", nil)
resp := httptest.NewRecorder()
obj, err := srv.ACLClone(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
aclResp, ok := obj.(aclCreateResponse)
if !ok {
t.Fatalf("should work: %#v %#v", obj, resp)
}
if aclResp.ID == id {
t.Fatalf("bad id")
}
id := makeTestACL(t, a.srv)

req, _ = http.NewRequest("GET", "/v1/acl/info/"+aclResp.ID, nil)
resp = httptest.NewRecorder()
obj, err = srv.ACLGet(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
respObj, ok := obj.(structs.ACLs)
if !ok {
t.Fatalf("should work")
}
if len(respObj) != 1 {
t.Fatalf("bad: %v", respObj)
}
})
req, _ := http.NewRequest("PUT", "/v1/acl/clone/"+id+"?token=root", nil)
resp := httptest.NewRecorder()
obj, err := a.srv.ACLClone(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
aclResp, ok := obj.(aclCreateResponse)
if !ok {
t.Fatalf("should work: %#v %#v", obj, resp)
}
if aclResp.ID == id {
t.Fatalf("bad id")
}

req, _ = http.NewRequest("GET", "/v1/acl/info/"+aclResp.ID, nil)
resp = httptest.NewRecorder()
obj, err = a.srv.ACLGet(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
respObj, ok := obj.(structs.ACLs)
if !ok {
t.Fatalf("should work")
}
if len(respObj) != 1 {
t.Fatalf("bad: %v", respObj)
}
}

func TestACLGet(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
func TestACL_Get(t *testing.T) {
t.Parallel()
t.Run("wrong id", func(t *testing.T) {
a := NewTestAgent(t.Name(), TestACLConfig())
defer a.Shutdown()

req, _ := http.NewRequest("GET", "/v1/acl/info/nope", nil)
resp := httptest.NewRecorder()
obj, err := srv.ACLGet(resp, req)
obj, err := a.srv.ACLGet(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand All @@ -162,12 +174,15 @@ func TestACLGet(t *testing.T) {
}
})

httpTest(t, func(srv *HTTPServer) {
id := makeTestACL(t, srv)
t.Run("right id", func(t *testing.T) {
a := NewTestAgent(t.Name(), TestACLConfig())
defer a.Shutdown()

id := makeTestACL(t, a.srv)

req, _ := http.NewRequest("GET", "/v1/acl/info/"+id, nil)
resp := httptest.NewRecorder()
obj, err := srv.ACLGet(resp, req)
obj, err := a.srv.ACLGet(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand All @@ -181,42 +196,46 @@ func TestACLGet(t *testing.T) {
})
}

func TestACLList(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
var ids []string
for i := 0; i < 10; i++ {
ids = append(ids, makeTestACL(t, srv))
}
func TestACL_List(t *testing.T) {
t.Parallel()
a := NewTestAgent(t.Name(), TestACLConfig())
defer a.Shutdown()

req, _ := http.NewRequest("GET", "/v1/acl/list?token=root", nil)
resp := httptest.NewRecorder()
obj, err := srv.ACLList(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
respObj, ok := obj.(structs.ACLs)
if !ok {
t.Fatalf("should work")
}
var ids []string
for i := 0; i < 10; i++ {
ids = append(ids, makeTestACL(t, a.srv))
}

// 10 + anonymous + master
if len(respObj) != 12 {
t.Fatalf("bad: %v", respObj)
}
})
req, _ := http.NewRequest("GET", "/v1/acl/list?token=root", nil)
resp := httptest.NewRecorder()
obj, err := a.srv.ACLList(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
respObj, ok := obj.(structs.ACLs)
if !ok {
t.Fatalf("should work")
}

// 10 + anonymous + master
if len(respObj) != 12 {
t.Fatalf("bad: %v", respObj)
}
}

func TestACLReplicationStatus(t *testing.T) {
httpTest(t, func(srv *HTTPServer) {
req, _ := http.NewRequest("GET", "/v1/acl/replication", nil)
resp := httptest.NewRecorder()
obj, err := srv.ACLReplicationStatus(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
_, ok := obj.(structs.ACLReplicationStatus)
if !ok {
t.Fatalf("should work")
}
})
t.Parallel()
a := NewTestAgent(t.Name(), nil)
defer a.Shutdown()

req, _ := http.NewRequest("GET", "/v1/acl/replication", nil)
resp := httptest.NewRecorder()
obj, err := a.srv.ACLReplicationStatus(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
_, ok := obj.(structs.ACLReplicationStatus)
if !ok {
t.Fatalf("should work")
}
}
Loading