Skip to content

Commit

Permalink
provider/aws: Add acceptance test for cloudwatch_log_group
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Sep 16, 2015
1 parent a180e37 commit 792dac3
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions builtin/providers/aws/resource_aws_cloudwatch_log_group_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package aws

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccAWSCloudWatchLogGroup_basic(t *testing.T) {
var lg cloudwatchlogs.LogGroup

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSCloudWatchLogGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSCloudWatchLogGroupConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudWatchLogGroupExists("aws_cloudwatch_log_group.foobar", &lg),
resource.TestCheckResourceAttr("aws_cloudwatch_log_group.foobar", "retention_in_days", ""),
),
},
},
})
}

func testAccCheckCloudWatchLogGroupExists(n string, lg *cloudwatchlogs.LogGroup) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}

conn := testAccProvider.Meta().(*AWSClient).cloudwatchlogsconn
logGroup, err := lookupCloudWatchLogGroup(conn, rs.Primary.ID, nil)
if err != nil {
return err
}

*lg = *logGroup

return nil
}
}

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

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_cloudwatch_log_group" {
continue
}

_, err := lookupCloudWatchLogGroup(conn, rs.Primary.ID, nil)
if err == nil {
return fmt.Errorf("LogGroup Still Exists: %s", rs.Primary.ID)
}
}

return nil
}

var testAccAWSCloudWatchLogGroupConfig = fmt.Sprintf(`
resource "aws_cloudwatch_log_group" "foobar" {
name = "foo-bar"
}
`)

0 comments on commit 792dac3

Please sign in to comment.