provider/aws: Fix Cloudwatch Log acceptance tests
Fixes `aws_cloudwatch_log_group` and `aws_cloudwatch_log_metric_filter` acceptance tests ``` $ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSCloudWatchLogMetricFilter_basic' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/01/31 12:01:05 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSCloudWatchLogMetricFilter_basic -timeout 120m === RUN TestAccAWSCloudWatchLogMetricFilter_basic --- PASS: TestAccAWSCloudWatchLogMetricFilter_basic (27.36s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 27.390s ``` ``` $ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSCloudWatchLogGroup_multiple' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/01/31 12:03:18 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSCloudWatchLogGroup_multiple -timeout 120m === RUN TestAccAWSCloudWatchLogGroup_multiple --- PASS: TestAccAWSCloudWatchLogGroup_multiple (16.39s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 16.422s ```
This commit is contained in:
parent
20c0668c6b
commit
7e23340f3a
|
@ -254,5 +254,5 @@ resource "aws_cloudwatch_log_group" "charlie" {
|
|||
name = "foo-bar-%d"
|
||||
retention_in_days = 3653
|
||||
}
|
||||
`, rInt, rInt, rInt)
|
||||
`, rInt, rInt+1, rInt+2)
|
||||
}
|
||||
|
|
|
@ -6,27 +6,29 @@ import (
|
|||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestAccAWSCloudWatchLogMetricFilter_basic(t *testing.T) {
|
||||
var mf cloudwatchlogs.MetricFilter
|
||||
rInt := acctest.RandInt()
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckAWSCloudWatchLogMetricFilterDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccAWSCloudWatchLogMetricFilterConfig,
|
||||
{
|
||||
Config: testAccAWSCloudWatchLogMetricFilterConfig(rInt),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckCloudWatchLogMetricFilterExists("aws_cloudwatch_log_metric_filter.foobar", &mf),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "name", "MyAppAccessCount"),
|
||||
testAccCheckCloudWatchLogMetricFilterName(&mf, "MyAppAccessCount"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "name", fmt.Sprintf("MyAppAccessCount-%d", rInt)),
|
||||
testAccCheckCloudWatchLogMetricFilterName(&mf, fmt.Sprintf("MyAppAccessCount-%d", rInt)),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "pattern", ""),
|
||||
testAccCheckCloudWatchLogMetricFilterPattern(&mf, ""),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "log_group_name", "MyApp/access.log"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "log_group_name", fmt.Sprintf("MyApp/access-%d.log", rInt)),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "metric_transformation.0.name", "EventCount"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "metric_transformation.0.namespace", "YourNamespace"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "metric_transformation.0.value", "1"),
|
||||
|
@ -37,15 +39,15 @@ func TestAccAWSCloudWatchLogMetricFilter_basic(t *testing.T) {
|
|||
}),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: testAccAWSCloudWatchLogMetricFilterConfigModified,
|
||||
{
|
||||
Config: testAccAWSCloudWatchLogMetricFilterConfigModified(rInt),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckCloudWatchLogMetricFilterExists("aws_cloudwatch_log_metric_filter.foobar", &mf),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "name", "MyAppAccessCount"),
|
||||
testAccCheckCloudWatchLogMetricFilterName(&mf, "MyAppAccessCount"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "name", fmt.Sprintf("MyAppAccessCount-%d", rInt)),
|
||||
testAccCheckCloudWatchLogMetricFilterName(&mf, fmt.Sprintf("MyAppAccessCount-%d", rInt)),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "pattern", "{ $.errorCode = \"AccessDenied\" }"),
|
||||
testAccCheckCloudWatchLogMetricFilterPattern(&mf, "{ $.errorCode = \"AccessDenied\" }"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "log_group_name", "MyApp/access.log"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "log_group_name", fmt.Sprintf("MyApp/access-%d.log", rInt)),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "metric_transformation.0.name", "AccessDeniedCount"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "metric_transformation.0.namespace", "MyNamespace"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "metric_transformation.0.value", "2"),
|
||||
|
@ -146,9 +148,10 @@ func testAccCheckAWSCloudWatchLogMetricFilterDestroy(s *terraform.State) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var testAccAWSCloudWatchLogMetricFilterConfig = `
|
||||
func testAccAWSCloudWatchLogMetricFilterConfig(rInt int) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "aws_cloudwatch_log_metric_filter" "foobar" {
|
||||
name = "MyAppAccessCount"
|
||||
name = "MyAppAccessCount-%d"
|
||||
pattern = ""
|
||||
log_group_name = "${aws_cloudwatch_log_group.dada.name}"
|
||||
|
||||
|
@ -160,13 +163,15 @@ resource "aws_cloudwatch_log_metric_filter" "foobar" {
|
|||
}
|
||||
|
||||
resource "aws_cloudwatch_log_group" "dada" {
|
||||
name = "MyApp/access.log"
|
||||
name = "MyApp/access-%d.log"
|
||||
}
|
||||
`, rInt, rInt)
|
||||
}
|
||||
`
|
||||
|
||||
var testAccAWSCloudWatchLogMetricFilterConfigModified = `
|
||||
func testAccAWSCloudWatchLogMetricFilterConfigModified(rInt int) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "aws_cloudwatch_log_metric_filter" "foobar" {
|
||||
name = "MyAppAccessCount"
|
||||
name = "MyAppAccessCount-%d"
|
||||
pattern = <<PATTERN
|
||||
{ $.errorCode = "AccessDenied" }
|
||||
PATTERN
|
||||
|
@ -180,6 +185,7 @@ PATTERN
|
|||
}
|
||||
|
||||
resource "aws_cloudwatch_log_group" "dada" {
|
||||
name = "MyApp/access.log"
|
||||
name = "MyApp/access-%d.log"
|
||||
}
|
||||
`, rInt, rInt)
|
||||
}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue