github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/newrelic/provider_test.go (about) 1 package newrelic 2 3 import ( 4 "fmt" 5 "os" 6 "testing" 7 "time" 8 9 "github.com/hashicorp/terraform/helper/acctest" 10 "github.com/hashicorp/terraform/helper/schema" 11 "github.com/hashicorp/terraform/terraform" 12 newrelic "github.com/newrelic/go-agent" 13 ) 14 15 var ( 16 testAccExpectedApplicationName string 17 testAccProviders map[string]terraform.ResourceProvider 18 testAccProvider *schema.Provider 19 ) 20 21 func init() { 22 testAccExpectedApplicationName = fmt.Sprintf("tf_test_%s", acctest.RandString(10)) 23 testAccProvider = Provider().(*schema.Provider) 24 testAccProviders = map[string]terraform.ResourceProvider{ 25 "newrelic": testAccProvider, 26 } 27 } 28 29 func TestProvider(t *testing.T) { 30 if err := Provider().(*schema.Provider).InternalValidate(); err != nil { 31 t.Fatalf("err: %s", err) 32 } 33 } 34 35 func TestProviderImpl(t *testing.T) { 36 var _ terraform.ResourceProvider = Provider() 37 } 38 39 func testAccPreCheck(t *testing.T) { 40 if v := os.Getenv("NEWRELIC_API_KEY"); v == "" { 41 t.Log(v) 42 t.Fatal("NEWRELIC_API_KEY must be set for acceptance tests") 43 } 44 45 // setup fake application by logging some metrics 46 if v := os.Getenv("NEWRELIC_LICENSE_KEY"); len(v) > 0 { 47 config := newrelic.NewConfig(testAccExpectedApplicationName, v) 48 app, err := newrelic.NewApplication(config) 49 if err != nil { 50 t.Log(err) 51 t.Fatal("Error setting up New Relic application") 52 } 53 54 if err := app.WaitForConnection(30 * time.Second); err != nil { 55 t.Log(err) 56 t.Fatal("Unable to setup New Relic application connection") 57 } 58 59 if err := app.RecordCustomEvent("terraform test", nil); err != nil { 60 t.Log(err) 61 t.Fatal("Unable to record custom event in New Relic") 62 } 63 64 app.Shutdown(30 * time.Second) 65 } else { 66 t.Log(v) 67 t.Fatal("NEWRELIC_LICENSE_KEY must be set for acceptance tests") 68 } 69 }