github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/icinga2/resource_icinga2_checkcommand_test.go (about) 1 package icinga2 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 "github.com/hashicorp/terraform/terraform" 9 "github.com/lrsmith/go-icinga2-api/iapi" 10 ) 11 12 func TestAccCreateCheckcommand(t *testing.T) { 13 14 var testAccCreateCheckcommand = fmt.Sprintf(` 15 resource "icinga2_checkcommand" "checkcommand" { 16 name = "terraform-test-checkcommand-1" 17 templates = [ "plugin-check-command" ] 18 command = "/usr/local/bin/check_command" 19 arguments = { 20 "-I" = "$IARG$" 21 "-J" = "$JARG$" } 22 }`) 23 24 resource.Test(t, resource.TestCase{ 25 PreCheck: func() { testAccPreCheck(t) }, 26 Providers: testAccProviders, 27 Steps: []resource.TestStep{ 28 resource.TestStep{ 29 Config: testAccCreateCheckcommand, 30 Check: resource.ComposeTestCheckFunc( 31 testAccCheckCheckcommandExists("icinga2_checkcommand.checkcommand"), 32 testAccCheckResourceState("icinga2_checkcommand.checkcommand", "name", "terraform-test-checkcommand-1"), 33 testAccCheckResourceState("icinga2_checkcommand.checkcommand", "command", "/usr/local/bin/check_command"), 34 testAccCheckResourceState("icinga2_checkcommand.checkcommand", "arguments.%", "2"), 35 testAccCheckResourceState("icinga2_checkcommand.checkcommand", "arguments.-I", "$IARG$"), 36 testAccCheckResourceState("icinga2_checkcommand.checkcommand", "arguments.-J", "$JARG$"), 37 ), 38 }, 39 }, 40 }) 41 } 42 43 func testAccCheckCheckcommandExists(rn string) resource.TestCheckFunc { 44 return func(s *terraform.State) error { 45 resource, ok := s.RootModule().Resources[rn] 46 if !ok { 47 return fmt.Errorf("Checkcommand resource not found: %s", rn) 48 } 49 50 if resource.Primary.ID == "" { 51 return fmt.Errorf("Checkcommand resource id not set") 52 } 53 54 client := testAccProvider.Meta().(*iapi.Server) 55 _, err := client.GetCheckcommand(resource.Primary.ID) 56 if err != nil { 57 return fmt.Errorf("Error getting getting Checkcommand: %s", err) 58 } 59 60 return nil 61 } 62 }