github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/internal/testing/apitests/api_test.go (about) 1 package apitests 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/nomad/api" 7 "github.com/hashicorp/nomad/testutil" 8 ) 9 10 type configCallback func(c *api.Config) 11 12 // seen is used to track which tests we have already marked as parallel 13 var seen map[*testing.T]struct{} 14 15 func init() { 16 seen = make(map[*testing.T]struct{}) 17 } 18 19 func makeACLClient(t *testing.T, cb1 configCallback, 20 cb2 testutil.ServerConfigCallback) (*api.Client, *testutil.TestServer, *api.ACLToken) { 21 client, server := makeClient(t, cb1, func(c *testutil.TestServerConfig) { 22 c.ACL.Enabled = true 23 if cb2 != nil { 24 cb2(c) 25 } 26 }) 27 28 // Get the root token 29 root, _, err := client.ACLTokens().Bootstrap(nil) 30 if err != nil { 31 t.Fatalf("failed to bootstrap ACLs: %v", err) 32 } 33 client.SetSecretID(root.SecretID) 34 return client, server, root 35 } 36 37 func makeClient(t *testing.T, cb1 configCallback, 38 cb2 testutil.ServerConfigCallback) (*api.Client, *testutil.TestServer) { 39 // Make client config 40 conf := api.DefaultConfig() 41 if cb1 != nil { 42 cb1(conf) 43 } 44 45 // Create server 46 server := testutil.NewTestServer(t, cb2) 47 conf.Address = "http://" + server.HTTPAddr 48 49 // Create client 50 client, err := api.NewClient(conf) 51 if err != nil { 52 t.Fatalf("err: %v", err) 53 } 54 55 return client, server 56 }