terraform/builtin/providers/heroku/resource_heroku_drain_test.go

108 lines
2.4 KiB
Go
Raw Normal View History

2014-08-19 18:18:45 +02:00
package heroku
import (
"fmt"
"testing"
"github.com/cyberdelia/heroku-go/v3"
2014-08-19 18:18:45 +02:00
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccHerokuDrain_Basic(t *testing.T) {
var drain heroku.LogDrain
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckHerokuDrainDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckHerokuDrainConfig_basic,
Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuDrainExists("heroku_drain.foobar", &drain),
testAccCheckHerokuDrainAttributes(&drain),
resource.TestCheckResourceAttr(
"heroku_drain.foobar", "url", "syslog://terraform.example.com:1234"),
resource.TestCheckResourceAttr(
"heroku_drain.foobar", "app", "terraform-test-app"),
),
},
},
})
}
func testAccCheckHerokuDrainDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*heroku.Service)
2014-08-19 18:18:45 +02:00
for _, rs := range s.Resources {
if rs.Type != "heroku_drain" {
continue
}
_, err := client.LogDrainInfo(rs.Attributes["app"], rs.ID)
if err == nil {
return fmt.Errorf("Drain still exists")
}
}
return nil
}
func testAccCheckHerokuDrainAttributes(Drain *heroku.LogDrain) resource.TestCheckFunc {
return func(s *terraform.State) error {
if Drain.URL != "syslog://terraform.example.com:1234" {
return fmt.Errorf("Bad URL: %s", Drain.URL)
}
if Drain.Token == "" {
return fmt.Errorf("No token: %#v", Drain)
}
return nil
}
}
func testAccCheckHerokuDrainExists(n string, Drain *heroku.LogDrain) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
return fmt.Errorf("No Drain ID is set")
}
client := testAccProvider.Meta().(*heroku.Service)
2014-08-19 18:18:45 +02:00
foundDrain, err := client.LogDrainInfo(rs.Attributes["app"], rs.ID)
if err != nil {
return err
}
if foundDrain.ID != rs.ID {
2014-08-19 18:18:45 +02:00
return fmt.Errorf("Drain not found")
}
*Drain = *foundDrain
return nil
}
}
const testAccCheckHerokuDrainConfig_basic = `
resource "heroku_app" "foobar" {
name = "terraform-test-app"
region = "us"
2014-08-19 18:18:45 +02:00
}
resource "heroku_drain" "foobar" {
app = "${heroku_app.foobar.name}"
url = "syslog://terraform.example.com:1234"
}`