7
7
"net/http"
8
8
"net/http/httptest"
9
9
"reflect"
10
+ "strings"
10
11
"testing"
11
12
12
13
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
@@ -19,18 +20,17 @@ import (
19
20
func TestAccHerokuApp_Basic (t * testing.T ) {
20
21
var app heroku.App
21
22
appName := fmt .Sprintf ("tftest-%s" , acctest .RandString (10 ))
22
- appStack := "heroku-20"
23
23
24
24
resource .Test (t , resource.TestCase {
25
25
PreCheck : func () { testAccPreCheck (t ) },
26
26
Providers : testAccProviders ,
27
27
CheckDestroy : testAccCheckHerokuAppDestroy ,
28
28
Steps : []resource.TestStep {
29
29
{
30
- Config : testAccCheckHerokuAppConfig_basic (appName , appStack ),
30
+ Config : testAccCheckHerokuAppConfig_basic (appName ),
31
31
Check : resource .ComposeTestCheckFunc (
32
32
testAccCheckHerokuAppExists ("heroku_app.foobar" , & app ),
33
- testAccCheckHerokuAppAttributes (& app , appName , "heroku-20" ),
33
+ testAccCheckHerokuAppAttributes (& app , appName ),
34
34
resource .TestCheckResourceAttr (
35
35
"heroku_app.foobar" , "name" , appName ),
36
36
resource .TestCheckResourceAttrSet (
@@ -41,6 +41,16 @@ func TestAccHerokuApp_Basic(t *testing.T) {
41
41
"heroku_app.foobar" , "internal_routing" , "false" ),
42
42
resource .TestCheckResourceAttr (
43
43
"heroku_app.foobar" , "all_config_vars.%" , "1" ),
44
+ resource .TestCheckResourceAttrWith (
45
+ "heroku_app.foobar" , "heroku_hostname" , func (value string ) error {
46
+ if ! strings .HasSuffix (value , "herokuapp.com" ) {
47
+ return fmt .Errorf (fmt .Sprintf ("'%s' should end with 'herokuapp.com'" , value ))
48
+ }
49
+ if ! strings .HasPrefix (value , appName ) {
50
+ return fmt .Errorf (fmt .Sprintf ("'%s' should start with '%s'" , value , appName ))
51
+ }
52
+ return nil
53
+ }),
44
54
),
45
55
},
46
56
},
@@ -49,14 +59,13 @@ func TestAccHerokuApp_Basic(t *testing.T) {
49
59
50
60
func TestAccHerokuApp_DontSetAllConfigVars (t * testing.T ) {
51
61
appName := fmt .Sprintf ("tftest-%s" , acctest .RandString (10 ))
52
- appStack := "heroku-20"
53
62
54
63
resource .Test (t , resource.TestCase {
55
64
PreCheck : func () { testAccPreCheck (t ) },
56
65
ProviderFactories : testAccProviderFactories ,
57
66
Steps : []resource.TestStep {
58
67
{
59
- Config : testAccCheckHerokuAppConfig_DontSetConfigVars (appName , appStack ),
68
+ Config : testAccCheckHerokuAppConfig_DontSetConfigVars (appName ),
60
69
Check : resource .ComposeTestCheckFunc (
61
70
resource .TestCheckResourceAttr (
62
71
"heroku_app.foobar" , "name" , appName ),
@@ -77,15 +86,14 @@ func TestAccHerokuApp_DontSetAllConfigVars(t *testing.T) {
77
86
func TestAccHerokuApp_Disappears (t * testing.T ) {
78
87
var app heroku.App
79
88
appName := fmt .Sprintf ("tftest-%s" , acctest .RandString (10 ))
80
- appStack := "heroku-18"
81
89
82
90
resource .Test (t , resource.TestCase {
83
91
PreCheck : func () { testAccPreCheck (t ) },
84
92
Providers : testAccProviders ,
85
93
CheckDestroy : testAccCheckHerokuAppDestroy ,
86
94
Steps : []resource.TestStep {
87
95
{
88
- Config : testAccCheckHerokuAppConfig_basic (appName , appStack ),
96
+ Config : testAccCheckHerokuAppConfig_basic (appName ),
89
97
Check : resource .ComposeTestCheckFunc (
90
98
testAccCheckHerokuAppExists ("heroku_app.foobar" , & app ),
91
99
testAccCheckHerokuAppDisappears (appName ),
@@ -100,36 +108,30 @@ func TestAccHerokuApp_Change(t *testing.T) {
100
108
var app heroku.App
101
109
appName := fmt .Sprintf ("tftest-%s" , acctest .RandString (10 ))
102
110
appName2 := fmt .Sprintf ("%s-v2" , appName )
103
- appStack := "heroku-18"
104
- appStack2 := "heroku-20"
105
111
106
112
resource .Test (t , resource.TestCase {
107
113
PreCheck : func () { testAccPreCheck (t ) },
108
114
Providers : testAccProviders ,
109
115
CheckDestroy : testAccCheckHerokuAppDestroy ,
110
116
Steps : []resource.TestStep {
111
117
{
112
- Config : testAccCheckHerokuAppConfig_basic (appName , appStack ),
118
+ Config : testAccCheckHerokuAppConfig_basic (appName ),
113
119
Check : resource .ComposeTestCheckFunc (
114
120
testAccCheckHerokuAppExists ("heroku_app.foobar" , & app ),
115
- testAccCheckHerokuAppAttributes (& app , appName , appStack ),
121
+ testAccCheckHerokuAppAttributes (& app , appName ),
116
122
resource .TestCheckResourceAttr (
117
123
"heroku_app.foobar" , "name" , appName ),
118
- resource .TestCheckResourceAttr (
119
- "heroku_app.foobar" , "stack" , appStack ),
120
124
resource .TestCheckResourceAttr (
121
125
"heroku_app.foobar" , "config_vars.FOO" , "bar" ),
122
126
),
123
127
},
124
128
{
125
- Config : testAccCheckHerokuAppConfig_updated (appName2 , appStack2 ),
129
+ Config : testAccCheckHerokuAppConfig_updated (appName2 ),
126
130
Check : resource .ComposeTestCheckFunc (
127
131
testAccCheckHerokuAppExists ("heroku_app.foobar" , & app ),
128
- testAccCheckHerokuAppAttributesUpdated (& app , appName2 , appStack2 ),
132
+ testAccCheckHerokuAppAttributesUpdated (& app , appName2 ),
129
133
resource .TestCheckResourceAttr (
130
134
"heroku_app.foobar" , "name" , appName2 ),
131
- resource .TestCheckResourceAttr (
132
- "heroku_app.foobar" , "stack" , appStack2 ),
133
135
resource .TestCheckResourceAttr (
134
136
"heroku_app.foobar" , "config_vars.FOO" , "bing" ),
135
137
resource .TestCheckResourceAttr (
@@ -143,18 +145,17 @@ func TestAccHerokuApp_Change(t *testing.T) {
143
145
func TestAccHerokuApp_NukeVars (t * testing.T ) {
144
146
var app heroku.App
145
147
appName := fmt .Sprintf ("tftest-%s" , acctest .RandString (10 ))
146
- appStack := "heroku-20"
147
148
148
149
resource .Test (t , resource.TestCase {
149
150
PreCheck : func () { testAccPreCheck (t ) },
150
151
Providers : testAccProviders ,
151
152
CheckDestroy : testAccCheckHerokuAppDestroy ,
152
153
Steps : []resource.TestStep {
153
154
{
154
- Config : testAccCheckHerokuAppConfig_basic (appName , appStack ),
155
+ Config : testAccCheckHerokuAppConfig_basic (appName ),
155
156
Check : resource .ComposeTestCheckFunc (
156
157
testAccCheckHerokuAppExists ("heroku_app.foobar" , & app ),
157
- testAccCheckHerokuAppAttributes (& app , appName , "heroku-20" ),
158
+ testAccCheckHerokuAppAttributes (& app , appName ),
158
159
resource .TestCheckResourceAttr (
159
160
"heroku_app.foobar" , "name" , appName ),
160
161
resource .TestCheckResourceAttr (
@@ -493,18 +494,14 @@ func testAccCheckHerokuAppDestroy(s *terraform.State) error {
493
494
return nil
494
495
}
495
496
496
- func testAccCheckHerokuAppAttributes (app * heroku.App , appName , stackName string ) resource.TestCheckFunc {
497
+ func testAccCheckHerokuAppAttributes (app * heroku.App , appName string ) resource.TestCheckFunc {
497
498
return func (s * terraform.State ) error {
498
499
client := testAccProvider .Meta ().(* Config ).Api
499
500
500
501
if app .Region .Name != "us" {
501
502
return fmt .Errorf ("Bad region: %s" , app .Region .Name )
502
503
}
503
504
504
- if app .BuildStack .Name != stackName {
505
- return fmt .Errorf ("Bad stack: %s" , app .BuildStack .Name )
506
- }
507
-
508
505
if app .Name != appName {
509
506
return fmt .Errorf ("Bad name: %s" , app .Name )
510
507
}
@@ -522,14 +519,10 @@ func testAccCheckHerokuAppAttributes(app *heroku.App, appName, stackName string)
522
519
}
523
520
}
524
521
525
- func testAccCheckHerokuAppAttributesUpdated (app * heroku.App , appName , stackName string ) resource.TestCheckFunc {
522
+ func testAccCheckHerokuAppAttributesUpdated (app * heroku.App , appName string ) resource.TestCheckFunc {
526
523
return func (s * terraform.State ) error {
527
524
client := testAccProvider .Meta ().(* Config ).Api
528
525
529
- if app .BuildStack .Name != stackName {
530
- return fmt .Errorf ("Bad stack: %s" , app .BuildStack .Name )
531
- }
532
-
533
526
if app .Name != appName {
534
527
return fmt .Errorf ("Bad name: %s" , app .Name )
535
528
}
@@ -765,17 +758,16 @@ func testAccCheckHerokuAppDisappears(appName string) resource.TestCheckFunc {
765
758
}
766
759
}
767
760
768
- func testAccCheckHerokuAppConfig_basic (appName , appStack string ) string {
761
+ func testAccCheckHerokuAppConfig_basic (appName string ) string {
769
762
return fmt .Sprintf (`
770
763
resource "heroku_app" "foobar" {
771
764
name = "%s"
772
- stack = "%s"
773
765
region = "us"
774
766
775
767
config_vars = {
776
768
FOO = "bar"
777
769
}
778
- }` , appName , appStack )
770
+ }` , appName )
779
771
}
780
772
781
773
func testAccCheckHerokuAppConfig_go (appName string ) string {
@@ -801,18 +793,17 @@ resource "heroku_app" "foobar" {
801
793
}` , appName )
802
794
}
803
795
804
- func testAccCheckHerokuAppConfig_updated (appName , appStack string ) string {
796
+ func testAccCheckHerokuAppConfig_updated (appName string ) string {
805
797
return fmt .Sprintf (`
806
798
resource "heroku_app" "foobar" {
807
799
name = "%s"
808
- stack = "%s"
809
800
region = "us"
810
801
811
802
config_vars = {
812
803
FOO = "bing"
813
804
BAZ = "bar"
814
805
}
815
- }` , appName , appStack )
806
+ }` , appName )
816
807
}
817
808
818
809
func testAccCheckHerokuAppConfig_no_vars (appName string ) string {
@@ -998,7 +989,7 @@ resource "heroku_app" "foobar" {
998
989
}` , appName , org , locked )
999
990
}
1000
991
1001
- func testAccCheckHerokuAppConfig_DontSetConfigVars (appName , appStack string ) string {
992
+ func testAccCheckHerokuAppConfig_DontSetConfigVars (appName string ) string {
1002
993
return fmt .Sprintf (`
1003
994
provider "heroku" {
1004
995
customizations {
@@ -1008,11 +999,10 @@ provider "heroku" {
1008
999
1009
1000
resource "heroku_app" "foobar" {
1010
1001
name = "%s"
1011
- stack = "%s"
1012
1002
region = "us"
1013
1003
1014
1004
config_vars = {
1015
1005
FOO = "bar"
1016
1006
}
1017
- }` , appName , appStack )
1007
+ }` , appName )
1018
1008
}
0 commit comments