github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/consul/resource_provider_test.go (about) 1 package consul 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/hashicorp/terraform/config" 8 "github.com/hashicorp/terraform/helper/schema" 9 "github.com/hashicorp/terraform/terraform" 10 ) 11 12 var testAccProviders map[string]terraform.ResourceProvider 13 var testAccProvider *schema.Provider 14 15 func init() { 16 testAccProvider = Provider().(*schema.Provider) 17 testAccProviders = map[string]terraform.ResourceProvider{ 18 "consul": testAccProvider, 19 } 20 } 21 22 func TestResourceProvider(t *testing.T) { 23 if err := Provider().(*schema.Provider).InternalValidate(); err != nil { 24 t.Fatalf("err: %s", err) 25 } 26 } 27 28 func TestResourceProvider_impl(t *testing.T) { 29 var _ terraform.ResourceProvider = Provider() 30 } 31 32 func TestResourceProvider_Configure(t *testing.T) { 33 rp := Provider() 34 35 raw := map[string]interface{}{ 36 "address": "demo.consul.io:80", 37 "datacenter": "nyc3", 38 "scheme": "https", 39 } 40 41 rawConfig, err := config.NewRawConfig(raw) 42 if err != nil { 43 t.Fatalf("err: %s", err) 44 } 45 46 err = rp.Configure(terraform.NewResourceConfig(rawConfig)) 47 if err != nil { 48 t.Fatalf("err: %s", err) 49 } 50 } 51 52 func TestResourceProvider_ConfigureTLS(t *testing.T) { 53 rp := Provider() 54 55 raw := map[string]interface{}{ 56 "address": "demo.consul.io:80", 57 "ca_file": "test-fixtures/cacert.pem", 58 "cert_file": "test-fixtures/usercert.pem", 59 "datacenter": "nyc3", 60 "key_file": "test-fixtures/userkey.pem", 61 "scheme": "https", 62 } 63 64 rawConfig, err := config.NewRawConfig(raw) 65 if err != nil { 66 t.Fatalf("err: %s", err) 67 } 68 69 err = rp.Configure(terraform.NewResourceConfig(rawConfig)) 70 if err != nil { 71 t.Fatalf("err: %s", err) 72 } 73 } 74 75 func testAccPreCheck(t *testing.T) { 76 if v := os.Getenv("CONSUL_HTTP_ADDR"); v != "" { 77 return 78 } 79 if v := os.Getenv("CONSUL_ADDRESS"); v != "" { 80 return 81 } 82 t.Fatal("Either CONSUL_ADDRESS or CONSUL_HTTP_ADDR must be set for acceptance tests") 83 }