github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/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, bCleanup := testBackendDefault(t) 24 defer bCleanup() 25 26 s1, err := b.StateMgr(backend.DefaultStateName) 27 if err != nil { 28 t.Fatalf("expected no error, got %v", err) 29 } 30 31 s2, err := b.StateMgr(backend.DefaultStateName) 32 if err != nil { 33 t.Fatalf("expected no error, got %v", err) 34 } 35 36 remote.TestRemoteLocks(t, s1.(*remote.State).Client, s2.(*remote.State).Client) 37 } 38 39 func TestRemoteClient_withRunID(t *testing.T) { 40 // Set the TFE_RUN_ID environment variable before creating the client! 41 if err := os.Setenv("TFE_RUN_ID", generateID("run-")); err != nil { 42 t.Fatalf("error setting env var TFE_RUN_ID: %v", err) 43 } 44 45 // Create a new test client. 46 client := testRemoteClient(t) 47 48 // Create a new empty state. 49 state := bytes.NewBuffer(nil) 50 if err := terraform.WriteState(terraform.NewState(), state); err != nil { 51 t.Fatalf("expected no error, got: %v", err) 52 } 53 54 // Store the new state to verify (this will be done 55 // by the mock that is used) that the run ID is set. 56 if err := client.Put(state.Bytes()); err != nil { 57 t.Fatalf("expected no error, got %v", err) 58 } 59 }