Merge pull request #12733 from hashicorp/jbardin/consul-acc-tests
Revert "Have the consul provider use a local test server"
This commit is contained in:
commit
a4ba2b27fd
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
func TestAccDataConsulAgentSelf_basic(t *testing.T) {
|
func TestAccDataConsulAgentSelf_basic(t *testing.T) {
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
|
@ -24,8 +25,7 @@ func TestAccDataConsulAgentSelf_basic(t *testing.T) {
|
||||||
testAccCheckDataSourceValue("data.consul_agent_self.read", "advertise_addr", "<any>"),
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "advertise_addr", "<any>"),
|
||||||
testAccCheckDataSourceValue("data.consul_agent_self.read", "bind_addr", "<any>"),
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "bind_addr", "<any>"),
|
||||||
testAccCheckDataSourceValue("data.consul_agent_self.read", "bootstrap_expect", "<all>"),
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "bootstrap_expect", "<all>"),
|
||||||
// the local test server is bootstrapped
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "bootstrap_mode", "false"),
|
||||||
testAccCheckDataSourceValue("data.consul_agent_self.read", "bootstrap_mode", "true"),
|
|
||||||
testAccCheckDataSourceValue("data.consul_agent_self.read", "client_addr", "<any>"),
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "client_addr", "<any>"),
|
||||||
testAccCheckDataSourceValue("data.consul_agent_self.read", "datacenter", "<any>"),
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "datacenter", "<any>"),
|
||||||
testAccCheckDataSourceValue("data.consul_agent_self.read", "dev_mode", "<any>"),
|
testAccCheckDataSourceValue("data.consul_agent_self.read", "dev_mode", "<any>"),
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
func TestAccDataConsulCatalogNodes_basic(t *testing.T) {
|
func TestAccDataConsulCatalogNodes_basic(t *testing.T) {
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
func TestAccDataConsulCatalogService_basic(t *testing.T) {
|
func TestAccDataConsulCatalogService_basic(t *testing.T) {
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
func TestAccDataConsulCatalogServices_basic(t *testing.T) {
|
func TestAccDataConsulCatalogServices_basic(t *testing.T) {
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
func TestAccDataConsulKeys_basic(t *testing.T) {
|
func TestAccDataConsulKeys_basic(t *testing.T) {
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
func TestAccConsulKeyPrefix_basic(t *testing.T) {
|
func TestAccConsulKeyPrefix_basic(t *testing.T) {
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: resource.ComposeTestCheckFunc(
|
CheckDestroy: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckConsulKeyPrefixKeyAbsent("species"),
|
testAccCheckConsulKeyPrefixKeyAbsent("species"),
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
func TestAccConsulKeys_basic(t *testing.T) {
|
func TestAccConsulKeys_basic(t *testing.T) {
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckConsulKeysDestroy,
|
CheckDestroy: testAccCheckConsulKeysDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
func TestAccConsulPreparedQuery_basic(t *testing.T) {
|
func TestAccConsulPreparedQuery_basic(t *testing.T) {
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckConsulPreparedQueryDestroy,
|
CheckDestroy: testAccCheckConsulPreparedQueryDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
|
|
|
@ -1,64 +1,24 @@
|
||||||
package consul
|
package consul
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/testutil"
|
|
||||||
"github.com/hashicorp/terraform/config"
|
"github.com/hashicorp/terraform/config"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
"github.com/mitchellh/mapstructure"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var testAccProviders map[string]terraform.ResourceProvider
|
var testAccProviders map[string]terraform.ResourceProvider
|
||||||
var testAccProvider *schema.Provider
|
var testAccProvider *schema.Provider
|
||||||
var testConsulHTTPAddr string
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
testAccProvider = Provider().(*schema.Provider)
|
testAccProvider = Provider().(*schema.Provider)
|
||||||
testAccProvider.ConfigureFunc = testProviderConfigure
|
|
||||||
|
|
||||||
testAccProviders = map[string]terraform.ResourceProvider{
|
testAccProviders = map[string]terraform.ResourceProvider{
|
||||||
"consul": testAccProvider,
|
"consul": testAccProvider,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need to overrride the configured address for the tests
|
|
||||||
func testProviderConfigure(d *schema.ResourceData) (interface{}, error) {
|
|
||||||
var config Config
|
|
||||||
configRaw := d.Get("").(map[string]interface{})
|
|
||||||
if err := mapstructure.Decode(configRaw, &config); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
config.Address = testConsulHTTPAddr
|
|
||||||
|
|
||||||
log.Printf("[INFO] Initializing Consul test client")
|
|
||||||
return config.Client()
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
|
||||||
t := struct {
|
|
||||||
testutil.TestingT
|
|
||||||
}{}
|
|
||||||
|
|
||||||
// start and stop the test consul server once for all tests
|
|
||||||
srv := testutil.NewTestServerConfig(t, func(c *testutil.TestServerConfig) {
|
|
||||||
c.LogLevel = "warn"
|
|
||||||
c.Stdout = ioutil.Discard
|
|
||||||
c.Stderr = ioutil.Discard
|
|
||||||
})
|
|
||||||
|
|
||||||
testConsulHTTPAddr = srv.HTTPAddr
|
|
||||||
|
|
||||||
ret := m.Run()
|
|
||||||
|
|
||||||
srv.Stop()
|
|
||||||
os.Exit(ret)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestResourceProvider(t *testing.T) {
|
func TestResourceProvider(t *testing.T) {
|
||||||
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
|
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
|
@ -72,9 +32,8 @@ func TestResourceProvider_impl(t *testing.T) {
|
||||||
func TestResourceProvider_Configure(t *testing.T) {
|
func TestResourceProvider_Configure(t *testing.T) {
|
||||||
rp := Provider()
|
rp := Provider()
|
||||||
|
|
||||||
// these configuration tests don't require an running server
|
|
||||||
raw := map[string]interface{}{
|
raw := map[string]interface{}{
|
||||||
"address": "example.com:8500",
|
"address": "demo.consul.io:80",
|
||||||
"datacenter": "nyc3",
|
"datacenter": "nyc3",
|
||||||
"scheme": "https",
|
"scheme": "https",
|
||||||
}
|
}
|
||||||
|
@ -94,7 +53,7 @@ func TestResourceProvider_ConfigureTLS(t *testing.T) {
|
||||||
rp := Provider()
|
rp := Provider()
|
||||||
|
|
||||||
raw := map[string]interface{}{
|
raw := map[string]interface{}{
|
||||||
"address": "example.com:8943",
|
"address": "demo.consul.io:80",
|
||||||
"ca_file": "test-fixtures/cacert.pem",
|
"ca_file": "test-fixtures/cacert.pem",
|
||||||
"cert_file": "test-fixtures/usercert.pem",
|
"cert_file": "test-fixtures/usercert.pem",
|
||||||
"datacenter": "nyc3",
|
"datacenter": "nyc3",
|
||||||
|
@ -112,3 +71,13 @@ func TestResourceProvider_ConfigureTLS(t *testing.T) {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccPreCheck(t *testing.T) {
|
||||||
|
if v := os.Getenv("CONSUL_HTTP_ADDR"); v != "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if v := os.Getenv("CONSUL_ADDRESS"); v != "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Fatal("Either CONSUL_ADDRESS or CONSUL_HTTP_ADDR must be set for acceptance tests")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue