From 40f4dd5ad936c1b51b60b8754b86df0d612520c0 Mon Sep 17 00:00:00 2001 From: Anthony Stanton Date: Thu, 22 Sep 2016 11:57:49 +0200 Subject: [PATCH] provider/librato: Fixes for various integer type casting bugs Fixes #8968 --- resource_librato_alert.go | 10 +++--- resource_librato_alert_test.go | 64 ++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/resource_librato_alert.go b/resource_librato_alert.go index 41e2b88..ac61f45 100644 --- a/resource_librato_alert.go +++ b/resource_librato_alert.go @@ -182,8 +182,8 @@ func resourceLibratoAlertCreate(d *schema.ResourceData, meta interface{}) error if v, ok := conditionData["detect_reset"].(bool); ok { condition.DetectReset = librato.Bool(v) } - if v, ok := conditionData["duration"].(uint); ok { - condition.Duration = librato.Uint(v) + if v, ok := conditionData["duration"].(int); ok { + condition.Duration = librato.Uint(uint(v)) } if v, ok := conditionData["summary_function"].(string); ok && v != "" { condition.SummaryFunction = librato.String(v) @@ -343,7 +343,7 @@ func resourceLibratoAlertUpdate(d *schema.ResourceData, meta interface{}) error alert.Active = librato.Bool(d.Get("active").(bool)) } if d.HasChange("rearm_seconds") { - alert.RearmSeconds = librato.Uint(d.Get("rearm_seconds").(uint)) + alert.RearmSeconds = librato.Uint(uint(d.Get("rearm_seconds").(int))) } if d.HasChange("services") { vs := d.Get("services").(*schema.Set) @@ -374,8 +374,8 @@ func resourceLibratoAlertUpdate(d *schema.ResourceData, meta interface{}) error if v, ok := conditionData["detect_reset"].(bool); ok { condition.DetectReset = librato.Bool(v) } - if v, ok := conditionData["duration"].(uint); ok { - condition.Duration = librato.Uint(v) + if v, ok := conditionData["duration"].(int); ok { + condition.Duration = librato.Uint(uint(v)) } if v, ok := conditionData["summary_function"].(string); ok && v != "" { condition.SummaryFunction = librato.String(v) diff --git a/resource_librato_alert_test.go b/resource_librato_alert_test.go index e244b60..1bac6a0 100644 --- a/resource_librato_alert_test.go +++ b/resource_librato_alert_test.go @@ -46,6 +46,12 @@ func TestAccLibratoAlert_Full(t *testing.T) { testAccCheckLibratoAlertName(&alert, "FooBar"), resource.TestCheckResourceAttr( "librato_alert.foobar", "name", "FooBar"), + resource.TestCheckResourceAttr( + "librato_alert.foobar", "condition.836525194.metric_name", "librato.cpu.percent.idle"), + resource.TestCheckResourceAttr( + "librato_alert.foobar", "condition.836525194.threshold", "10"), + resource.TestCheckResourceAttr( + "librato_alert.foobar", "condition.836525194.duration", "600"), ), }, }, @@ -82,6 +88,35 @@ func TestAccLibratoAlert_Updated(t *testing.T) { }) } +func TestAccLibratoAlert_FullUpdate(t *testing.T) { + var alert librato.Alert + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLibratoAlertDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckLibratoAlertConfig_full_update, + Check: resource.ComposeTestCheckFunc( + testAccCheckLibratoAlertExists("librato_alert.foobar", &alert), + testAccCheckLibratoAlertName(&alert, "FooBar"), + resource.TestCheckResourceAttr( + "librato_alert.foobar", "name", "FooBar"), + resource.TestCheckResourceAttr( + "librato_alert.foobar", "rearm_seconds", "1200"), + resource.TestCheckResourceAttr( + "librato_alert.foobar", "condition.2524844643.metric_name", "librato.cpu.percent.idle"), + resource.TestCheckResourceAttr( + "librato_alert.foobar", "condition.2524844643.threshold", "10"), + resource.TestCheckResourceAttr( + "librato_alert.foobar", "condition.2524844643.duration", "60"), + ), + }, + }, + }) +} + func testAccCheckLibratoAlertDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*librato.Client) @@ -192,6 +227,7 @@ resource "librato_alert" "foobar" { condition { type = "above" threshold = 10 + duration = 600 metric_name = "librato.cpu.percent.idle" } attributes { @@ -200,3 +236,31 @@ resource "librato_alert" "foobar" { active = false rearm_seconds = 300 }` + +const testAccCheckLibratoAlertConfig_full_update = ` +resource "librato_service" "foobar" { + title = "Foo Bar" + type = "mail" + settings = <