heroku: randomize names in acctests

Should fix build failures seen here:

https://travis-ci.org/hashicorp/terraform/builds/103764448
This commit is contained in:
Paul Hinze 2016-01-21 09:31:48 -06:00
parent a5b28868a8
commit d1010f40c5
2 changed files with 70 additions and 49 deletions

View File

@ -5,12 +5,14 @@ import (
"testing" "testing"
"github.com/cyberdelia/heroku-go/v3" "github.com/cyberdelia/heroku-go/v3"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccHerokuAddon_Basic(t *testing.T) { func TestAccHerokuAddon_Basic(t *testing.T) {
var addon heroku.Addon var addon heroku.Addon
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -18,14 +20,14 @@ func TestAccHerokuAddon_Basic(t *testing.T) {
CheckDestroy: testAccCheckHerokuAddonDestroy, CheckDestroy: testAccCheckHerokuAddonDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccCheckHerokuAddonConfig_basic, Config: testAccCheckHerokuAddonConfig_basic(appName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuAddonExists("heroku_addon.foobar", &addon), testAccCheckHerokuAddonExists("heroku_addon.foobar", &addon),
testAccCheckHerokuAddonAttributes(&addon, "deployhooks:http"), testAccCheckHerokuAddonAttributes(&addon, "deployhooks:http"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_addon.foobar", "config.0.url", "http://google.com"), "heroku_addon.foobar", "config.0.url", "http://google.com"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_addon.foobar", "app", "terraform-test-app"), "heroku_addon.foobar", "app", appName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_addon.foobar", "plan", "deployhooks:http"), "heroku_addon.foobar", "plan", "deployhooks:http"),
), ),
@ -37,6 +39,7 @@ func TestAccHerokuAddon_Basic(t *testing.T) {
// GH-198 // GH-198
func TestAccHerokuAddon_noPlan(t *testing.T) { func TestAccHerokuAddon_noPlan(t *testing.T) {
var addon heroku.Addon var addon heroku.Addon
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -44,23 +47,23 @@ func TestAccHerokuAddon_noPlan(t *testing.T) {
CheckDestroy: testAccCheckHerokuAddonDestroy, CheckDestroy: testAccCheckHerokuAddonDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccCheckHerokuAddonConfig_no_plan, Config: testAccCheckHerokuAddonConfig_no_plan(appName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuAddonExists("heroku_addon.foobar", &addon), testAccCheckHerokuAddonExists("heroku_addon.foobar", &addon),
testAccCheckHerokuAddonAttributes(&addon, "memcachier:dev"), testAccCheckHerokuAddonAttributes(&addon, "memcachier:dev"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_addon.foobar", "app", "terraform-test-app"), "heroku_addon.foobar", "app", appName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_addon.foobar", "plan", "memcachier"), "heroku_addon.foobar", "plan", "memcachier"),
), ),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccCheckHerokuAddonConfig_no_plan, Config: testAccCheckHerokuAddonConfig_no_plan(appName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuAddonExists("heroku_addon.foobar", &addon), testAccCheckHerokuAddonExists("heroku_addon.foobar", &addon),
testAccCheckHerokuAddonAttributes(&addon, "memcachier:dev"), testAccCheckHerokuAddonAttributes(&addon, "memcachier:dev"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_addon.foobar", "app", "terraform-test-app"), "heroku_addon.foobar", "app", appName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_addon.foobar", "plan", "memcachier"), "heroku_addon.foobar", "plan", "memcachier"),
), ),
@ -128,9 +131,10 @@ func testAccCheckHerokuAddonExists(n string, addon *heroku.Addon) resource.TestC
} }
} }
const testAccCheckHerokuAddonConfig_basic = ` func testAccCheckHerokuAddonConfig_basic(appName string) string {
return fmt.Sprintf(`
resource "heroku_app" "foobar" { resource "heroku_app" "foobar" {
name = "terraform-test-app" name = "%s"
region = "us" region = "us"
} }
@ -140,15 +144,18 @@ resource "heroku_addon" "foobar" {
config { config {
url = "http://google.com" url = "http://google.com"
} }
}` }`, appName)
}
const testAccCheckHerokuAddonConfig_no_plan = ` func testAccCheckHerokuAddonConfig_no_plan(appName string) string {
return fmt.Sprintf(`
resource "heroku_app" "foobar" { resource "heroku_app" "foobar" {
name = "terraform-test-app" name = "%s"
region = "us" region = "us"
} }
resource "heroku_addon" "foobar" { resource "heroku_addon" "foobar" {
app = "${heroku_app.foobar.name}" app = "${heroku_app.foobar.name}"
plan = "memcachier" plan = "memcachier"
}` }`, appName)
}

View File

@ -6,12 +6,14 @@ import (
"testing" "testing"
"github.com/cyberdelia/heroku-go/v3" "github.com/cyberdelia/heroku-go/v3"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccHerokuApp_Basic(t *testing.T) { func TestAccHerokuApp_Basic(t *testing.T) {
var app heroku.App var app heroku.App
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -19,12 +21,12 @@ func TestAccHerokuApp_Basic(t *testing.T) {
CheckDestroy: testAccCheckHerokuAppDestroy, CheckDestroy: testAccCheckHerokuAppDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccCheckHerokuAppConfig_basic, Config: testAccCheckHerokuAppConfig_basic(appName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuAppExists("heroku_app.foobar", &app), testAccCheckHerokuAppExists("heroku_app.foobar", &app),
testAccCheckHerokuAppAttributes(&app), testAccCheckHerokuAppAttributes(&app, appName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_app.foobar", "name", "terraform-test-app"), "heroku_app.foobar", "name", appName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_app.foobar", "config_vars.0.FOO", "bar"), "heroku_app.foobar", "config_vars.0.FOO", "bar"),
), ),
@ -35,6 +37,8 @@ func TestAccHerokuApp_Basic(t *testing.T) {
func TestAccHerokuApp_NameChange(t *testing.T) { func TestAccHerokuApp_NameChange(t *testing.T) {
var app heroku.App var app heroku.App
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
appName2 := fmt.Sprintf("%s-v2", appName)
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -42,23 +46,23 @@ func TestAccHerokuApp_NameChange(t *testing.T) {
CheckDestroy: testAccCheckHerokuAppDestroy, CheckDestroy: testAccCheckHerokuAppDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccCheckHerokuAppConfig_basic, Config: testAccCheckHerokuAppConfig_basic(appName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuAppExists("heroku_app.foobar", &app), testAccCheckHerokuAppExists("heroku_app.foobar", &app),
testAccCheckHerokuAppAttributes(&app), testAccCheckHerokuAppAttributes(&app, appName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_app.foobar", "name", "terraform-test-app"), "heroku_app.foobar", "name", appName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_app.foobar", "config_vars.0.FOO", "bar"), "heroku_app.foobar", "config_vars.0.FOO", "bar"),
), ),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccCheckHerokuAppConfig_updated, Config: testAccCheckHerokuAppConfig_updated(appName2),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuAppExists("heroku_app.foobar", &app), testAccCheckHerokuAppExists("heroku_app.foobar", &app),
testAccCheckHerokuAppAttributesUpdated(&app), testAccCheckHerokuAppAttributesUpdated(&app, appName2),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_app.foobar", "name", "terraform-test-renamed"), "heroku_app.foobar", "name", appName2),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_app.foobar", "config_vars.0.FOO", "bing"), "heroku_app.foobar", "config_vars.0.FOO", "bing"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -71,6 +75,7 @@ func TestAccHerokuApp_NameChange(t *testing.T) {
func TestAccHerokuApp_NukeVars(t *testing.T) { func TestAccHerokuApp_NukeVars(t *testing.T) {
var app heroku.App var app heroku.App
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -78,23 +83,23 @@ func TestAccHerokuApp_NukeVars(t *testing.T) {
CheckDestroy: testAccCheckHerokuAppDestroy, CheckDestroy: testAccCheckHerokuAppDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccCheckHerokuAppConfig_basic, Config: testAccCheckHerokuAppConfig_basic(appName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuAppExists("heroku_app.foobar", &app), testAccCheckHerokuAppExists("heroku_app.foobar", &app),
testAccCheckHerokuAppAttributes(&app), testAccCheckHerokuAppAttributes(&app, appName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_app.foobar", "name", "terraform-test-app"), "heroku_app.foobar", "name", appName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_app.foobar", "config_vars.0.FOO", "bar"), "heroku_app.foobar", "config_vars.0.FOO", "bar"),
), ),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccCheckHerokuAppConfig_no_vars, Config: testAccCheckHerokuAppConfig_no_vars(appName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuAppExists("heroku_app.foobar", &app), testAccCheckHerokuAppExists("heroku_app.foobar", &app),
testAccCheckHerokuAppAttributesNoVars(&app), testAccCheckHerokuAppAttributesNoVars(&app, appName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_app.foobar", "name", "terraform-test-app"), "heroku_app.foobar", "name", appName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"heroku_app.foobar", "config_vars.0.FOO", ""), "heroku_app.foobar", "config_vars.0.FOO", ""),
), ),
@ -105,6 +110,7 @@ func TestAccHerokuApp_NukeVars(t *testing.T) {
func TestAccHerokuApp_Organization(t *testing.T) { func TestAccHerokuApp_Organization(t *testing.T) {
var app heroku.OrganizationApp var app heroku.OrganizationApp
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
org := os.Getenv("HEROKU_ORGANIZATION") org := os.Getenv("HEROKU_ORGANIZATION")
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
@ -118,10 +124,10 @@ func TestAccHerokuApp_Organization(t *testing.T) {
CheckDestroy: testAccCheckHerokuAppDestroy, CheckDestroy: testAccCheckHerokuAppDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: fmt.Sprintf(testAccCheckHerokuAppConfig_organization, org), Config: testAccCheckHerokuAppConfig_organization(appName, org),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuAppExistsOrg("heroku_app.foobar", &app), testAccCheckHerokuAppExistsOrg("heroku_app.foobar", &app),
testAccCheckHerokuAppAttributesOrg(&app, org), testAccCheckHerokuAppAttributesOrg(&app, appName, org),
), ),
}, },
}, },
@ -146,7 +152,7 @@ func testAccCheckHerokuAppDestroy(s *terraform.State) error {
return nil return nil
} }
func testAccCheckHerokuAppAttributes(app *heroku.App) resource.TestCheckFunc { func testAccCheckHerokuAppAttributes(app *heroku.App, appName string) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
client := testAccProvider.Meta().(*heroku.Service) client := testAccProvider.Meta().(*heroku.Service)
@ -158,7 +164,7 @@ func testAccCheckHerokuAppAttributes(app *heroku.App) resource.TestCheckFunc {
return fmt.Errorf("Bad stack: %s", app.Stack.Name) return fmt.Errorf("Bad stack: %s", app.Stack.Name)
} }
if app.Name != "terraform-test-app" { if app.Name != appName {
return fmt.Errorf("Bad name: %s", app.Name) return fmt.Errorf("Bad name: %s", app.Name)
} }
@ -175,11 +181,11 @@ func testAccCheckHerokuAppAttributes(app *heroku.App) resource.TestCheckFunc {
} }
} }
func testAccCheckHerokuAppAttributesUpdated(app *heroku.App) resource.TestCheckFunc { func testAccCheckHerokuAppAttributesUpdated(app *heroku.App, appName string) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
client := testAccProvider.Meta().(*heroku.Service) client := testAccProvider.Meta().(*heroku.Service)
if app.Name != "terraform-test-renamed" { if app.Name != appName {
return fmt.Errorf("Bad name: %s", app.Name) return fmt.Errorf("Bad name: %s", app.Name)
} }
@ -202,11 +208,11 @@ func testAccCheckHerokuAppAttributesUpdated(app *heroku.App) resource.TestCheckF
} }
} }
func testAccCheckHerokuAppAttributesNoVars(app *heroku.App) resource.TestCheckFunc { func testAccCheckHerokuAppAttributesNoVars(app *heroku.App, appName string) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
client := testAccProvider.Meta().(*heroku.Service) client := testAccProvider.Meta().(*heroku.Service)
if app.Name != "terraform-test-app" { if app.Name != appName {
return fmt.Errorf("Bad name: %s", app.Name) return fmt.Errorf("Bad name: %s", app.Name)
} }
@ -223,7 +229,7 @@ func testAccCheckHerokuAppAttributesNoVars(app *heroku.App) resource.TestCheckFu
} }
} }
func testAccCheckHerokuAppAttributesOrg(app *heroku.OrganizationApp, org string) resource.TestCheckFunc { func testAccCheckHerokuAppAttributesOrg(app *heroku.OrganizationApp, appName string, org string) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
client := testAccProvider.Meta().(*heroku.Service) client := testAccProvider.Meta().(*heroku.Service)
@ -235,7 +241,7 @@ func testAccCheckHerokuAppAttributesOrg(app *heroku.OrganizationApp, org string)
return fmt.Errorf("Bad stack: %s", app.Stack.Name) return fmt.Errorf("Bad stack: %s", app.Stack.Name)
} }
if app.Name != "terraform-test-app" { if app.Name != appName {
return fmt.Errorf("Bad name: %s", app.Name) return fmt.Errorf("Bad name: %s", app.Name)
} }
@ -316,36 +322,43 @@ func testAccCheckHerokuAppExistsOrg(n string, app *heroku.OrganizationApp) resou
} }
} }
const testAccCheckHerokuAppConfig_basic = ` func testAccCheckHerokuAppConfig_basic(appName string) string {
return fmt.Sprintf(`
resource "heroku_app" "foobar" { resource "heroku_app" "foobar" {
name = "terraform-test-app" name = "%s"
region = "us" region = "us"
config_vars { config_vars {
FOO = "bar" FOO = "bar"
} }
}` }`, appName)
}
const testAccCheckHerokuAppConfig_updated = ` func testAccCheckHerokuAppConfig_updated(appName string) string {
return fmt.Sprintf(`
resource "heroku_app" "foobar" { resource "heroku_app" "foobar" {
name = "terraform-test-renamed" name = "%s"
region = "us" region = "us"
config_vars { config_vars {
FOO = "bing" FOO = "bing"
BAZ = "bar" BAZ = "bar"
} }
}` }`, appName)
}
const testAccCheckHerokuAppConfig_no_vars = ` func testAccCheckHerokuAppConfig_no_vars(appName string) string {
return fmt.Sprintf(`
resource "heroku_app" "foobar" { resource "heroku_app" "foobar" {
name = "terraform-test-app" name = "%s"
region = "us" region = "us"
}` }`, appName)
}
const testAccCheckHerokuAppConfig_organization = ` func testAccCheckHerokuAppConfig_organization(appName, org string) string {
return fmt.Sprintf(`
resource "heroku_app" "foobar" { resource "heroku_app" "foobar" {
name = "terraform-test-app" name = "%s"
region = "us" region = "us"
organization { organization {
@ -355,4 +368,5 @@ resource "heroku_app" "foobar" {
config_vars { config_vars {
FOO = "bar" FOO = "bar"
} }
}` }`, appName, org)
}