github.com/hugorut/terraform@v1.1.3/src/backend/remote/backend_state_test.go (about)

     1  package remote
     2  
     3  import (
     4  	"bytes"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/hugorut/terraform/src/backend"
     9  	"github.com/hugorut/terraform/src/cloud"
    10  	"github.com/hugorut/terraform/src/states"
    11  	"github.com/hugorut/terraform/src/states/remote"
    12  	"github.com/hugorut/terraform/src/states/statefile"
    13  )
    14  
    15  func TestRemoteClient_impl(t *testing.T) {
    16  	var _ remote.Client = new(remoteClient)
    17  }
    18  
    19  func TestRemoteClient(t *testing.T) {
    20  	client := testRemoteClient(t)
    21  	remote.TestClient(t, client)
    22  }
    23  
    24  func TestRemoteClient_stateLock(t *testing.T) {
    25  	b, bCleanup := testBackendDefault(t)
    26  	defer bCleanup()
    27  
    28  	s1, err := b.StateMgr(backend.DefaultStateName)
    29  	if err != nil {
    30  		t.Fatalf("expected no error, got %v", err)
    31  	}
    32  
    33  	s2, err := b.StateMgr(backend.DefaultStateName)
    34  	if err != nil {
    35  		t.Fatalf("expected no error, got %v", err)
    36  	}
    37  
    38  	remote.TestRemoteLocks(t, s1.(*remote.State).Client, s2.(*remote.State).Client)
    39  }
    40  
    41  func TestRemoteClient_withRunID(t *testing.T) {
    42  	// Set the TFE_RUN_ID environment variable before creating the client!
    43  	if err := os.Setenv("TFE_RUN_ID", cloud.GenerateID("run-")); err != nil {
    44  		t.Fatalf("error setting env var TFE_RUN_ID: %v", err)
    45  	}
    46  
    47  	// Create a new test client.
    48  	client := testRemoteClient(t)
    49  
    50  	// Create a new empty state.
    51  	sf := statefile.New(states.NewState(), "", 0)
    52  	var buf bytes.Buffer
    53  	statefile.Write(sf, &buf)
    54  
    55  	// Store the new state to verify (this will be done
    56  	// by the mock that is used) that the run ID is set.
    57  	if err := client.Put(buf.Bytes()); err != nil {
    58  		t.Fatalf("expected no error, got %v", err)
    59  	}
    60  }