Skip to content

Commit

Permalink
Merge pull request #372 from heroku/randomized-herokuapp-names
Browse files Browse the repository at this point in the history
Prepare for randomized herokuapp.com app names
  • Loading branch information
mars authored May 24, 2023
2 parents a74bc62 + 03cade5 commit 69a18b0
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
HEROKU_EMAIL: [email protected]
HEROKU_TEST_USER: [email protected]
HEROKU_NON_ADMIN_TEST_USER: [email protected]
HEROKU_SLUG_ID: 8527dbf3-c0a0-4255-beab-aca0aad1dfc9
HEROKU_SLUG_ID: f2eba78f-25c9-476b-8998-2325241b980a
HEROKU_USER_ID: aaaa7bc7-7de5-410f-a60c-3741d2c355d1
# GOFLAGS: "-mod=vendor"
# TF_LOG: DEBUG
21 changes: 5 additions & 16 deletions heroku/data_source_heroku_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,29 @@ import (

func TestAccDatasourceHerokuApp_Basic(t *testing.T) {
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
appStack := "heroku-20"
gitUrl := fmt.Sprintf("https://git.heroku.com/%s.git", appName)
webUrl := fmt.Sprintf("https://%s.herokuapp.com/", appName)
herokuHostname := fmt.Sprintf("%s.herokuapp.com", appName)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckHerokuAppWithDatasource_basic(appName, appStack),
Config: testAccCheckHerokuAppWithDatasource_basic(appName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.heroku_app.foobar", "name", appName),
resource.TestCheckResourceAttrSet(
"data.heroku_app.foobar", "id"),
resource.TestCheckResourceAttr(
"data.heroku_app.foobar", "stack", appStack),
resource.TestCheckResourceAttr(
"data.heroku_app.foobar", "region", "us"),
resource.TestCheckResourceAttr(
"data.heroku_app.foobar", "git_url", gitUrl),
resource.TestCheckResourceAttr(
"data.heroku_app.foobar", "web_url", webUrl),
resource.TestCheckResourceAttr(
"data.heroku_app.foobar", "config_vars.FOO", "bar"),
resource.TestCheckResourceAttr(
"data.heroku_app.foobar", "buildpacks.0", "https://github.com/heroku/heroku-buildpack-multi-procfile"),
resource.TestCheckResourceAttr(
"data.heroku_app.foobar", "acm", "false"),
resource.TestCheckResourceAttr(
"data.heroku_app.foobar", "heroku_hostname", herokuHostname),
),
},
},
Expand Down Expand Up @@ -78,11 +69,10 @@ func TestAccDatasourceHerokuApp_Organization(t *testing.T) {
})
}

func testAccCheckHerokuApp_basic(appName string, stack string) string {
func testAccCheckHerokuApp_basic(appName string) string {
return fmt.Sprintf(`
resource "heroku_app" "foobar" {
name = "%s"
stack = "%s"
region = "us"
buildpacks = [
Expand All @@ -93,14 +83,13 @@ resource "heroku_app" "foobar" {
FOO = "bar"
}
}
`, appName, stack)
`, appName)
}

func testAccCheckHerokuAppWithDatasource_basic(appName string, stack string) string {
func testAccCheckHerokuAppWithDatasource_basic(appName string) string {
return fmt.Sprintf(`
resource "heroku_app" "foobar" {
name = "%s"
stack = "%s"
region = "us"
buildpacks = [
Expand All @@ -116,7 +105,7 @@ resource "heroku_app" "foobar" {
data "heroku_app" "foobar" {
name = "${heroku_app.foobar.name}"
}
`, appName, stack)
`, appName)
}

func testAccCheckHerokuApp_organization(appName, orgName string) string {
Expand Down
3 changes: 1 addition & 2 deletions heroku/import_heroku_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import (

func TestAccHerokuApp_importBasic(t *testing.T) {
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
appStack := "heroku-20"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckHerokuAppDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckHerokuAppConfig_basic(appName, appStack),
Config: testAccCheckHerokuAppConfig_basic(appName),
},
{
ResourceName: "heroku_app.foobar",
Expand Down
7 changes: 6 additions & 1 deletion heroku/resource_heroku_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"
"net/url"
"strings"
"time"

"github.com/hashicorp/go-uuid"
Expand Down Expand Up @@ -362,7 +363,11 @@ func setAppDetails(d *schema.ResourceData, app *application) (err error) {
err = d.Set("web_url", app.App.WebURL)
err = d.Set("acm", app.App.Acm)
err = d.Set("uuid", app.App.ID)
err = d.Set("heroku_hostname", fmt.Sprintf("%s.herokuapp.com", app.App.Name))
err = d.Set("heroku_hostname",
strings.TrimPrefix(
strings.TrimPrefix(
strings.TrimSuffix(
app.App.WebURL, "/"), "https://"), "http://"))

return err
}
Expand Down
68 changes: 29 additions & 39 deletions heroku/resource_heroku_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/http/httptest"
"reflect"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
Expand All @@ -19,18 +20,17 @@ import (
func TestAccHerokuApp_Basic(t *testing.T) {
var app heroku.App
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
appStack := "heroku-20"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckHerokuAppDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckHerokuAppConfig_basic(appName, appStack),
Config: testAccCheckHerokuAppConfig_basic(appName),
Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
testAccCheckHerokuAppAttributes(&app, appName, "heroku-20"),
testAccCheckHerokuAppAttributes(&app, appName),
resource.TestCheckResourceAttr(
"heroku_app.foobar", "name", appName),
resource.TestCheckResourceAttrSet(
Expand All @@ -41,6 +41,16 @@ func TestAccHerokuApp_Basic(t *testing.T) {
"heroku_app.foobar", "internal_routing", "false"),
resource.TestCheckResourceAttr(
"heroku_app.foobar", "all_config_vars.%", "1"),
resource.TestCheckResourceAttrWith(
"heroku_app.foobar", "heroku_hostname", func(value string) error {
if !strings.HasSuffix(value, "herokuapp.com") {
return fmt.Errorf(fmt.Sprintf("'%s' should end with 'herokuapp.com'", value))
}
if !strings.HasPrefix(value, appName) {
return fmt.Errorf(fmt.Sprintf("'%s' should start with '%s'", value, appName))
}
return nil
}),
),
},
},
Expand All @@ -49,14 +59,13 @@ func TestAccHerokuApp_Basic(t *testing.T) {

func TestAccHerokuApp_DontSetAllConfigVars(t *testing.T) {
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
appStack := "heroku-20"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccCheckHerokuAppConfig_DontSetConfigVars(appName, appStack),
Config: testAccCheckHerokuAppConfig_DontSetConfigVars(appName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"heroku_app.foobar", "name", appName),
Expand All @@ -77,15 +86,14 @@ func TestAccHerokuApp_DontSetAllConfigVars(t *testing.T) {
func TestAccHerokuApp_Disappears(t *testing.T) {
var app heroku.App
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
appStack := "heroku-18"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckHerokuAppDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckHerokuAppConfig_basic(appName, appStack),
Config: testAccCheckHerokuAppConfig_basic(appName),
Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
testAccCheckHerokuAppDisappears(appName),
Expand All @@ -100,36 +108,30 @@ func TestAccHerokuApp_Change(t *testing.T) {
var app heroku.App
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
appName2 := fmt.Sprintf("%s-v2", appName)
appStack := "heroku-18"
appStack2 := "heroku-20"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckHerokuAppDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckHerokuAppConfig_basic(appName, appStack),
Config: testAccCheckHerokuAppConfig_basic(appName),
Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
testAccCheckHerokuAppAttributes(&app, appName, appStack),
testAccCheckHerokuAppAttributes(&app, appName),
resource.TestCheckResourceAttr(
"heroku_app.foobar", "name", appName),
resource.TestCheckResourceAttr(
"heroku_app.foobar", "stack", appStack),
resource.TestCheckResourceAttr(
"heroku_app.foobar", "config_vars.FOO", "bar"),
),
},
{
Config: testAccCheckHerokuAppConfig_updated(appName2, appStack2),
Config: testAccCheckHerokuAppConfig_updated(appName2),
Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
testAccCheckHerokuAppAttributesUpdated(&app, appName2, appStack2),
testAccCheckHerokuAppAttributesUpdated(&app, appName2),
resource.TestCheckResourceAttr(
"heroku_app.foobar", "name", appName2),
resource.TestCheckResourceAttr(
"heroku_app.foobar", "stack", appStack2),
resource.TestCheckResourceAttr(
"heroku_app.foobar", "config_vars.FOO", "bing"),
resource.TestCheckResourceAttr(
Expand All @@ -143,18 +145,17 @@ func TestAccHerokuApp_Change(t *testing.T) {
func TestAccHerokuApp_NukeVars(t *testing.T) {
var app heroku.App
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
appStack := "heroku-20"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckHerokuAppDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckHerokuAppConfig_basic(appName, appStack),
Config: testAccCheckHerokuAppConfig_basic(appName),
Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
testAccCheckHerokuAppAttributes(&app, appName, "heroku-20"),
testAccCheckHerokuAppAttributes(&app, appName),
resource.TestCheckResourceAttr(
"heroku_app.foobar", "name", appName),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -493,18 +494,14 @@ func testAccCheckHerokuAppDestroy(s *terraform.State) error {
return nil
}

func testAccCheckHerokuAppAttributes(app *heroku.App, appName, stackName string) resource.TestCheckFunc {
func testAccCheckHerokuAppAttributes(app *heroku.App, appName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*Config).Api

if app.Region.Name != "us" {
return fmt.Errorf("Bad region: %s", app.Region.Name)
}

if app.BuildStack.Name != stackName {
return fmt.Errorf("Bad stack: %s", app.BuildStack.Name)
}

if app.Name != appName {
return fmt.Errorf("Bad name: %s", app.Name)
}
Expand All @@ -522,14 +519,10 @@ func testAccCheckHerokuAppAttributes(app *heroku.App, appName, stackName string)
}
}

func testAccCheckHerokuAppAttributesUpdated(app *heroku.App, appName, stackName string) resource.TestCheckFunc {
func testAccCheckHerokuAppAttributesUpdated(app *heroku.App, appName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*Config).Api

if app.BuildStack.Name != stackName {
return fmt.Errorf("Bad stack: %s", app.BuildStack.Name)
}

if app.Name != appName {
return fmt.Errorf("Bad name: %s", app.Name)
}
Expand Down Expand Up @@ -765,17 +758,16 @@ func testAccCheckHerokuAppDisappears(appName string) resource.TestCheckFunc {
}
}

func testAccCheckHerokuAppConfig_basic(appName, appStack string) string {
func testAccCheckHerokuAppConfig_basic(appName string) string {
return fmt.Sprintf(`
resource "heroku_app" "foobar" {
name = "%s"
stack = "%s"
region = "us"
config_vars = {
FOO = "bar"
}
}`, appName, appStack)
}`, appName)
}

func testAccCheckHerokuAppConfig_go(appName string) string {
Expand All @@ -801,18 +793,17 @@ resource "heroku_app" "foobar" {
}`, appName)
}

func testAccCheckHerokuAppConfig_updated(appName, appStack string) string {
func testAccCheckHerokuAppConfig_updated(appName string) string {
return fmt.Sprintf(`
resource "heroku_app" "foobar" {
name = "%s"
stack = "%s"
region = "us"
config_vars = {
FOO = "bing"
BAZ = "bar"
}
}`, appName, appStack)
}`, appName)
}

func testAccCheckHerokuAppConfig_no_vars(appName string) string {
Expand Down Expand Up @@ -998,7 +989,7 @@ resource "heroku_app" "foobar" {
}`, appName, org, locked)
}

func testAccCheckHerokuAppConfig_DontSetConfigVars(appName, appStack string) string {
func testAccCheckHerokuAppConfig_DontSetConfigVars(appName string) string {
return fmt.Sprintf(`
provider "heroku" {
customizations {
Expand All @@ -1008,11 +999,10 @@ provider "heroku" {
resource "heroku_app" "foobar" {
name = "%s"
stack = "%s"
region = "us"
config_vars = {
FOO = "bar"
}
}`, appName, appStack)
}`, appName)
}
1 change: 0 additions & 1 deletion heroku/resource_heroku_slug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ resource "heroku_slug" "foobar" {
test = "echo 'Just a test'"
diag = "echo 'Just diagnosis'"
}
stack = "heroku-18"
}`, appName)
}

Expand Down

0 comments on commit 69a18b0

Please sign in to comment.