2014-08-19 00:49:54 +02:00
|
|
|
package heroku
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2014-08-27 16:50:37 +02:00
|
|
|
"github.com/cyberdelia/heroku-go/v3"
|
2014-08-19 00:49:54 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccHerokuAddon_Basic(t *testing.T) {
|
|
|
|
var addon heroku.Addon
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckHerokuAddonDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccCheckHerokuAddonConfig_basic,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckHerokuAddonExists("heroku_addon.foobar", &addon),
|
|
|
|
testAccCheckHerokuAddonAttributes(&addon),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"heroku_addon.foobar", "config.0.url", "http://google.com"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"heroku_addon.foobar", "app", "terraform-test-app"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"heroku_addon.foobar", "plan", "deployhooks:http"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckHerokuAddonDestroy(s *terraform.State) error {
|
2014-08-27 16:50:37 +02:00
|
|
|
client := testAccProvider.Meta().(*heroku.Service)
|
2014-08-19 00:49:54 +02:00
|
|
|
|
|
|
|
for _, rs := range s.Resources {
|
|
|
|
if rs.Type != "heroku_addon" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := client.AddonInfo(rs.Attributes["app"], rs.ID)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
return fmt.Errorf("Addon still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckHerokuAddonAttributes(addon *heroku.Addon) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
|
|
|
|
if addon.Plan.Name != "deployhooks:http" {
|
|
|
|
return fmt.Errorf("Bad plan: %s", addon.Plan)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckHerokuAddonExists(n string, addon *heroku.Addon) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.Resources[n]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.ID == "" {
|
|
|
|
return fmt.Errorf("No Addon ID is set")
|
|
|
|
}
|
|
|
|
|
2014-08-27 16:50:37 +02:00
|
|
|
client := testAccProvider.Meta().(*heroku.Service)
|
2014-08-19 00:49:54 +02:00
|
|
|
|
|
|
|
foundAddon, err := client.AddonInfo(rs.Attributes["app"], rs.ID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-08-27 16:50:37 +02:00
|
|
|
if foundAddon.ID != rs.ID {
|
2014-08-19 00:49:54 +02:00
|
|
|
return fmt.Errorf("Addon not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
*addon = *foundAddon
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const testAccCheckHerokuAddonConfig_basic = `
|
|
|
|
resource "heroku_app" "foobar" {
|
|
|
|
name = "terraform-test-app"
|
2014-08-28 00:50:38 +02:00
|
|
|
region = "us"
|
2014-08-19 00:49:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "heroku_addon" "foobar" {
|
|
|
|
app = "${heroku_app.foobar.name}"
|
|
|
|
plan = "deployhooks:http"
|
|
|
|
config {
|
|
|
|
url = "http://google.com"
|
|
|
|
}
|
|
|
|
}`
|