Skip to content

Commit d1010f4

Browse files
committed
heroku: randomize names in acctests
Should fix build failures seen here: https://travis-ci.org/hashicorp/terraform/builds/103764448
1 parent a5b2886 commit d1010f4

2 files changed

Lines changed: 70 additions & 49 deletions

File tree

builtin/providers/heroku/resource_heroku_addon_test.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,29 @@ import (
55
"testing"
66

77
"github.com/cyberdelia/heroku-go/v3"
8+
"github.com/hashicorp/terraform/helper/acctest"
89
"github.com/hashicorp/terraform/helper/resource"
910
"github.com/hashicorp/terraform/terraform"
1011
)
1112

1213
func TestAccHerokuAddon_Basic(t *testing.T) {
1314
var addon heroku.Addon
15+
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
1416

1517
resource.Test(t, resource.TestCase{
1618
PreCheck: func() { testAccPreCheck(t) },
1719
Providers: testAccProviders,
1820
CheckDestroy: testAccCheckHerokuAddonDestroy,
1921
Steps: []resource.TestStep{
2022
resource.TestStep{
21-
Config: testAccCheckHerokuAddonConfig_basic,
23+
Config: testAccCheckHerokuAddonConfig_basic(appName),
2224
Check: resource.ComposeTestCheckFunc(
2325
testAccCheckHerokuAddonExists("heroku_addon.foobar", &addon),
2426
testAccCheckHerokuAddonAttributes(&addon, "deployhooks:http"),
2527
resource.TestCheckResourceAttr(
2628
"heroku_addon.foobar", "config.0.url", "http://google.com"),
2729
resource.TestCheckResourceAttr(
28-
"heroku_addon.foobar", "app", "terraform-test-app"),
30+
"heroku_addon.foobar", "app", appName),
2931
resource.TestCheckResourceAttr(
3032
"heroku_addon.foobar", "plan", "deployhooks:http"),
3133
),
@@ -37,30 +39,31 @@ func TestAccHerokuAddon_Basic(t *testing.T) {
3739
// GH-198
3840
func TestAccHerokuAddon_noPlan(t *testing.T) {
3941
var addon heroku.Addon
42+
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
4043

4144
resource.Test(t, resource.TestCase{
4245
PreCheck: func() { testAccPreCheck(t) },
4346
Providers: testAccProviders,
4447
CheckDestroy: testAccCheckHerokuAddonDestroy,
4548
Steps: []resource.TestStep{
4649
resource.TestStep{
47-
Config: testAccCheckHerokuAddonConfig_no_plan,
50+
Config: testAccCheckHerokuAddonConfig_no_plan(appName),
4851
Check: resource.ComposeTestCheckFunc(
4952
testAccCheckHerokuAddonExists("heroku_addon.foobar", &addon),
5053
testAccCheckHerokuAddonAttributes(&addon, "memcachier:dev"),
5154
resource.TestCheckResourceAttr(
52-
"heroku_addon.foobar", "app", "terraform-test-app"),
55+
"heroku_addon.foobar", "app", appName),
5356
resource.TestCheckResourceAttr(
5457
"heroku_addon.foobar", "plan", "memcachier"),
5558
),
5659
},
5760
resource.TestStep{
58-
Config: testAccCheckHerokuAddonConfig_no_plan,
61+
Config: testAccCheckHerokuAddonConfig_no_plan(appName),
5962
Check: resource.ComposeTestCheckFunc(
6063
testAccCheckHerokuAddonExists("heroku_addon.foobar", &addon),
6164
testAccCheckHerokuAddonAttributes(&addon, "memcachier:dev"),
6265
resource.TestCheckResourceAttr(
63-
"heroku_addon.foobar", "app", "terraform-test-app"),
66+
"heroku_addon.foobar", "app", appName),
6467
resource.TestCheckResourceAttr(
6568
"heroku_addon.foobar", "plan", "memcachier"),
6669
),
@@ -128,9 +131,10 @@ func testAccCheckHerokuAddonExists(n string, addon *heroku.Addon) resource.TestC
128131
}
129132
}
130133

131-
const testAccCheckHerokuAddonConfig_basic = `
134+
func testAccCheckHerokuAddonConfig_basic(appName string) string {
135+
return fmt.Sprintf(`
132136
resource "heroku_app" "foobar" {
133-
name = "terraform-test-app"
137+
name = "%s"
134138
region = "us"
135139
}
136140
@@ -140,15 +144,18 @@ resource "heroku_addon" "foobar" {
140144
config {
141145
url = "http://google.com"
142146
}
143-
}`
147+
}`, appName)
148+
}
144149

145-
const testAccCheckHerokuAddonConfig_no_plan = `
150+
func testAccCheckHerokuAddonConfig_no_plan(appName string) string {
151+
return fmt.Sprintf(`
146152
resource "heroku_app" "foobar" {
147-
name = "terraform-test-app"
153+
name = "%s"
148154
region = "us"
149155
}
150156
151157
resource "heroku_addon" "foobar" {
152158
app = "${heroku_app.foobar.name}"
153159
plan = "memcachier"
154-
}`
160+
}`, appName)
161+
}

builtin/providers/heroku/resource_heroku_app_test.go

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,27 @@ import (
66
"testing"
77

88
"github.com/cyberdelia/heroku-go/v3"
9+
"github.com/hashicorp/terraform/helper/acctest"
910
"github.com/hashicorp/terraform/helper/resource"
1011
"github.com/hashicorp/terraform/terraform"
1112
)
1213

1314
func TestAccHerokuApp_Basic(t *testing.T) {
1415
var app heroku.App
16+
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
1517

1618
resource.Test(t, resource.TestCase{
1719
PreCheck: func() { testAccPreCheck(t) },
1820
Providers: testAccProviders,
1921
CheckDestroy: testAccCheckHerokuAppDestroy,
2022
Steps: []resource.TestStep{
2123
resource.TestStep{
22-
Config: testAccCheckHerokuAppConfig_basic,
24+
Config: testAccCheckHerokuAppConfig_basic(appName),
2325
Check: resource.ComposeTestCheckFunc(
2426
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
25-
testAccCheckHerokuAppAttributes(&app),
27+
testAccCheckHerokuAppAttributes(&app, appName),
2628
resource.TestCheckResourceAttr(
27-
"heroku_app.foobar", "name", "terraform-test-app"),
29+
"heroku_app.foobar", "name", appName),
2830
resource.TestCheckResourceAttr(
2931
"heroku_app.foobar", "config_vars.0.FOO", "bar"),
3032
),
@@ -35,30 +37,32 @@ func TestAccHerokuApp_Basic(t *testing.T) {
3537

3638
func TestAccHerokuApp_NameChange(t *testing.T) {
3739
var app heroku.App
40+
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
41+
appName2 := fmt.Sprintf("%s-v2", appName)
3842

3943
resource.Test(t, resource.TestCase{
4044
PreCheck: func() { testAccPreCheck(t) },
4145
Providers: testAccProviders,
4246
CheckDestroy: testAccCheckHerokuAppDestroy,
4347
Steps: []resource.TestStep{
4448
resource.TestStep{
45-
Config: testAccCheckHerokuAppConfig_basic,
49+
Config: testAccCheckHerokuAppConfig_basic(appName),
4650
Check: resource.ComposeTestCheckFunc(
4751
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
48-
testAccCheckHerokuAppAttributes(&app),
52+
testAccCheckHerokuAppAttributes(&app, appName),
4953
resource.TestCheckResourceAttr(
50-
"heroku_app.foobar", "name", "terraform-test-app"),
54+
"heroku_app.foobar", "name", appName),
5155
resource.TestCheckResourceAttr(
5256
"heroku_app.foobar", "config_vars.0.FOO", "bar"),
5357
),
5458
},
5559
resource.TestStep{
56-
Config: testAccCheckHerokuAppConfig_updated,
60+
Config: testAccCheckHerokuAppConfig_updated(appName2),
5761
Check: resource.ComposeTestCheckFunc(
5862
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
59-
testAccCheckHerokuAppAttributesUpdated(&app),
63+
testAccCheckHerokuAppAttributesUpdated(&app, appName2),
6064
resource.TestCheckResourceAttr(
61-
"heroku_app.foobar", "name", "terraform-test-renamed"),
65+
"heroku_app.foobar", "name", appName2),
6266
resource.TestCheckResourceAttr(
6367
"heroku_app.foobar", "config_vars.0.FOO", "bing"),
6468
resource.TestCheckResourceAttr(
@@ -71,30 +75,31 @@ func TestAccHerokuApp_NameChange(t *testing.T) {
7175

7276
func TestAccHerokuApp_NukeVars(t *testing.T) {
7377
var app heroku.App
78+
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
7479

7580
resource.Test(t, resource.TestCase{
7681
PreCheck: func() { testAccPreCheck(t) },
7782
Providers: testAccProviders,
7883
CheckDestroy: testAccCheckHerokuAppDestroy,
7984
Steps: []resource.TestStep{
8085
resource.TestStep{
81-
Config: testAccCheckHerokuAppConfig_basic,
86+
Config: testAccCheckHerokuAppConfig_basic(appName),
8287
Check: resource.ComposeTestCheckFunc(
8388
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
84-
testAccCheckHerokuAppAttributes(&app),
89+
testAccCheckHerokuAppAttributes(&app, appName),
8590
resource.TestCheckResourceAttr(
86-
"heroku_app.foobar", "name", "terraform-test-app"),
91+
"heroku_app.foobar", "name", appName),
8792
resource.TestCheckResourceAttr(
8893
"heroku_app.foobar", "config_vars.0.FOO", "bar"),
8994
),
9095
},
9196
resource.TestStep{
92-
Config: testAccCheckHerokuAppConfig_no_vars,
97+
Config: testAccCheckHerokuAppConfig_no_vars(appName),
9398
Check: resource.ComposeTestCheckFunc(
9499
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
95-
testAccCheckHerokuAppAttributesNoVars(&app),
100+
testAccCheckHerokuAppAttributesNoVars(&app, appName),
96101
resource.TestCheckResourceAttr(
97-
"heroku_app.foobar", "name", "terraform-test-app"),
102+
"heroku_app.foobar", "name", appName),
98103
resource.TestCheckResourceAttr(
99104
"heroku_app.foobar", "config_vars.0.FOO", ""),
100105
),
@@ -105,6 +110,7 @@ func TestAccHerokuApp_NukeVars(t *testing.T) {
105110

106111
func TestAccHerokuApp_Organization(t *testing.T) {
107112
var app heroku.OrganizationApp
113+
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
108114
org := os.Getenv("HEROKU_ORGANIZATION")
109115

110116
resource.Test(t, resource.TestCase{
@@ -118,10 +124,10 @@ func TestAccHerokuApp_Organization(t *testing.T) {
118124
CheckDestroy: testAccCheckHerokuAppDestroy,
119125
Steps: []resource.TestStep{
120126
resource.TestStep{
121-
Config: fmt.Sprintf(testAccCheckHerokuAppConfig_organization, org),
127+
Config: testAccCheckHerokuAppConfig_organization(appName, org),
122128
Check: resource.ComposeTestCheckFunc(
123129
testAccCheckHerokuAppExistsOrg("heroku_app.foobar", &app),
124-
testAccCheckHerokuAppAttributesOrg(&app, org),
130+
testAccCheckHerokuAppAttributesOrg(&app, appName, org),
125131
),
126132
},
127133
},
@@ -146,7 +152,7 @@ func testAccCheckHerokuAppDestroy(s *terraform.State) error {
146152
return nil
147153
}
148154

149-
func testAccCheckHerokuAppAttributes(app *heroku.App) resource.TestCheckFunc {
155+
func testAccCheckHerokuAppAttributes(app *heroku.App, appName string) resource.TestCheckFunc {
150156
return func(s *terraform.State) error {
151157
client := testAccProvider.Meta().(*heroku.Service)
152158

@@ -158,7 +164,7 @@ func testAccCheckHerokuAppAttributes(app *heroku.App) resource.TestCheckFunc {
158164
return fmt.Errorf("Bad stack: %s", app.Stack.Name)
159165
}
160166

161-
if app.Name != "terraform-test-app" {
167+
if app.Name != appName {
162168
return fmt.Errorf("Bad name: %s", app.Name)
163169
}
164170

@@ -175,11 +181,11 @@ func testAccCheckHerokuAppAttributes(app *heroku.App) resource.TestCheckFunc {
175181
}
176182
}
177183

178-
func testAccCheckHerokuAppAttributesUpdated(app *heroku.App) resource.TestCheckFunc {
184+
func testAccCheckHerokuAppAttributesUpdated(app *heroku.App, appName string) resource.TestCheckFunc {
179185
return func(s *terraform.State) error {
180186
client := testAccProvider.Meta().(*heroku.Service)
181187

182-
if app.Name != "terraform-test-renamed" {
188+
if app.Name != appName {
183189
return fmt.Errorf("Bad name: %s", app.Name)
184190
}
185191

@@ -202,11 +208,11 @@ func testAccCheckHerokuAppAttributesUpdated(app *heroku.App) resource.TestCheckF
202208
}
203209
}
204210

205-
func testAccCheckHerokuAppAttributesNoVars(app *heroku.App) resource.TestCheckFunc {
211+
func testAccCheckHerokuAppAttributesNoVars(app *heroku.App, appName string) resource.TestCheckFunc {
206212
return func(s *terraform.State) error {
207213
client := testAccProvider.Meta().(*heroku.Service)
208214

209-
if app.Name != "terraform-test-app" {
215+
if app.Name != appName {
210216
return fmt.Errorf("Bad name: %s", app.Name)
211217
}
212218

@@ -223,7 +229,7 @@ func testAccCheckHerokuAppAttributesNoVars(app *heroku.App) resource.TestCheckFu
223229
}
224230
}
225231

226-
func testAccCheckHerokuAppAttributesOrg(app *heroku.OrganizationApp, org string) resource.TestCheckFunc {
232+
func testAccCheckHerokuAppAttributesOrg(app *heroku.OrganizationApp, appName string, org string) resource.TestCheckFunc {
227233
return func(s *terraform.State) error {
228234
client := testAccProvider.Meta().(*heroku.Service)
229235

@@ -235,7 +241,7 @@ func testAccCheckHerokuAppAttributesOrg(app *heroku.OrganizationApp, org string)
235241
return fmt.Errorf("Bad stack: %s", app.Stack.Name)
236242
}
237243

238-
if app.Name != "terraform-test-app" {
244+
if app.Name != appName {
239245
return fmt.Errorf("Bad name: %s", app.Name)
240246
}
241247

@@ -316,36 +322,43 @@ func testAccCheckHerokuAppExistsOrg(n string, app *heroku.OrganizationApp) resou
316322
}
317323
}
318324

319-
const testAccCheckHerokuAppConfig_basic = `
325+
func testAccCheckHerokuAppConfig_basic(appName string) string {
326+
return fmt.Sprintf(`
320327
resource "heroku_app" "foobar" {
321-
name = "terraform-test-app"
328+
name = "%s"
322329
region = "us"
323330
324331
config_vars {
325332
FOO = "bar"
326333
}
327-
}`
334+
}`, appName)
335+
}
328336

329-
const testAccCheckHerokuAppConfig_updated = `
337+
func testAccCheckHerokuAppConfig_updated(appName string) string {
338+
return fmt.Sprintf(`
330339
resource "heroku_app" "foobar" {
331-
name = "terraform-test-renamed"
340+
name = "%s"
332341
region = "us"
333342
334343
config_vars {
335344
FOO = "bing"
336345
BAZ = "bar"
337346
}
338-
}`
347+
}`, appName)
348+
}
339349

340-
const testAccCheckHerokuAppConfig_no_vars = `
350+
func testAccCheckHerokuAppConfig_no_vars(appName string) string {
351+
return fmt.Sprintf(`
341352
resource "heroku_app" "foobar" {
342-
name = "terraform-test-app"
353+
name = "%s"
343354
region = "us"
344-
}`
355+
}`, appName)
356+
}
345357

346-
const testAccCheckHerokuAppConfig_organization = `
358+
func testAccCheckHerokuAppConfig_organization(appName, org string) string {
359+
return fmt.Sprintf(`
347360
resource "heroku_app" "foobar" {
348-
name = "terraform-test-app"
361+
name = "%s"
349362
region = "us"
350363
351364
organization {
@@ -355,4 +368,5 @@ resource "heroku_app" "foobar" {
355368
config_vars {
356369
FOO = "bar"
357370
}
358-
}`
371+
}`, appName, org)
372+
}

0 commit comments

Comments
 (0)