github.com/peterbale/terraform@v0.9.0-beta2.0.20170315142748-5723acd55547/builtin/providers/vault/provider_test.go (about)

     1  package vault
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/helper/schema"
     8  	"github.com/hashicorp/terraform/terraform"
     9  )
    10  
    11  // How to run the acceptance tests for this provider:
    12  //
    13  // - Obtain an official Vault release from the Vault website at
    14  //   https://vaultproject.io/ and extract the "vault" binary
    15  //   somewhere.
    16  //
    17  // - Run the following to start the Vault server in development mode:
    18  //       vault server -dev
    19  //
    20  // - Take the "Root Token" value printed by Vault as the server started
    21  //   up and set it as the value of the VAULT_TOKEN environment variable
    22  //   in a new shell whose current working directory is the root of the
    23  //   Terraform repository.
    24  //
    25  // - As directed by the Vault server output, set the VAULT_ADDR environment
    26  //   variable. e.g.:
    27  //       export VAULT_ADDR='http://127.0.0.1:8200'
    28  //
    29  // - Run the Terraform acceptance tests as usual:
    30  //       make testacc TEST=./builtin/providers/vault
    31  //
    32  // The tests expect to be run in a fresh, empty Vault and thus do not attempt
    33  // to randomize or otherwise make the generated resource paths unique on
    34  // each run. In case of weird behavior, restart the Vault dev server to
    35  // start over with a fresh Vault. (Remember to reset VAULT_TOKEN.)
    36  
    37  func TestProvider(t *testing.T) {
    38  	if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
    39  		t.Fatalf("err: %s", err)
    40  	}
    41  }
    42  
    43  var testProvider *schema.Provider
    44  var testProviders map[string]terraform.ResourceProvider
    45  
    46  func init() {
    47  	testProvider = Provider().(*schema.Provider)
    48  	testProviders = map[string]terraform.ResourceProvider{
    49  		"vault": testProvider,
    50  	}
    51  }
    52  
    53  func testAccPreCheck(t *testing.T) {
    54  	if v := os.Getenv("VAULT_ADDR"); v == "" {
    55  		t.Fatal("VAULT_ADDR must be set for acceptance tests")
    56  	}
    57  	if v := os.Getenv("VAULT_TOKEN"); v == "" {
    58  		t.Fatal("VAULT_TOKEN must be set for acceptance tests")
    59  	}
    60  }