terraform/builtin/providers/heroku/provider_test.go

83 lines
1.7 KiB
Go
Raw Normal View History

2014-07-23 06:03:30 +02:00
package heroku
import (
"os"
"testing"
"github.com/bgentry/heroku-go"
2014-07-23 06:03:30 +02:00
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/helper/schema"
2014-07-23 06:03:30 +02:00
"github.com/hashicorp/terraform/terraform"
)
var testAccProviders map[string]terraform.ResourceProvider
var testAccProvider *schema.Provider
2014-07-23 06:03:30 +02:00
func init() {
testAccProvider = Provider()
2014-07-23 06:03:30 +02:00
testAccProviders = map[string]terraform.ResourceProvider{
"heroku": testAccProvider,
}
}
func TestProvider(t *testing.T) {
if err := Provider().InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
2014-07-23 06:03:30 +02:00
}
func TestProvider_impl(t *testing.T) {
var _ terraform.ResourceProvider = Provider()
}
func TestProviderConfigure(t *testing.T) {
2014-07-23 06:03:30 +02:00
var expectedKey string
var expectedEmail string
if v := os.Getenv("HEROKU_EMAIL"); v != "" {
expectedEmail = v
} else {
expectedEmail = "foo"
}
if v := os.Getenv("HEROKU_API_KEY"); v != "" {
expectedKey = v
} else {
expectedKey = "foo"
}
raw := map[string]interface{}{
"api_key": expectedKey,
"email": expectedEmail,
}
rawConfig, err := config.NewRawConfig(raw)
if err != nil {
t.Fatalf("err: %s", err)
}
rp := Provider()
2014-07-23 06:03:30 +02:00
err = rp.Configure(terraform.NewResourceConfig(rawConfig))
if err != nil {
t.Fatalf("err: %s", err)
}
config := rp.Meta().(*heroku.Client)
if config.Username != expectedEmail {
t.Fatalf("bad: %#v", config)
2014-07-23 06:03:30 +02:00
}
if config.Password != expectedKey {
t.Fatalf("bad: %#v", config)
2014-07-23 06:03:30 +02:00
}
}
func testAccPreCheck(t *testing.T) {
if v := os.Getenv("HEROKU_EMAIL"); v == "" {
t.Fatal("HEROKU_EMAIL must be set for acceptance tests")
}
if v := os.Getenv("HEROKU_API_KEY"); v == "" {
t.Fatal("HEROKU_API_KEY must be set for acceptance tests")
}
}