github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/newrelic/data_source_newrelic_application_test.go (about) 1 package newrelic 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 "github.com/hashicorp/terraform/terraform" 9 ) 10 11 func TestAccNewRelicApplication_Basic(t *testing.T) { 12 resource.Test(t, resource.TestCase{ 13 PreCheck: func() { testAccPreCheck(t) }, 14 Providers: testAccProviders, 15 Steps: []resource.TestStep{ 16 resource.TestStep{ 17 Config: testAccNewRelicApplicationConfig(), 18 Check: resource.ComposeTestCheckFunc( 19 testAccNewRelicApplication("data.newrelic_application.app"), 20 ), 21 }, 22 }, 23 }) 24 } 25 26 func testAccNewRelicApplication(n string) resource.TestCheckFunc { 27 return func(s *terraform.State) error { 28 r := s.RootModule().Resources[n] 29 a := r.Primary.Attributes 30 31 if a["id"] == "" { 32 return fmt.Errorf("Expected to get an application from New Relic") 33 } 34 35 if a["name"] != testAccExpectedApplicationName { 36 return fmt.Errorf("Expected the application name to be: %s, but got: %s", testAccExpectedApplicationName, a["name"]) 37 } 38 39 return nil 40 } 41 } 42 43 // The test application for this data source is created in provider_test.go 44 func testAccNewRelicApplicationConfig() string { 45 return fmt.Sprintf(` 46 data "newrelic_application" "app" { 47 name = "%s" 48 } 49 `, testAccExpectedApplicationName) 50 }