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