Skip to content

Commit

Permalink
api: run ACL tests by default
Browse files Browse the repository at this point in the history
  • Loading branch information
gogolok committed Jun 13, 2015
1 parent 8ffa0ea commit 2b8d0c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
38 changes: 7 additions & 31 deletions api/acl_test.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
package api

import (
"os"
"testing"
)

// ROOT is a management token for the tests
var CONSUL_ROOT string

func init() {
CONSUL_ROOT = os.Getenv("CONSUL_ROOT")
}

func TestACL_CreateDestroy(t *testing.T) {
t.Parallel()
if CONSUL_ROOT == "" {
t.SkipNow()
}
c, s := makeClient(t)
c, s := makeACLClient(t)
defer s.Stop()

c.config.Token = CONSUL_ROOT
acl := c.ACL()

ae := ACLEntry{
Expand Down Expand Up @@ -63,16 +51,12 @@ func TestACL_CreateDestroy(t *testing.T) {

func TestACL_CloneDestroy(t *testing.T) {
t.Parallel()
if CONSUL_ROOT == "" {
t.SkipNow()
}
c, s := makeClient(t)
c, s := makeACLClient(t)
defer s.Stop()

c.config.Token = CONSUL_ROOT
acl := c.ACL()

id, wm, err := acl.Clone(CONSUL_ROOT, nil)
id, wm, err := acl.Clone(c.config.Token, nil)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand All @@ -97,16 +81,12 @@ func TestACL_CloneDestroy(t *testing.T) {

func TestACL_Info(t *testing.T) {
t.Parallel()
if CONSUL_ROOT == "" {
t.SkipNow()
}
c, s := makeClient(t)
c, s := makeACLClient(t)
defer s.Stop()

c.config.Token = CONSUL_ROOT
acl := c.ACL()

ae, qm, err := acl.Info(CONSUL_ROOT, nil)
ae, qm, err := acl.Info(c.config.Token, nil)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand All @@ -118,20 +98,16 @@ func TestACL_Info(t *testing.T) {
t.Fatalf("bad: %v", qm)
}

if ae == nil || ae.ID != CONSUL_ROOT || ae.Type != ACLManagementType {
if ae == nil || ae.ID != c.config.Token || ae.Type != ACLManagementType {
t.Fatalf("bad: %#v", ae)
}
}

func TestACL_List(t *testing.T) {
t.Parallel()
if CONSUL_ROOT == "" {
t.SkipNow()
}
c, s := makeClient(t)
c, s := makeACLClient(t)
defer s.Stop()

c.config.Token = CONSUL_ROOT
acl := c.ACL()

acls, qm, err := acl.List(nil)
Expand Down
10 changes: 10 additions & 0 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ func makeClient(t *testing.T) (*Client, *testutil.TestServer) {
return makeClientWithConfig(t, nil, nil)
}

func makeACLClient(t *testing.T) (*Client, *testutil.TestServer) {
return makeClientWithConfig(t, func(clientConfig *Config) {
clientConfig.Token = "root"
}, func(serverConfig *testutil.TestServerConfig) {
serverConfig.ACLMasterToken = "root"
serverConfig.ACLDatacenter = "dc1"
serverConfig.ACLDefaultPolicy = "deny"
})
}

func makeClientWithConfig(
t *testing.T,
cb1 configCallback,
Expand Down

0 comments on commit 2b8d0c4

Please sign in to comment.