github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/alicloud/provider_test.go (about)

     1  package alicloud
     2  
     3  import (
     4  	"log"
     5  	"os"
     6  	"testing"
     7  
     8  	"fmt"
     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  		"alicloud": testAccProvider,
    21  	}
    22  }
    23  
    24  func TestProvider(t *testing.T) {
    25  	if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
    26  		t.Fatalf("err: %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  	if v := os.Getenv("ALICLOUD_ACCESS_KEY"); v == "" {
    36  		t.Fatal("ALICLOUD_ACCESS_KEY must be set for acceptance tests")
    37  	}
    38  	if v := os.Getenv("ALICLOUD_SECRET_KEY"); v == "" {
    39  		t.Fatal("ALICLOUD_SECRET_KEY must be set for acceptance tests")
    40  	}
    41  	if v := os.Getenv("ALICLOUD_REGION"); v == "" {
    42  		log.Println("[INFO] Test: Using cn-beijing as test region")
    43  		os.Setenv("ALICLOUD_REGION", "cn-beijing")
    44  	}
    45  }
    46  
    47  func testAccCheckAlicloudDataSourceID(n string) resource.TestCheckFunc {
    48  	return func(s *terraform.State) error {
    49  		rs, ok := s.RootModule().Resources[n]
    50  		if !ok {
    51  			return fmt.Errorf("Can't find data source: %s", n)
    52  		}
    53  
    54  		if rs.Primary.ID == "" {
    55  			return fmt.Errorf("data source ID not set")
    56  		}
    57  		return nil
    58  	}
    59  }