@@ -2,6 +2,7 @@ package heroku
22
33import (
44 "fmt"
5+ "os"
56 "testing"
67
78 "github.com/cyberdelia/heroku-go/v3"
@@ -102,6 +103,31 @@ func TestAccHerokuApp_NukeVars(t *testing.T) {
102103 })
103104}
104105
106+ func TestAccHerokuApp_Organization (t * testing.T ) {
107+ var app heroku.OrganizationApp
108+ org := os .Getenv ("HEROKU_ORGANIZATION" )
109+
110+ resource .Test (t , resource.TestCase {
111+ PreCheck : func () {
112+ testAccPreCheck (t )
113+ if org == "" {
114+ t .Skip ("HEROKU_ORGANIZATION is not set; skipping test." )
115+ }
116+ },
117+ Providers : testAccProviders ,
118+ CheckDestroy : testAccCheckHerokuAppDestroy ,
119+ Steps : []resource.TestStep {
120+ resource.TestStep {
121+ Config : fmt .Sprintf (testAccCheckHerokuAppConfig_organization , org ),
122+ Check : resource .ComposeTestCheckFunc (
123+ testAccCheckHerokuAppExistsOrg ("heroku_app.foobar" , & app ),
124+ testAccCheckHerokuAppAttributesOrg (& app , org ),
125+ ),
126+ },
127+ },
128+ })
129+ }
130+
105131func testAccCheckHerokuAppDestroy (s * terraform.State ) error {
106132 client := testAccProvider .Meta ().(* heroku.Service )
107133
@@ -197,6 +223,39 @@ func testAccCheckHerokuAppAttributesNoVars(app *heroku.App) resource.TestCheckFu
197223 }
198224}
199225
226+ func testAccCheckHerokuAppAttributesOrg (app * heroku.OrganizationApp , org string ) resource.TestCheckFunc {
227+ return func (s * terraform.State ) error {
228+ client := testAccProvider .Meta ().(* heroku.Service )
229+
230+ if app .Region .Name != "us" {
231+ return fmt .Errorf ("Bad region: %s" , app .Region .Name )
232+ }
233+
234+ if app .Stack .Name != "cedar-14" {
235+ return fmt .Errorf ("Bad stack: %s" , app .Stack .Name )
236+ }
237+
238+ if app .Name != "terraform-test-app" {
239+ return fmt .Errorf ("Bad name: %s" , app .Name )
240+ }
241+
242+ if app .Organization == nil || app .Organization .Name != org {
243+ return fmt .Errorf ("Bad org: %v" , app .Organization )
244+ }
245+
246+ vars , err := client .ConfigVarInfo (app .Name )
247+ if err != nil {
248+ return err
249+ }
250+
251+ if vars ["FOO" ] != "bar" {
252+ return fmt .Errorf ("Bad config vars: %v" , vars )
253+ }
254+
255+ return nil
256+ }
257+ }
258+
200259func testAccCheckHerokuAppExists (n string , app * heroku.App ) resource.TestCheckFunc {
201260 return func (s * terraform.State ) error {
202261 rs , ok := s .RootModule ().Resources [n ]
@@ -227,29 +286,73 @@ func testAccCheckHerokuAppExists(n string, app *heroku.App) resource.TestCheckFu
227286 }
228287}
229288
289+ func testAccCheckHerokuAppExistsOrg (n string , app * heroku.OrganizationApp ) resource.TestCheckFunc {
290+ return func (s * terraform.State ) error {
291+ rs , ok := s .RootModule ().Resources [n ]
292+
293+ if ! ok {
294+ return fmt .Errorf ("Not found: %s" , n )
295+ }
296+
297+ if rs .Primary .ID == "" {
298+ return fmt .Errorf ("No App Name is set" )
299+ }
300+
301+ client := testAccProvider .Meta ().(* heroku.Service )
302+
303+ foundApp , err := client .OrganizationAppInfo (rs .Primary .ID )
304+
305+ if err != nil {
306+ return err
307+ }
308+
309+ if foundApp .Name != rs .Primary .ID {
310+ return fmt .Errorf ("App not found" )
311+ }
312+
313+ * app = * foundApp
314+
315+ return nil
316+ }
317+ }
318+
230319const testAccCheckHerokuAppConfig_basic = `
231320resource "heroku_app" "foobar" {
232- name = "terraform-test-app"
233- region = "us"
321+ name = "terraform-test-app"
322+ region = "us"
234323
235- config_vars {
236- FOO = "bar"
237- }
324+ config_vars {
325+ FOO = "bar"
326+ }
238327}`
239328
240329const testAccCheckHerokuAppConfig_updated = `
241330resource "heroku_app" "foobar" {
242- name = "terraform-test-renamed"
243- region = "us"
331+ name = "terraform-test-renamed"
332+ region = "us"
244333
245- config_vars {
246- FOO = "bing"
247- BAZ = "bar"
248- }
334+ config_vars {
335+ FOO = "bing"
336+ BAZ = "bar"
337+ }
249338}`
250339
251340const testAccCheckHerokuAppConfig_no_vars = `
252341resource "heroku_app" "foobar" {
253- name = "terraform-test-app"
254- region = "us"
342+ name = "terraform-test-app"
343+ region = "us"
344+ }`
345+
346+ const testAccCheckHerokuAppConfig_organization = `
347+ resource "heroku_app" "foobar" {
348+ name = "terraform-test-app"
349+ region = "us"
350+
351+ organization {
352+ name = "%s"
353+ }
354+
355+ config_vars {
356+ FOO = "bar"
357+ }
255358}`
0 commit comments