provider/aws: Generate random names for Beanstalk tests resources (#10367)

* provider/aws: Generate name for TestAccElasticBeanstalkApplicationImport

This allows tests to run concurrently.

* provider/aws: Generate names for TestAWSElasticBeanstalkEnvironment_importBasic

This allows tests to run concurrently.
This commit is contained in:
James Nugent 2016-11-25 15:44:41 +00:00 committed by Paul Stack
parent b77dac5ab8
commit 08b860290a
2 changed files with 34 additions and 6 deletions

View File

@ -1,24 +1,27 @@
package aws
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAWSElasticBeanstalkApplication_importBasic(t *testing.T) {
resourceName := "aws_elastic_beanstalk_application.tftest"
config := fmt.Sprintf("tf-test-name-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBeanstalkAppDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccBeanstalkAppConfig,
{
Config: testAccBeanstalkAppImportConfig(config),
},
resource.TestStep{
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
@ -26,3 +29,10 @@ func TestAWSElasticBeanstalkApplication_importBasic(t *testing.T) {
},
})
}
func testAccBeanstalkAppImportConfig(name string) string {
return fmt.Sprintf(`resource "aws_elastic_beanstalk_application" "tftest" {
name = "%s"
description = "tf-test-desc"
}`, name)
}

View File

@ -1,24 +1,29 @@
package aws
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAWSElasticBeanstalkEnvironment_importBasic(t *testing.T) {
resourceName := "aws_elastic_beanstalk_application.tftest"
applicationName := fmt.Sprintf("tf-test-name-%d", acctest.RandInt())
environmentName := fmt.Sprintf("tf-test-env-name-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBeanstalkAppDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccBeanstalkEnvConfig,
{
Config: testAccBeanstalkEnvImportConfig(applicationName, environmentName),
},
resource.TestStep{
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
@ -26,3 +31,16 @@ func TestAWSElasticBeanstalkEnvironment_importBasic(t *testing.T) {
},
})
}
func testAccBeanstalkEnvImportConfig(appName, envName string) string {
return fmt.Sprintf(`resource "aws_elastic_beanstalk_application" "tftest" {
name = "%s"
description = "tf-test-desc"
}
resource "aws_elastic_beanstalk_environment" "tfenvtest" {
name = "%s"
application = "${aws_elastic_beanstalk_application.tftest.name}"
solution_stack_name = "64bit Amazon Linux running Python"
}`, appName, envName)
}