github.com/profects/terraform@v0.9.0-beta1.0.20170227135739-92d4809db30d/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  	var _ remote.ClientLocker = new(RemoteClient)
    17  }
    18  
    19  func TestRemoteClient(t *testing.T) {
    20  	addr := os.Getenv("CONSUL_HTTP_ADDR")
    21  	if addr == "" {
    22  		t.Log("consul tests require CONSUL_HTTP_ADDR")
    23  		t.Skip()
    24  	}
    25  
    26  	// Get the backend
    27  	b := backend.TestBackendConfig(t, New(), map[string]interface{}{
    28  		"address": addr,
    29  		"path":    fmt.Sprintf("tf-unit/%s", time.Now().String()),
    30  	})
    31  
    32  	// Test
    33  	remotestate.TestClient(t, b)
    34  }
    35  
    36  func TestConsul_stateLock(t *testing.T) {
    37  	addr := os.Getenv("CONSUL_HTTP_ADDR")
    38  	if addr == "" {
    39  		t.Log("consul lock tests require CONSUL_HTTP_ADDR")
    40  		t.Skip()
    41  	}
    42  
    43  	path := fmt.Sprintf("tf-unit/%s", time.Now().String())
    44  
    45  	// create 2 instances to get 2 remote.Clients
    46  	sA, err := backend.TestBackendConfig(t, New(), map[string]interface{}{
    47  		"address": addr,
    48  		"path":    path,
    49  	}).State()
    50  	if err != nil {
    51  		t.Fatal(err)
    52  	}
    53  
    54  	sB, err := backend.TestBackendConfig(t, New(), map[string]interface{}{
    55  		"address": addr,
    56  		"path":    path,
    57  	}).State()
    58  	if err != nil {
    59  		t.Fatal(err)
    60  	}
    61  
    62  	remote.TestRemoteLocks(t, sA.(*remote.State).Client, sB.(*remote.State).Client)
    63  }