2014-07-23 06:03:30 +02:00
|
|
|
package heroku
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2014-08-18 18:32:40 +02:00
|
|
|
"github.com/bgentry/heroku-go"
|
2014-07-23 06:03:30 +02:00
|
|
|
"github.com/hashicorp/terraform/config"
|
2014-08-18 18:32:40 +02:00
|
|
|
"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
|
2014-08-18 18:32:40 +02:00
|
|
|
var testAccProvider *schema.Provider
|
2014-07-23 06:03:30 +02:00
|
|
|
|
|
|
|
func init() {
|
2014-08-18 18:32:40 +02:00
|
|
|
testAccProvider = Provider()
|
2014-07-23 06:03:30 +02:00
|
|
|
testAccProviders = map[string]terraform.ResourceProvider{
|
|
|
|
"heroku": testAccProvider,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-18 18:32:40 +02:00
|
|
|
func TestProvider(t *testing.T) {
|
|
|
|
if err := Provider().InternalValidate(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
2014-07-23 06:03:30 +02:00
|
|
|
}
|
|
|
|
|
2014-08-18 18:32:40 +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)
|
|
|
|
}
|
|
|
|
|
2014-08-18 18:32:40 +02:00
|
|
|
rp := Provider()
|
2014-07-23 06:03:30 +02:00
|
|
|
err = rp.Configure(terraform.NewResourceConfig(rawConfig))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2014-08-18 18:32:40 +02:00
|
|
|
config := rp.Meta().(*heroku.Client)
|
|
|
|
if config.Username != expectedEmail {
|
|
|
|
t.Fatalf("bad: %#v", config)
|
2014-07-23 06:03:30 +02:00
|
|
|
}
|
2014-08-18 18:32:40 +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")
|
|
|
|
}
|
|
|
|
}
|