provider/librato: Fixes for various integer type casting bugs

Fixes #8968
This commit is contained in:
Anthony Stanton 2016-09-22 11:57:49 +02:00 committed by stack72
parent cfe7979692
commit 1d329c8927
No known key found for this signature in database
GPG Key ID: 8619A619B085CB16
2 changed files with 69 additions and 5 deletions

View File

@ -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)

View File

@ -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 = <<EOF
{
"addresses": "admin@example.com"
}
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
}`