github.com/nevins-b/terraform@v0.3.8-0.20170215184714-bbae22007d5a/backend/remote-state/consul/client_test.go (about)

     1  package consul
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/hashicorp/terraform/backend"
    10  	"github.com/hashicorp/terraform/backend/remote-state"
    11  	"github.com/hashicorp/terraform/state/remote"
    12  )
    13  
    14  func TestRemoteClient_impl(t *testing.T) {
    15  	var _ remote.Client = new(RemoteClient)
    16  }
    17  
    18  func TestRemoteClient(t *testing.T) {
    19  	addr := os.Getenv("CONSUL_HTTP_ADDR")
    20  	if addr == "" {
    21  		t.Log("consul tests require CONSUL_HTTP_ADDR")
    22  		t.Skip()
    23  	}
    24  
    25  	// Get the backend
    26  	b := backend.TestBackendConfig(t, New(), map[string]interface{}{
    27  		"address": addr,
    28  		"path":    fmt.Sprintf("tf-unit/%s", time.Now().String()),
    29  	})
    30  
    31  	// Test
    32  	remotestate.TestClient(t, b)
    33  }
    34  
    35  func TestConsul_stateLock(t *testing.T) {
    36  	addr := os.Getenv("CONSUL_HTTP_ADDR")
    37  	if addr == "" {
    38  		t.Log("consul lock tests require CONSUL_HTTP_ADDR")
    39  		t.Skip()
    40  	}
    41  
    42  	path := fmt.Sprintf("tf-unit/%s", time.Now().String())
    43  
    44  	// create 2 instances to get 2 remote.Clients
    45  	sA, err := backend.TestBackendConfig(t, New(), map[string]interface{}{
    46  		"address": addr,
    47  		"path":    path,
    48  	}).State()
    49  	if err != nil {
    50  		t.Fatal(err)
    51  	}
    52  
    53  	sB, err := backend.TestBackendConfig(t, New(), map[string]interface{}{
    54  		"address": addr,
    55  		"path":    path,
    56  	}).State()
    57  	if err != nil {
    58  		t.Fatal(err)
    59  	}
    60  
    61  	remote.TestRemoteLocks(t, sA.(*remote.State).Client, sB.(*remote.State).Client)
    62  }