Skip to content

Commit

Permalink
Add acceptance test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharon Nam authored and Sharon Nam committed Jun 28, 2023
1 parent 58015df commit 2896d78
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/service/events/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func FindRuleByTwoPartKey(ctx context.Context, conn *eventbridge.EventBridge, ev
return output, nil
}

// Decodes unicode translation of <,>,&
// RuleEventPatternJSONDecoder decodes unicode translation of <,>,&
func RuleEventPatternJSONDecoder(jsonString interface{}) (string, error) {
var j interface{}

Expand Down
42 changes: 38 additions & 4 deletions internal/service/events/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ func TestRuleEventPatternJSONDecoder(t *testing.T) {
}
tests := map[string]testCase{
"lessThanGreaterThan": {
input: `{"detail": {"count": [ { "numeric": [ "\u003e", 0, "\u003c", 5 ] } ]}}`,
expected: `{"detail": {"count": [ { "numeric": [ ">", 0, "<", 5 ] } ]}}`,
input: `{"detail":{"count":[{"numeric":["\u003e",0,"\u003c",5]}]}}`,
expected: `{"detail":{"count":[{"numeric":[">",0,"<",5]}]}}`,
},
"ampersand": {
input: `{"detail": {"count": [ { "numeric": [ "\u0026", 0, "\u0026", 5 ] } ]}}`,
expected: `{"detail": {"count": [ { "numeric": [ "&", 0, "&", 5 ] } ]}}`,
input: `{"detail":{"count":[{"numeric":["\u0026",0,"\u0026",5]}]}}`,
expected: `{"detail":{"count":[{"numeric":["&",0,"&",5]}]}}`,
},
}

Expand Down Expand Up @@ -292,6 +292,31 @@ func TestAccEventsRule_pattern(t *testing.T) {
})
}

func TestAccEventsRule_patternJsonEncoder(t *testing.T) {
ctx := acctest.Context(t)
var v1 eventbridge.DescribeRuleOutput
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_cloudwatch_event_rule.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, eventbridge.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRuleDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccRuleConfig_patternJSONEncoder(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckRuleExists(ctx, resourceName, &v1),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "schedule_expression", ""),
acctest.CheckResourceAttrEquivalentJSON(resourceName, "event_pattern", `{"detail":{"count":[{"numeric":[">",0,"<",5]}]}}`),
),
},
},
})
}

func TestAccEventsRule_scheduleAndPattern(t *testing.T) {
ctx := acctest.Context(t)
var v eventbridge.DescribeRuleOutput
Expand Down Expand Up @@ -721,6 +746,15 @@ PATTERN
`, rName, pattern)
}

func testAccRuleConfig_patternJSONEncoder(rName string) string {
return fmt.Sprintf(`
resource "aws_cloudwatch_event_rule" "test" {
name = %[1]q
event_pattern = jsonencode({ "detail" : { "count" : [{ "numeric" : [">", 0, "<", 5] }] } })
}
`, rName)
}

func testAccRuleConfig_scheduleAndPattern(rName, pattern string) string {
return fmt.Sprintf(`
resource "aws_cloudwatch_event_rule" "test" {
Expand Down

0 comments on commit 2896d78

Please sign in to comment.