github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/spotinst/provider_test.go (about)

     1  package spotinst
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/helper/schema"
     8  	"github.com/hashicorp/terraform/terraform"
     9  )
    10  
    11  var testAccProviders map[string]terraform.ResourceProvider
    12  var testAccProvider *schema.Provider
    13  
    14  func init() {
    15  	testAccProvider = Provider().(*schema.Provider)
    16  	testAccProviders = map[string]terraform.ResourceProvider{
    17  		"spotinst": testAccProvider,
    18  	}
    19  }
    20  
    21  func TestProvider(t *testing.T) {
    22  	if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
    23  		t.Fatalf("err: %s", err)
    24  	}
    25  }
    26  
    27  func TestProvider_impl(t *testing.T) {
    28  	var _ terraform.ResourceProvider = Provider()
    29  }
    30  
    31  func testAccPreCheck(t *testing.T) {
    32  	c := map[string]string{
    33  		"email":         os.Getenv("SPOTINST_EMAIL"),
    34  		"password":      os.Getenv("SPOTINST_PASSWORD"),
    35  		"client_id":     os.Getenv("SPOTINST_CLIENT_ID"),
    36  		"client_secret": os.Getenv("SPOTINST_CLIENT_SECRET"),
    37  		"token":         os.Getenv("SPOTINST_TOKEN"),
    38  	}
    39  	if c["password"] != "" && c["token"] != "" {
    40  		t.Fatalf("ERR_CONFLICT: Both a password and a token were set, only one is required")
    41  	}
    42  	if c["password"] != "" && (c["email"] == "" || c["client_id"] == "" || c["client_secret"] == "") {
    43  		t.Fatalf("ERR_MISSING: A password was set without email, client_id or client_secret")
    44  	}
    45  	if c["password"] == "" && c["token"] == "" {
    46  		t.Fatalf("ERR_MISSING: A token is required if not using password")
    47  	}
    48  }