2014-07-26 04:14:48 +02:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
2016-01-21 21:54:56 +01:00
|
|
|
"os"
|
2014-07-26 04:14:48 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/config"
|
2014-10-13 20:35:45 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
2014-07-26 04:14:48 +02:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
var testAccProviders map[string]terraform.ResourceProvider
|
2014-10-13 20:35:45 +02:00
|
|
|
var testAccProvider *schema.Provider
|
2014-07-26 04:14:48 +02:00
|
|
|
|
|
|
|
func init() {
|
2014-10-13 20:35:45 +02:00
|
|
|
testAccProvider = Provider().(*schema.Provider)
|
2014-07-26 04:14:48 +02:00
|
|
|
testAccProviders = map[string]terraform.ResourceProvider{
|
|
|
|
"consul": testAccProvider,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-13 20:35:45 +02:00
|
|
|
func TestResourceProvider(t *testing.T) {
|
|
|
|
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-26 04:14:48 +02:00
|
|
|
func TestResourceProvider_impl(t *testing.T) {
|
2014-10-13 20:35:45 +02:00
|
|
|
var _ terraform.ResourceProvider = Provider()
|
2014-07-26 04:14:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestResourceProvider_Configure(t *testing.T) {
|
2014-10-13 20:35:45 +02:00
|
|
|
rp := Provider()
|
2014-07-26 04:14:48 +02:00
|
|
|
|
|
|
|
raw := map[string]interface{}{
|
|
|
|
"address": "demo.consul.io:80",
|
2014-10-20 21:02:37 +02:00
|
|
|
"datacenter": "nyc3",
|
2015-05-07 01:12:32 +02:00
|
|
|
"scheme": "https",
|
2014-07-26 04:14:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
rawConfig, err := config.NewRawConfig(raw)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = rp.Configure(terraform.NewResourceConfig(rawConfig))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
2016-01-21 21:54:56 +01:00
|
|
|
|
2016-08-12 04:22:41 +02:00
|
|
|
func TestResourceProvider_ConfigureTLS(t *testing.T) {
|
|
|
|
rp := Provider()
|
|
|
|
|
|
|
|
raw := map[string]interface{}{
|
|
|
|
"address": "demo.consul.io:80",
|
|
|
|
"ca_file": "test-fixtures/cacert.pem",
|
|
|
|
"cert_file": "test-fixtures/usercert.pem",
|
|
|
|
"datacenter": "nyc3",
|
|
|
|
"key_file": "test-fixtures/userkey.pem",
|
|
|
|
"scheme": "https",
|
|
|
|
}
|
|
|
|
|
|
|
|
rawConfig, err := config.NewRawConfig(raw)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = rp.Configure(terraform.NewResourceConfig(rawConfig))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-21 21:54:56 +01:00
|
|
|
func testAccPreCheck(t *testing.T) {
|
2016-08-12 04:22:41 +02:00
|
|
|
if v := os.Getenv("CONSUL_HTTP_ADDR"); v != "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if v := os.Getenv("CONSUL_ADDRESS"); v != "" {
|
|
|
|
return
|
2016-01-21 21:54:56 +01:00
|
|
|
}
|
2016-08-12 04:22:41 +02:00
|
|
|
t.Fatal("Either CONSUL_ADDRESS or CONSUL_HTTP_ADDR must be set for acceptance tests")
|
2016-01-21 21:54:56 +01:00
|
|
|
}
|