github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/opc/provider_test.go (about) 1 package opc 2 3 import ( 4 "fmt" 5 "os" 6 "testing" 7 8 "github.com/hashicorp/go-oracle-terraform/compute" 9 "github.com/hashicorp/terraform/helper/resource" 10 "github.com/hashicorp/terraform/helper/schema" 11 "github.com/hashicorp/terraform/terraform" 12 ) 13 14 var testAccProviders map[string]terraform.ResourceProvider 15 var testAccProvider *schema.Provider 16 17 func init() { 18 testAccProvider = Provider().(*schema.Provider) 19 testAccProviders = map[string]terraform.ResourceProvider{ 20 "opc": testAccProvider, 21 } 22 } 23 24 func TestProvider(t *testing.T) { 25 if err := Provider().(*schema.Provider).InternalValidate(); err != nil { 26 t.Fatalf("Error creating Provider: %s", err) 27 } 28 } 29 30 func TestProvider_impl(t *testing.T) { 31 var _ terraform.ResourceProvider = Provider() 32 } 33 34 func testAccPreCheck(t *testing.T) { 35 required := []string{"OPC_USERNAME", "OPC_PASSWORD", "OPC_IDENTITY_DOMAIN", "OPC_ENDPOINT"} 36 for _, prop := range required { 37 if os.Getenv(prop) == "" { 38 t.Fatalf("%s must be set for acceptance test", prop) 39 } 40 } 41 } 42 43 type OPCResourceState struct { 44 *compute.Client 45 *terraform.InstanceState 46 } 47 48 func opcResourceCheck(resourceName string, f func(checker *OPCResourceState) error) resource.TestCheckFunc { 49 return func(s *terraform.State) error { 50 rs, ok := s.RootModule().Resources[resourceName] 51 if !ok { 52 return fmt.Errorf("Resource not found: %s", resourceName) 53 } 54 55 state := &OPCResourceState{ 56 Client: testAccProvider.Meta().(*compute.Client), 57 InstanceState: rs.Primary, 58 } 59 60 return f(state) 61 } 62 }