provider/aws: Fix acceptance tests for autoscaling schedule

Fixes acceptance tests for `aws_autoscaling_schedule` resource

```
$ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSAutoscalingSchedule_basic'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/01/30 14:40:34 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSAutoscalingSchedule_basic -timeout 120m
=== RUN   TestAccAWSAutoscalingSchedule_basic
--- PASS: TestAccAWSAutoscalingSchedule_basic (170.38s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/aws	170.406s
```

```
$ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSAutoscalingSchedule_disappears'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/01/30 15:00:49 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSAutoscalingSchedule_disappears -timeout 120m
=== RUN   TestAccAWSAutoscalingSchedule_disappears
--- PASS: TestAccAWSAutoscalingSchedule_disappears (179.23s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/aws	179.253s
```
This commit is contained in:
Jake Champlin 2017-01-30 15:07:10 -05:00
parent 870b85765b
commit feafe3c0b5
No known key found for this signature in database
GPG Key ID: DC31F41958EF4AC2
2 changed files with 42 additions and 19 deletions

View File

@ -20,48 +20,48 @@ func resourceAwsAutoscalingSchedule() *schema.Resource {
Delete: resourceAwsAutoscalingScheduleDelete,
Schema: map[string]*schema.Schema{
"arn": &schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"scheduled_action_name": &schema.Schema{
"scheduled_action_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"autoscaling_group_name": &schema.Schema{
"autoscaling_group_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"start_time": &schema.Schema{
"start_time": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validateASGScheduleTimestamp,
},
"end_time": &schema.Schema{
"end_time": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validateASGScheduleTimestamp,
},
"recurrence": &schema.Schema{
"recurrence": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"min_size": &schema.Schema{
"min_size": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"max_size": &schema.Schema{
"max_size": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"desired_capacity": &schema.Schema{
"desired_capacity": {
Type: schema.TypeInt,
Optional: true,
Computed: true,

View File

@ -3,6 +3,7 @@ package aws
import (
"fmt"
"testing"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/autoscaling"
@ -13,16 +14,26 @@ import (
func TestAccAWSAutoscalingSchedule_basic(t *testing.T) {
var schedule autoscaling.ScheduledUpdateGroupAction
rName := fmt.Sprintf("tf-test-%d", acctest.RandInt())
n := time.Now().UTC()
d, err := time.ParseDuration("2h")
if err != nil {
t.Fatalf("err parsing time duration: %s", err)
}
s, err := time.ParseDuration("1h")
if err != nil {
t.Fatalf("err parsing time duration: %s", err)
}
start := n.Add(s).Format(awsAutoscalingScheduleTimeLayout)
end := n.Add(d).Format(awsAutoscalingScheduleTimeLayout)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAutoscalingScheduleDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSAutoscalingScheduleConfig(rName),
{
Config: testAccAWSAutoscalingScheduleConfig(rName, start, end),
Check: resource.ComposeTestCheckFunc(
testAccCheckScalingScheduleExists("aws_autoscaling_schedule.foobar", &schedule),
),
@ -34,13 +45,25 @@ func TestAccAWSAutoscalingSchedule_basic(t *testing.T) {
func TestAccAWSAutoscalingSchedule_disappears(t *testing.T) {
var schedule autoscaling.ScheduledUpdateGroupAction
rName := fmt.Sprintf("tf-test-%d", acctest.RandInt())
n := time.Now().UTC()
d, err := time.ParseDuration("2h")
if err != nil {
t.Fatalf("err parsing time duration: %s", err)
}
s, err := time.ParseDuration("1h")
if err != nil {
t.Fatalf("err parsing time duration: %s", err)
}
start := n.Add(s).Format(awsAutoscalingScheduleTimeLayout)
end := n.Add(d).Format(awsAutoscalingScheduleTimeLayout)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAutoscalingScheduleDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSAutoscalingScheduleConfig(rName),
{
Config: testAccAWSAutoscalingScheduleConfig(rName, start, end),
Check: resource.ComposeTestCheckFunc(
testAccCheckScalingScheduleExists("aws_autoscaling_schedule.foobar", &schedule),
testAccCheckScalingScheduleDisappears(&schedule),
@ -74,7 +97,7 @@ func TestAccAWSAutoscalingSchedule_recurrence(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAutoscalingScheduleDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccAWSAutoscalingScheduleConfig_recurrence(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckScalingScheduleExists("aws_autoscaling_schedule.foobar", &schedule),
@ -159,7 +182,7 @@ func testAccCheckAWSAutoscalingScheduleDestroy(s *terraform.State) error {
return nil
}
func testAccAWSAutoscalingScheduleConfig(r string) string {
func testAccAWSAutoscalingScheduleConfig(r, start, end string) string {
return fmt.Sprintf(`
resource "aws_launch_configuration" "foobar" {
name = "%s"
@ -189,10 +212,10 @@ resource "aws_autoscaling_schedule" "foobar" {
min_size = 0
max_size = 1
desired_capacity = 0
start_time = "2016-12-11T18:00:00Z"
end_time = "2016-12-12T06:00:00Z"
start_time = "%s"
end_time = "%s"
autoscaling_group_name = "${aws_autoscaling_group.foobar.name}"
}`, r, r)
}`, r, r, start, end)
}
func testAccAWSAutoscalingScheduleConfig_recurrence(r string) string {