Merge pull request #1030 from gogolok/api_run_acl_tests_by_default

api: run ACL tests by default
This commit is contained in:
Ryan Uber 2015-06-13 23:10:57 -07:00
commit e3b3c99801
2 changed files with 17 additions and 31 deletions

View File

@ -1,26 +1,14 @@
package api package api
import ( import (
"os"
"testing" "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) { func TestACL_CreateDestroy(t *testing.T) {
t.Parallel() t.Parallel()
if CONSUL_ROOT == "" { c, s := makeACLClient(t)
t.SkipNow()
}
c, s := makeClient(t)
defer s.Stop() defer s.Stop()
c.config.Token = CONSUL_ROOT
acl := c.ACL() acl := c.ACL()
ae := ACLEntry{ ae := ACLEntry{
@ -63,16 +51,12 @@ func TestACL_CreateDestroy(t *testing.T) {
func TestACL_CloneDestroy(t *testing.T) { func TestACL_CloneDestroy(t *testing.T) {
t.Parallel() t.Parallel()
if CONSUL_ROOT == "" { c, s := makeACLClient(t)
t.SkipNow()
}
c, s := makeClient(t)
defer s.Stop() defer s.Stop()
c.config.Token = CONSUL_ROOT
acl := c.ACL() acl := c.ACL()
id, wm, err := acl.Clone(CONSUL_ROOT, nil) id, wm, err := acl.Clone(c.config.Token, nil)
if err != nil { if err != nil {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
@ -97,16 +81,12 @@ func TestACL_CloneDestroy(t *testing.T) {
func TestACL_Info(t *testing.T) { func TestACL_Info(t *testing.T) {
t.Parallel() t.Parallel()
if CONSUL_ROOT == "" { c, s := makeACLClient(t)
t.SkipNow()
}
c, s := makeClient(t)
defer s.Stop() defer s.Stop()
c.config.Token = CONSUL_ROOT
acl := c.ACL() acl := c.ACL()
ae, qm, err := acl.Info(CONSUL_ROOT, nil) ae, qm, err := acl.Info(c.config.Token, nil)
if err != nil { if err != nil {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
@ -118,20 +98,16 @@ func TestACL_Info(t *testing.T) {
t.Fatalf("bad: %v", qm) 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) t.Fatalf("bad: %#v", ae)
} }
} }
func TestACL_List(t *testing.T) { func TestACL_List(t *testing.T) {
t.Parallel() t.Parallel()
if CONSUL_ROOT == "" { c, s := makeACLClient(t)
t.SkipNow()
}
c, s := makeClient(t)
defer s.Stop() defer s.Stop()
c.config.Token = CONSUL_ROOT
acl := c.ACL() acl := c.ACL()
acls, qm, err := acl.List(nil) acls, qm, err := acl.List(nil)

View File

@ -20,6 +20,16 @@ func makeClient(t *testing.T) (*Client, *testutil.TestServer) {
return makeClientWithConfig(t, nil, nil) 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( func makeClientWithConfig(
t *testing.T, t *testing.T,
cb1 configCallback, cb1 configCallback,