2017-04-28 18:25:56 +02:00
|
|
|
package heroku
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
heroku "github.com/cyberdelia/heroku-go/v3"
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccHerokuPipeline_Basic(t *testing.T) {
|
2017-05-24 13:04:17 +02:00
|
|
|
var pipeline heroku.Pipeline
|
2017-04-28 18:25:56 +02:00
|
|
|
pipelineName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
|
2017-04-28 21:46:06 +02:00
|
|
|
pipelineName2 := fmt.Sprintf("%s-2", pipelineName)
|
2017-04-28 18:25:56 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckHerokuPipelineDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccCheckHerokuPipelineConfig_basic(pipelineName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckHerokuPipelineExists("heroku_pipeline.foobar", &pipeline),
|
2017-04-28 21:46:06 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"heroku_pipeline.foobar", "name", pipelineName),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: testAccCheckHerokuPipelineConfig_basic(pipelineName2),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"heroku_pipeline.foobar", "name", pipelineName2),
|
2017-04-28 18:25:56 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckHerokuPipelineConfig_basic(pipelineName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "heroku_pipeline" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
}
|
|
|
|
`, pipelineName)
|
|
|
|
}
|
|
|
|
|
2017-05-24 13:04:17 +02:00
|
|
|
func testAccCheckHerokuPipelineExists(n string, pipeline *heroku.Pipeline) resource.TestCheckFunc {
|
2017-04-28 18:25:56 +02:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No pipeline name set")
|
|
|
|
}
|
|
|
|
|
|
|
|
client := testAccProvider.Meta().(*heroku.Service)
|
|
|
|
|
|
|
|
foundPipeline, err := client.PipelineInfo(context.TODO(), rs.Primary.ID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if foundPipeline.ID != rs.Primary.ID {
|
|
|
|
return fmt.Errorf("Pipeline not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
*pipeline = *foundPipeline
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckHerokuPipelineDestroy(s *terraform.State) error {
|
|
|
|
client := testAccProvider.Meta().(*heroku.Service)
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "heroku_pipeline" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := client.PipelineInfo(context.TODO(), rs.Primary.ID)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
return fmt.Errorf("Pipeline still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|