provider/librato: Randomize the test case names as dangling resources were causing failures
This commit is contained in:
parent
1d329c8927
commit
0867ed4961
|
@ -5,6 +5,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
"github.com/henrikhodne/go-librato/librato"
|
"github.com/henrikhodne/go-librato/librato"
|
||||||
|
@ -12,19 +13,20 @@ import (
|
||||||
|
|
||||||
func TestAccLibratoAlert_Basic(t *testing.T) {
|
func TestAccLibratoAlert_Basic(t *testing.T) {
|
||||||
var alert librato.Alert
|
var alert librato.Alert
|
||||||
|
name := acctest.RandString(10)
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckLibratoAlertDestroy,
|
CheckDestroy: testAccCheckLibratoAlertDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccCheckLibratoAlertConfig_basic,
|
Config: testAccCheckLibratoAlertConfig_basic(name),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckLibratoAlertExists("librato_alert.foobar", &alert),
|
testAccCheckLibratoAlertExists("librato_alert.foobar", &alert),
|
||||||
testAccCheckLibratoAlertName(&alert, "FooBar"),
|
testAccCheckLibratoAlertName(&alert, name),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"librato_alert.foobar", "name", "FooBar"),
|
"librato_alert.foobar", "name", name),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -33,19 +35,20 @@ func TestAccLibratoAlert_Basic(t *testing.T) {
|
||||||
|
|
||||||
func TestAccLibratoAlert_Full(t *testing.T) {
|
func TestAccLibratoAlert_Full(t *testing.T) {
|
||||||
var alert librato.Alert
|
var alert librato.Alert
|
||||||
|
name := acctest.RandString(10)
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckLibratoAlertDestroy,
|
CheckDestroy: testAccCheckLibratoAlertDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccCheckLibratoAlertConfig_full,
|
Config: testAccCheckLibratoAlertConfig_full(name),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckLibratoAlertExists("librato_alert.foobar", &alert),
|
testAccCheckLibratoAlertExists("librato_alert.foobar", &alert),
|
||||||
testAccCheckLibratoAlertName(&alert, "FooBar"),
|
testAccCheckLibratoAlertName(&alert, name),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"librato_alert.foobar", "name", "FooBar"),
|
"librato_alert.foobar", "name", name),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"librato_alert.foobar", "condition.836525194.metric_name", "librato.cpu.percent.idle"),
|
"librato_alert.foobar", "condition.836525194.metric_name", "librato.cpu.percent.idle"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
|
@ -60,23 +63,24 @@ func TestAccLibratoAlert_Full(t *testing.T) {
|
||||||
|
|
||||||
func TestAccLibratoAlert_Updated(t *testing.T) {
|
func TestAccLibratoAlert_Updated(t *testing.T) {
|
||||||
var alert librato.Alert
|
var alert librato.Alert
|
||||||
|
name := acctest.RandString(10)
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckLibratoAlertDestroy,
|
CheckDestroy: testAccCheckLibratoAlertDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccCheckLibratoAlertConfig_basic,
|
Config: testAccCheckLibratoAlertConfig_basic(name),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckLibratoAlertExists("librato_alert.foobar", &alert),
|
testAccCheckLibratoAlertExists("librato_alert.foobar", &alert),
|
||||||
testAccCheckLibratoAlertDescription(&alert, "A Test Alert"),
|
testAccCheckLibratoAlertDescription(&alert, "A Test Alert"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"librato_alert.foobar", "name", "FooBar"),
|
"librato_alert.foobar", "name", name),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccCheckLibratoAlertConfig_new_value,
|
Config: testAccCheckLibratoAlertConfig_new_value(name),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckLibratoAlertExists("librato_alert.foobar", &alert),
|
testAccCheckLibratoAlertExists("librato_alert.foobar", &alert),
|
||||||
testAccCheckLibratoAlertDescription(&alert, "A modified Test Alert"),
|
testAccCheckLibratoAlertDescription(&alert, "A modified Test Alert"),
|
||||||
|
@ -90,19 +94,20 @@ func TestAccLibratoAlert_Updated(t *testing.T) {
|
||||||
|
|
||||||
func TestAccLibratoAlert_FullUpdate(t *testing.T) {
|
func TestAccLibratoAlert_FullUpdate(t *testing.T) {
|
||||||
var alert librato.Alert
|
var alert librato.Alert
|
||||||
|
name := acctest.RandString(10)
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckLibratoAlertDestroy,
|
CheckDestroy: testAccCheckLibratoAlertDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccCheckLibratoAlertConfig_full_update,
|
Config: testAccCheckLibratoAlertConfig_full_update(name),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckLibratoAlertExists("librato_alert.foobar", &alert),
|
testAccCheckLibratoAlertExists("librato_alert.foobar", &alert),
|
||||||
testAccCheckLibratoAlertName(&alert, "FooBar"),
|
testAccCheckLibratoAlertName(&alert, name),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"librato_alert.foobar", "name", "FooBar"),
|
"librato_alert.foobar", "name", name),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"librato_alert.foobar", "rearm_seconds", "1200"),
|
"librato_alert.foobar", "rearm_seconds", "1200"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
|
@ -197,19 +202,24 @@ func testAccCheckLibratoAlertExists(n string, alert *librato.Alert) resource.Tes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccCheckLibratoAlertConfig_basic = `
|
func testAccCheckLibratoAlertConfig_basic(name string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "librato_alert" "foobar" {
|
resource "librato_alert" "foobar" {
|
||||||
name = "FooBar"
|
name = "%s"
|
||||||
description = "A Test Alert"
|
description = "A Test Alert"
|
||||||
}`
|
}`, name)
|
||||||
|
}
|
||||||
|
|
||||||
const testAccCheckLibratoAlertConfig_new_value = `
|
func testAccCheckLibratoAlertConfig_new_value(name string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "librato_alert" "foobar" {
|
resource "librato_alert" "foobar" {
|
||||||
name = "FooBar"
|
name = "%s"
|
||||||
description = "A modified Test Alert"
|
description = "A modified Test Alert"
|
||||||
}`
|
}`, name)
|
||||||
|
}
|
||||||
|
|
||||||
const testAccCheckLibratoAlertConfig_full = `
|
func testAccCheckLibratoAlertConfig_full(name string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "librato_service" "foobar" {
|
resource "librato_service" "foobar" {
|
||||||
title = "Foo Bar"
|
title = "Foo Bar"
|
||||||
type = "mail"
|
type = "mail"
|
||||||
|
@ -221,7 +231,7 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "librato_alert" "foobar" {
|
resource "librato_alert" "foobar" {
|
||||||
name = "FooBar"
|
name = "%s"
|
||||||
description = "A Test Alert"
|
description = "A Test Alert"
|
||||||
services = [ "${librato_service.foobar.id}" ]
|
services = [ "${librato_service.foobar.id}" ]
|
||||||
condition {
|
condition {
|
||||||
|
@ -235,9 +245,11 @@ resource "librato_alert" "foobar" {
|
||||||
}
|
}
|
||||||
active = false
|
active = false
|
||||||
rearm_seconds = 300
|
rearm_seconds = 300
|
||||||
}`
|
}`, name)
|
||||||
|
}
|
||||||
|
|
||||||
const testAccCheckLibratoAlertConfig_full_update = `
|
func testAccCheckLibratoAlertConfig_full_update(name string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "librato_service" "foobar" {
|
resource "librato_service" "foobar" {
|
||||||
title = "Foo Bar"
|
title = "Foo Bar"
|
||||||
type = "mail"
|
type = "mail"
|
||||||
|
@ -249,7 +261,7 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "librato_alert" "foobar" {
|
resource "librato_alert" "foobar" {
|
||||||
name = "FooBar"
|
name = "%s"
|
||||||
description = "A Test Alert"
|
description = "A Test Alert"
|
||||||
services = [ "${librato_service.foobar.id}" ]
|
services = [ "${librato_service.foobar.id}" ]
|
||||||
condition {
|
condition {
|
||||||
|
@ -263,4 +275,5 @@ resource "librato_alert" "foobar" {
|
||||||
}
|
}
|
||||||
active = false
|
active = false
|
||||||
rearm_seconds = 1200
|
rearm_seconds = 1200
|
||||||
}`
|
}`, name)
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
"github.com/henrikhodne/go-librato/librato"
|
"github.com/henrikhodne/go-librato/librato"
|
||||||
|
@ -12,19 +13,20 @@ import (
|
||||||
|
|
||||||
func TestAccLibratoSpace_Basic(t *testing.T) {
|
func TestAccLibratoSpace_Basic(t *testing.T) {
|
||||||
var space librato.Space
|
var space librato.Space
|
||||||
|
name := acctest.RandString(10)
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckLibratoSpaceDestroy,
|
CheckDestroy: testAccCheckLibratoSpaceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccCheckLibratoSpaceConfig_basic,
|
Config: testAccCheckLibratoSpaceConfig_basic(name),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckLibratoSpaceExists("librato_space.foobar", &space),
|
testAccCheckLibratoSpaceExists("librato_space.foobar", &space),
|
||||||
testAccCheckLibratoSpaceAttributes(&space),
|
testAccCheckLibratoSpaceAttributes(&space, name),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"librato_space.foobar", "name", "Foo Bar"),
|
"librato_space.foobar", "name", name),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -54,10 +56,10 @@ func testAccCheckLibratoSpaceDestroy(s *terraform.State) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckLibratoSpaceAttributes(space *librato.Space) resource.TestCheckFunc {
|
func testAccCheckLibratoSpaceAttributes(space *librato.Space, name string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
|
|
||||||
if space.Name == nil || *space.Name != "Foo Bar" {
|
if space.Name == nil || *space.Name != name {
|
||||||
return fmt.Errorf("Bad name: %s", *space.Name)
|
return fmt.Errorf("Bad name: %s", *space.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +102,9 @@ func testAccCheckLibratoSpaceExists(n string, space *librato.Space) resource.Tes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccCheckLibratoSpaceConfig_basic = `
|
func testAccCheckLibratoSpaceConfig_basic(name string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "librato_space" "foobar" {
|
resource "librato_space" "foobar" {
|
||||||
name = "Foo Bar"
|
name = "%s"
|
||||||
}`
|
}`, name)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue