13dab7dd24
* Divest api/ package of deps elsewhere in the nomad repo. This will allow making api/ a module without then pulling in the external repo, leading to a package name conflict. This required some migration of tests to an apitests/ folder (can be moved anywhere as it has no deps on it). It also required some duplication of code, notably some test helpers from api/ -> apitests/ and part (but not all) of testutil/ -> api/testutil/. Once there's more separation and an e.g. sdk/ folder those can be removed in favor of a dep on the sdk/ folder, provided the sdk/ folder doesn't depend on api/ or /. * Also remove consul dep from api/ package * Fix stupid linters * Some restructuring
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package apitests
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/nomad/api"
|
|
"github.com/hashicorp/nomad/testutil"
|
|
)
|
|
|
|
type configCallback func(c *api.Config)
|
|
|
|
// seen is used to track which tests we have already marked as parallel
|
|
var seen map[*testing.T]struct{}
|
|
|
|
func init() {
|
|
seen = make(map[*testing.T]struct{})
|
|
}
|
|
|
|
func makeACLClient(t *testing.T, cb1 configCallback,
|
|
cb2 testutil.ServerConfigCallback) (*api.Client, *testutil.TestServer, *api.ACLToken) {
|
|
client, server := makeClient(t, cb1, func(c *testutil.TestServerConfig) {
|
|
c.ACL.Enabled = true
|
|
if cb2 != nil {
|
|
cb2(c)
|
|
}
|
|
})
|
|
|
|
// Get the root token
|
|
root, _, err := client.ACLTokens().Bootstrap(nil)
|
|
if err != nil {
|
|
t.Fatalf("failed to bootstrap ACLs: %v", err)
|
|
}
|
|
client.SetSecretID(root.SecretID)
|
|
return client, server, root
|
|
}
|
|
|
|
func makeClient(t *testing.T, cb1 configCallback,
|
|
cb2 testutil.ServerConfigCallback) (*api.Client, *testutil.TestServer) {
|
|
// Make client config
|
|
conf := api.DefaultConfig()
|
|
if cb1 != nil {
|
|
cb1(conf)
|
|
}
|
|
|
|
// Create server
|
|
server := testutil.NewTestServer(t, cb2)
|
|
conf.Address = "http://" + server.HTTPAddr
|
|
|
|
// Create client
|
|
client, err := api.NewClient(conf)
|
|
if err != nil {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
|
|
return client, server
|
|
}
|