terraform/builtin/providers/aws/resource_provider_test.go

99 lines
2.1 KiB
Go
Raw Normal View History

2014-05-30 02:28:38 +02:00
package aws
import (
2014-07-10 20:31:16 +02:00
"log"
"os"
2014-06-24 04:01:57 +02:00
"reflect"
2014-05-30 02:28:38 +02:00
"testing"
2014-06-24 04:01:57 +02:00
"github.com/hashicorp/terraform/config"
2014-05-30 02:28:38 +02:00
"github.com/hashicorp/terraform/terraform"
)
2014-07-10 20:31:16 +02:00
var testAccProviders map[string]terraform.ResourceProvider
var testAccProvider *ResourceProvider
func init() {
testAccProvider = new(ResourceProvider)
testAccProviders = map[string]terraform.ResourceProvider{
"aws": testAccProvider,
}
}
2014-05-30 02:28:38 +02:00
func TestResourceProvider_impl(t *testing.T) {
var _ terraform.ResourceProvider = new(ResourceProvider)
}
2014-06-24 04:01:57 +02:00
func TestResourceProvider_Configure(t *testing.T) {
rp := new(ResourceProvider)
raw := map[string]interface{}{
"access_key": "foo",
"secret_key": "bar",
2014-07-30 00:22:50 +02:00
"region": "us-east-1",
2014-06-24 04:01:57 +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)
}
expected := Config{
AccessKey: "foo",
SecretKey: "bar",
2014-07-30 00:22:50 +02:00
Region: "us-east-1",
2014-06-24 04:01:57 +02:00
}
if !reflect.DeepEqual(rp.Config, expected) {
t.Fatalf("bad: %#v", rp.Config)
}
if rp.p == nil {
t.Fatal("provider should be set")
}
if !reflect.DeepEqual(rp, rp.p.Meta()) {
t.Fatalf("meta should be set")
}
2014-06-24 04:01:57 +02:00
}
2014-07-10 20:31:16 +02:00
func TestResourceProvider_ConfigureBadRegion(t *testing.T) {
rp := new(ResourceProvider)
raw := map[string]interface{}{
"access_key": "foo",
"secret_key": "bar",
"region": "blah",
}
rawConfig, err := config.NewRawConfig(raw)
if err != nil {
t.Fatalf("err: %s", err)
}
err = rp.Configure(terraform.NewResourceConfig(rawConfig))
if err == nil {
t.Fatalf("should have err: bad region")
}
}
2014-07-10 20:31:16 +02:00
func testAccPreCheck(t *testing.T) {
if v := os.Getenv("AWS_ACCESS_KEY"); v == "" {
t.Fatal("AWS_ACCESS_KEY must be set for acceptance tests")
}
if v := os.Getenv("AWS_SECRET_KEY"); v == "" {
t.Fatal("AWS_SECRET_KEY must be set for acceptance tests")
}
if v := os.Getenv("AWS_REGION"); v == "" {
log.Println("[INFO] Test: Using us-west-2 as test region")
os.Setenv("AWS_REGION", "us-west-2")
}
if v := os.Getenv("AWS_SSL_CERTIFICATE_ID"); v == "" {
t.Fatal("AWS_SSL_CERTIFICATE_ID must be set for acceptance tests")
}
2014-07-10 20:31:16 +02:00
}