Skip to content

Commit

Permalink
Add wafregional_byte_match_set test
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukegoto committed May 3, 2017
1 parent 8f0ef7d commit 2ba6e2b
Showing 1 changed file with 186 additions and 0 deletions.
186 changes: 186 additions & 0 deletions builtin/providers/aws/resource_aws_wafregional_byte_match_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ func TestAccAWSWafRegionalByteMatchSet_basic(t *testing.T) {
"aws_wafregional_byte_match_set.byte_set", "name", byteMatchSet),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.#", "2"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.target_string", "badrefer1"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.text_transformation", "NONE"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.target_string", "badrefer2"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.text_transformation", "NONE"),
),
},
},
Expand All @@ -55,6 +75,26 @@ func TestAccAWSWafRegionalByteMatchSet_changeNameForceNew(t *testing.T) {
"aws_wafregional_byte_match_set.byte_set", "name", byteMatchSet),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.#", "2"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.target_string", "badrefer1"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.text_transformation", "NONE"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.target_string", "badrefer2"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.text_transformation", "NONE"),
),
},
{
Expand All @@ -65,6 +105,120 @@ func TestAccAWSWafRegionalByteMatchSet_changeNameForceNew(t *testing.T) {
"aws_wafregional_byte_match_set.byte_set", "name", byteMatchSetNewName),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.#", "2"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.target_string", "badrefer1"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.text_transformation", "NONE"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.target_string", "badrefer2"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.text_transformation", "NONE"),
),
},
},
})
}

func TestAccAWSWafRegionalByteMatchSet_changeByteMatchTuple(t *testing.T) {
var before, after waf.ByteMatchSet
byteMatchSetName := fmt.Sprintf("byte-batch-set-%s", acctest.RandString(5))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSWafRegionalByteMatchSetDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSWafRegionalByteMatchSetConfig(byteMatchSetName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSWafRegionalByteMatchSetExists("aws_wafregional_byte_match_set.byte_set", &before),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "name", byteMatchSetName),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.#", "2"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.target_string", "badrefer1"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2174619346.text_transformation", "NONE"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.target_string", "badrefer2"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.839525137.text_transformation", "NONE"),
),
},
{
Config: testAccAWSWafRegionalByteMatchSetConfigChangeByteMatchTuple(byteMatchSetName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSWafRegionalByteMatchSetExists("aws_wafregional_byte_match_set.byte_set", &after),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "name", byteMatchSetName),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.#", "2"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2397850647.field_to_match.4253810390.data", "GET"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2397850647.field_to_match.4253810390.type", "METHOD"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2397850647.positional_constraint", "STARTS_WITH"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2397850647.target_string", "badrefer1+"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.2397850647.text_transformation", "LOWERCASE"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.4153613423.field_to_match.3756326843.data", ""),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.4153613423.field_to_match.3756326843.type", "URI"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.4153613423.positional_constraint", "ENDS_WITH"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.4153613423.target_string", "badrefer2+"),
resource.TestCheckResourceAttr(
"aws_wafregional_byte_match_set.byte_set", "byte_match_tuple.4153613423.text_transformation", "LOWERCASE"),
),
},
},
})
}

func TestAccAWSWafRegionalByteMatchSet_noByteMatchTuples(t *testing.T) {
var byteMatchSet waf.ByteMatchSet
byteMatchSetName := fmt.Sprintf("byte-batch-set-%s", acctest.RandString(5))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSWafRegionalByteMatchSetDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSWafRegionalByteMatchSetConfig_noDescriptors(byteMatchSetName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSWafRegionalByteMatchSetExists("aws_wafregional_byte_match_set.byte_match_set", &byteMatchSet),
resource.TestCheckResourceAttr("aws_wafregional_byte_match_set.byte_match_set", "name", byteMatchSetName),
resource.TestCheckResourceAttr("aws_wafregional_byte_match_set.byte_match_set", "byte_match_tuple.#", "0"),
),
},
},
Expand Down Expand Up @@ -248,3 +402,35 @@ resource "aws_wafregional_byte_match_set" "byte_set" {
}
}`, name)
}

func testAccAWSWafRegionalByteMatchSetConfig_noDescriptors(name string) string {
return fmt.Sprintf(`
resource "aws_wafregional_byte_match_set" "byte_match_set" {
name = "%s"
}`, name)
}

func testAccAWSWafRegionalByteMatchSetConfigChangeByteMatchTuple(name string) string {
return fmt.Sprintf(`
resource "aws_wafregional_byte_match_set" "byte_set" {
name = "%s"
byte_match_tuple {
text_transformation = "LOWERCASE"
target_string = "badrefer1+"
positional_constraint = "STARTS_WITH"
field_to_match {
type = "METHOD"
data = "GET"
}
}
byte_match_tuple {
text_transformation = "LOWERCASE"
target_string = "badrefer2+"
positional_constraint = "ENDS_WITH"
field_to_match {
type = "URI"
}
}
}`, name)
}

0 comments on commit 2ba6e2b

Please sign in to comment.