Add first failing test for heroku_space

This commit is contained in:
Bernerd Schaefer 2017-04-24 17:08:13 -07:00
parent 6daef74e9b
commit 43257492b9
3 changed files with 129 additions and 2 deletions

View File

@ -25,11 +25,12 @@ func Provider() terraform.ResourceProvider {
},
ResourcesMap: map[string]*schema.Resource{
"heroku_app": resourceHerokuApp(),
"heroku_addon": resourceHerokuAddon(),
"heroku_app": resourceHerokuApp(),
"heroku_cert": resourceHerokuCert(),
"heroku_domain": resourceHerokuDomain(),
"heroku_drain": resourceHerokuDrain(),
"heroku_cert": resourceHerokuCert(),
"heroku_space": resourceHerokuSpace(),
},
ConfigureFunc: providerConfigure,

View File

@ -0,0 +1,31 @@
package heroku
import "github.com/hashicorp/terraform/helper/schema"
func resourceHerokuSpace() *schema.Resource {
return &schema.Resource{
Create: func(_ *schema.ResourceData, _ interface{}) error { return nil },
Read: func(_ *schema.ResourceData, _ interface{}) error { return nil },
Update: func(_ *schema.ResourceData, _ interface{}) error { return nil },
Delete: func(_ *schema.ResourceData, _ interface{}) error { return nil },
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"organization": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"region": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
},
}
}

View File

@ -0,0 +1,95 @@
package heroku
import (
"context"
"fmt"
"os"
"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 TestAccHerokuSpace_Basic(t *testing.T) {
var space heroku.SpaceInfoResult
spaceName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
org := os.Getenv("HEROKU_ORGANIZATION")
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
if org == "" {
t.Skip("HEROKU_ORGANIZATION is not set; skipping test.")
}
},
Providers: testAccProviders,
CheckDestroy: testAccCheckHerokuSpaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckHerokuSpaceConfig_basic(spaceName, org),
Check: resource.ComposeTestCheckFunc(
testAccCheckHerokuSpaceExists("heroku_space.foobar", &space),
),
},
},
})
}
func testAccCheckHerokuSpaceConfig_basic(spaceName, orgName string) string {
return fmt.Sprintf(`
resource "heroku_space" "foobar" {
name = "%s"
organization = "%s"
region = "virginia"
}
`, spaceName, orgName)
}
func testAccCheckHerokuSpaceExists(n string, space *heroku.SpaceInfoResult) resource.TestCheckFunc {
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 space name set")
}
client := testAccProvider.Meta().(*heroku.Service)
foundSpace, err := client.SpaceInfo(context.TODO(), rs.Primary.ID)
if err != nil {
return err
}
if foundSpace.Name != rs.Primary.ID {
return fmt.Errorf("Space not found")
}
*space = *foundSpace
return nil
}
}
func testAccCheckHerokuSpaceDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*heroku.Service)
for _, rs := range s.RootModule().Resources {
if rs.Type != "heroku_space" {
continue
}
_, err := client.SpaceInfo(context.TODO(), rs.Primary.ID)
if err == nil {
return fmt.Errorf("Space still exists")
}
}
return nil
}