2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2022-03-25 18:44:16 +00:00
|
|
|
package e2eutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
capi "github.com/hashicorp/consul/api"
|
|
|
|
napi "github.com/hashicorp/nomad/api"
|
2023-01-10 16:39:45 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/useragent"
|
2022-03-25 18:44:16 +00:00
|
|
|
vapi "github.com/hashicorp/vault/api"
|
2023-01-10 16:39:45 +00:00
|
|
|
"github.com/shoenig/test/must"
|
2022-03-25 18:44:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NomadClient creates a default Nomad client based on the env vars
|
|
|
|
// from the test environment. Fails the test if it can't be created
|
|
|
|
func NomadClient(t *testing.T) *napi.Client {
|
|
|
|
client, err := napi.NewClient(napi.DefaultConfig())
|
2023-01-10 16:39:45 +00:00
|
|
|
must.NoError(t, err)
|
2022-03-25 18:44:16 +00:00
|
|
|
return client
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConsulClient creates a default Consul client based on the env vars
|
|
|
|
// from the test environment. Fails the test if it can't be created
|
|
|
|
func ConsulClient(t *testing.T) *capi.Client {
|
|
|
|
client, err := capi.NewClient(capi.DefaultConfig())
|
2023-01-10 16:39:45 +00:00
|
|
|
must.NoError(t, err)
|
2022-03-25 18:44:16 +00:00
|
|
|
return client
|
|
|
|
}
|
|
|
|
|
|
|
|
// VaultClient creates a default Vault client based on the env vars
|
|
|
|
// from the test environment. Fails the test if it can't be created
|
|
|
|
func VaultClient(t *testing.T) *vapi.Client {
|
|
|
|
client, err := vapi.NewClient(vapi.DefaultConfig())
|
2023-01-10 16:39:45 +00:00
|
|
|
useragent.SetHeaders(client)
|
|
|
|
must.NoError(t, err)
|
2022-03-25 18:44:16 +00:00
|
|
|
return client
|
|
|
|
}
|