github.com/ezbercih/terraform@v0.1.1-0.20140729011846-3c33865e0839/builtin/providers/heroku/resource_heroku_addon_test.go (about) 1 package heroku 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/bgentry/heroku-go" 8 "github.com/hashicorp/terraform/helper/resource" 9 "github.com/hashicorp/terraform/terraform" 10 ) 11 12 func TestAccHerokuAddon_Basic(t *testing.T) { 13 var addon heroku.Addon 14 15 resource.Test(t, resource.TestCase{ 16 PreCheck: func() { testAccPreCheck(t) }, 17 Providers: testAccProviders, 18 CheckDestroy: testAccCheckHerokuAddonDestroy, 19 Steps: []resource.TestStep{ 20 resource.TestStep{ 21 Config: testAccCheckHerokuAddonConfig_basic, 22 Check: resource.ComposeTestCheckFunc( 23 testAccCheckHerokuAddonExists("heroku_addon.foobar", &addon), 24 testAccCheckHerokuAddonAttributes(&addon), 25 resource.TestCheckResourceAttr( 26 "heroku_addon.foobar", "config.0.url", "http://google.com"), 27 resource.TestCheckResourceAttr( 28 "heroku_addon.foobar", "app", "terraform-test-app"), 29 resource.TestCheckResourceAttr( 30 "heroku_addon.foobar", "plan", "deployhooks:http"), 31 ), 32 }, 33 }, 34 }) 35 } 36 37 func testAccCheckHerokuAddonDestroy(s *terraform.State) error { 38 client := testAccProvider.client 39 40 for _, rs := range s.Resources { 41 if rs.Type != "heroku_addon" { 42 continue 43 } 44 45 _, err := client.AddonInfo(rs.Attributes["app"], rs.ID) 46 47 if err == nil { 48 return fmt.Errorf("Addon still exists") 49 } 50 } 51 52 return nil 53 } 54 55 func testAccCheckHerokuAddonAttributes(addon *heroku.Addon) resource.TestCheckFunc { 56 return func(s *terraform.State) error { 57 58 if addon.Plan.Name != "deployhooks:http" { 59 return fmt.Errorf("Bad plan: %s", addon.Plan) 60 } 61 62 return nil 63 } 64 } 65 66 func testAccCheckHerokuAddonExists(n string, addon *heroku.Addon) resource.TestCheckFunc { 67 return func(s *terraform.State) error { 68 rs, ok := s.Resources[n] 69 70 if !ok { 71 return fmt.Errorf("Not found: %s", n) 72 } 73 74 if rs.ID == "" { 75 return fmt.Errorf("No Addon ID is set") 76 } 77 78 client := testAccProvider.client 79 80 foundAddon, err := client.AddonInfo(rs.Attributes["app"], rs.ID) 81 82 if err != nil { 83 return err 84 } 85 86 if foundAddon.Id != rs.ID { 87 return fmt.Errorf("Addon not found") 88 } 89 90 *addon = *foundAddon 91 92 return nil 93 } 94 } 95 96 const testAccCheckHerokuAddonConfig_basic = ` 97 resource "heroku_app" "foobar" { 98 name = "terraform-test-app" 99 } 100 101 resource "heroku_addon" "foobar" { 102 app = "${heroku_app.foobar.name}" 103 plan = "deployhooks:http" 104 config { 105 url = "http://google.com" 106 } 107 }`