Skip to content

Commit

Permalink
Fixes panic
Browse files Browse the repository at this point in the history
  • Loading branch information
gdavison committed Jul 10, 2024
1 parent 78ced03 commit ec491cd
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/service/pinpoint/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func findAppSettingsByID(ctx context.Context, conn *pinpoint.Pinpoint, id string
}

func expandCampaignHook(configs []interface{}) *pinpoint.CampaignHook {
if len(configs) == 0 {
if len(configs) == 0 || configs[0] == nil {
return nil
}

Expand Down Expand Up @@ -351,7 +351,7 @@ func flattenCampaignHook(ch *pinpoint.CampaignHook) []interface{} {
}

func expandCampaignLimits(configs []interface{}) *pinpoint.CampaignLimits {
if len(configs) == 0 {
if len(configs) == 0 || configs[0] == nil {
return nil
}

Expand Down Expand Up @@ -394,7 +394,7 @@ func flattenCampaignLimits(cl *pinpoint.CampaignLimits) []interface{} {
}

func expandQuietTime(configs []interface{}) *pinpoint.QuietTime {
if len(configs) == 0 {
if len(configs) == 0 || configs[0] == nil {
return nil
}

Expand Down
138 changes: 138 additions & 0 deletions internal/service/pinpoint/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,42 @@ func TestAccPinpointApp_campaignHookLambda(t *testing.T) {
})
}

func TestAccPinpointApp_campaignHookEmpty(t *testing.T) {
ctx := acctest.Context(t)
var application pinpoint.ApplicationResponse
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_pinpoint_app.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckApp(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.PinpointServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckAppDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccAppConfig_campaignHookEmpty(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppExists(ctx, resourceName, &application),
),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("campaign_hook"), knownvalue.ListExact([]knownvalue.Check{
knownvalue.ObjectExact(map[string]knownvalue.Check{
"lambda_function_name": knownvalue.StringExact(""),
names.AttrMode: knownvalue.StringExact(""),
"web_url": knownvalue.StringExact(""),
}),
})),
},
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccPinpointApp_limits(t *testing.T) {
ctx := acctest.Context(t)
var application pinpoint.ApplicationResponse
Expand Down Expand Up @@ -269,6 +305,43 @@ func TestAccPinpointApp_limits(t *testing.T) {
})
}

func TestAccPinpointApp_limitsEmpty(t *testing.T) {
ctx := acctest.Context(t)
var application pinpoint.ApplicationResponse
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_pinpoint_app.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckApp(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.PinpointServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckAppDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccAppConfig_limitsEmpty(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppExists(ctx, resourceName, &application),
),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("limits"), knownvalue.ListExact([]knownvalue.Check{
knownvalue.ObjectExact(map[string]knownvalue.Check{
"daily": knownvalue.Int64Exact(0),
"maximum_duration": knownvalue.Int64Exact(0),
"messages_per_second": knownvalue.Int64Exact(0),
"total": knownvalue.Int64Exact(0),
}),
})),
},
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccPinpointApp_quietTime(t *testing.T) {
ctx := acctest.Context(t)
var application pinpoint.ApplicationResponse
Expand Down Expand Up @@ -304,6 +377,41 @@ func TestAccPinpointApp_quietTime(t *testing.T) {
})
}

func TestAccPinpointApp_quietTimeEmpty(t *testing.T) {
ctx := acctest.Context(t)
var application pinpoint.ApplicationResponse
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_pinpoint_app.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckApp(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.PinpointServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckAppDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccAppConfig_quietTimeEmpty(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppExists(ctx, resourceName, &application),
),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("quiet_time"), knownvalue.ListExact([]knownvalue.Check{
knownvalue.ObjectExact(map[string]knownvalue.Check{
"end": knownvalue.StringExact(""),
"start": knownvalue.StringExact(""),
}),
})),
},
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccPreCheckApp(ctx context.Context, t *testing.T) {
t.Helper()
acctest.PreCheckPinpointApp(ctx, t)
Expand Down Expand Up @@ -461,6 +569,16 @@ resource "aws_lambda_permission" "test" {
`, rName)
}

func testAccAppConfig_campaignHookEmpty(rName string) string {
return fmt.Sprintf(`
resource "aws_pinpoint_app" "test" {
name = %[1]q
campaign_hook {}
}
`, rName)
}

func testAccAppConfig_limits(rName string) string {
return fmt.Sprintf(`
resource "aws_pinpoint_app" "test" {
Expand All @@ -476,6 +594,16 @@ resource "aws_pinpoint_app" "test" {
`, rName)
}

func testAccAppConfig_limitsEmpty(rName string) string {
return fmt.Sprintf(`
resource "aws_pinpoint_app" "test" {
name = %[1]q
limits {}
}
`, rName)
}

func testAccAppConfig_quietTime(rName string) string {
return fmt.Sprintf(`
resource "aws_pinpoint_app" "test" {
Expand All @@ -488,3 +616,13 @@ resource "aws_pinpoint_app" "test" {
}
`, rName)
}

func testAccAppConfig_quietTimeEmpty(rName string) string {
return fmt.Sprintf(`
resource "aws_pinpoint_app" "test" {
name = %[1]q
quiet_time {}
}
`, rName)
}

0 comments on commit ec491cd

Please sign in to comment.