@@ -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
1314func 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
3638func 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
7276func 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
106111func 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 (`
320327resource "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 (`
330339resource "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 (`
341352resource "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 (`
347360resource "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