Skip to content

Commit

Permalink
add acc test that fails on master
Browse files Browse the repository at this point in the history
  • Loading branch information
catsby committed Jul 28, 2016
1 parent 8de5bd7 commit a507cbc
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,17 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i
if len(add) > 0 {
for _, r := range rm {
for _, a := range add {
// ResourceNames are optional. Some defaults come with it, some do
// not. We need to guard against nil/empty in state as well as
// nil/empty from the API
if a.ResourceName != nil {
if r.ResourceName == nil {
continue
}
if *r.ResourceName != *a.ResourceName {
continue
}
}
if *r.Namespace == *a.Namespace && *r.OptionName == *a.OptionName {
continue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package aws
import (
"fmt"
"log"
"reflect"
"regexp"
"sort"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -178,6 +180,93 @@ func TestAccAWSBeanstalkEnv_vpc(t *testing.T) {
})
}

func TestAccAWSBeanstalkEnv_basic_settings_update(t *testing.T) {
var app elasticbeanstalk.EnvironmentDescription

rInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBeanstalkEnvDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccBeanstalkEnvConfig_empty_settings(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app),
testAccVerifyBeanstalkConfig(&app, []string{}),
),
},
resource.TestStep{
Config: testAccBeanstalkEnvConfig_settings(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app),
testAccVerifyBeanstalkConfig(&app, []string{"TF_LOG", "TF_SOME_VAR"}),
),
},
resource.TestStep{
Config: testAccBeanstalkEnvConfig_empty_settings(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app),
testAccVerifyBeanstalkConfig(&app, []string{}),
),
},
},
})
}

func testAccVerifyBeanstalkConfig(env *elasticbeanstalk.EnvironmentDescription, expected []string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if env == nil {
return fmt.Errorf("Nil environment in testAccVerifyBeanstalkConfig")
}
conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn

resp, err := conn.DescribeConfigurationSettings(&elasticbeanstalk.DescribeConfigurationSettingsInput{
ApplicationName: env.ApplicationName,
EnvironmentName: env.EnvironmentName,
})

if err != nil {
return fmt.Errorf("Error describing config settings in testAccVerifyBeanstalkConfig: %s", err)
}

// should only be 1 environment
if len(resp.ConfigurationSettings) != 1 {
return fmt.Errorf("Expected only 1 set of Configuration Settings in testAccVerifyBeanstalkConfig, got (%d)", len(resp.ConfigurationSettings))
}

cs := resp.ConfigurationSettings[0]

var foundEnvs []string
testStrings := []string{"TF_LOG", "TF_SOME_VAR"}
for _, os := range cs.OptionSettings {
for _, k := range testStrings {
if *os.OptionName == k {
foundEnvs = append(foundEnvs, k)
}
}
}

// if expected is zero, then we should not have found any of the predefined
// env vars
if len(expected) == 0 {
if len(foundEnvs) > 0 {
return fmt.Errorf("Found configs we should not have: %#v", foundEnvs)
}
return nil
}

sort.Strings(testStrings)
sort.Strings(expected)
if !reflect.DeepEqual(testStrings, expected) {
return fmt.Errorf("Error matching strings, expected:\n\n%#v\n\ngot:\n\n%#v\n", testStrings, foundEnvs)
}

return nil
}
}

func testAccCheckBeanstalkEnvDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn

Expand Down Expand Up @@ -342,6 +431,71 @@ resource "aws_elastic_beanstalk_environment" "tfenvtest" {
}
`

func testAccBeanstalkEnvConfig_empty_settings(r int) string {
return fmt.Sprintf(`
resource "aws_elastic_beanstalk_application" "tftest" {
name = "tf-test-name-%d"
description = "tf-test-desc"
}
resource "aws_elastic_beanstalk_environment" "tfenvtest" {
name = "tf-test-name-%d"
application = "${aws_elastic_beanstalk_application.tftest.name}"
solution_stack_name = "64bit Amazon Linux running Python"
wait_for_ready_timeout = "15m"
}`, r, r)
}

func testAccBeanstalkEnvConfig_settings(r int) string {
return fmt.Sprintf(`
resource "aws_elastic_beanstalk_application" "tftest" {
name = "tf-test-name-%d"
description = "tf-test-desc"
}
resource "aws_elastic_beanstalk_environment" "tfenvtest" {
name = "tf-test-name-%d"
application = "${aws_elastic_beanstalk_application.tftest.name}"
solution_stack_name = "64bit Amazon Linux running Python"
wait_for_ready_timeout = "15m"
setting {
namespace = "aws:elasticbeanstalk:application:environment"
name = "TF_LOG"
value = "true"
}
setting {
namespace = "aws:elasticbeanstalk:application:environment"
name = "TF_SOME_VAR"
value = "true"
}
setting {
namespace = "aws:autoscaling:scheduledaction"
resource = "ScheduledAction01"
name = "MinSize"
value = 2
}
setting {
namespace = "aws:autoscaling:scheduledaction"
resource = "ScheduledAction01"
name = "MaxSize"
value = 3
}
setting {
namespace = "aws:autoscaling:scheduledaction"
resource = "ScheduledAction01"
name = "StartTime"
value = "2016-07-28T04:07:02Z"
}
}`, r, r)
}

const testAccBeanstalkWorkerEnvConfig = `
resource "aws_iam_instance_profile" "tftest" {
name = "tftest_profile"
Expand Down

0 comments on commit a507cbc

Please sign in to comment.