Skip to content

Commit

Permalink
provider/librato: Fixes for various integer type casting bugs
Browse files Browse the repository at this point in the history
Fixes #8968
  • Loading branch information
elblivion authored and stack72 committed Sep 22, 2016
1 parent bd43f41 commit 40f4dd5
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
10 changes: 5 additions & 5 deletions resource_librato_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
64 changes: 64 additions & 0 deletions resource_librato_alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -192,6 +227,7 @@ resource "librato_alert" "foobar" {
condition {
type = "above"
threshold = 10
duration = 600
metric_name = "librato.cpu.percent.idle"
}
attributes {
Expand All @@ -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 = <<EOF
{
"addresses": "[email protected]"
}
EOF
}
resource "librato_alert" "foobar" {
name = "FooBar"
description = "A Test Alert"
services = [ "${librato_service.foobar.id}" ]
condition {
type = "above"
threshold = 10
duration = 60
metric_name = "librato.cpu.percent.idle"
}
attributes {
runbook_url = "https://www.youtube.com/watch?v=oHg5SJYRHA0"
}
active = false
rearm_seconds = 1200
}`

0 comments on commit 40f4dd5

Please sign in to comment.