2018-10-31 16:45:03 +01:00
|
|
|
package remote
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-05-17 17:42:17 +02:00
|
|
|
"github.com/hashicorp/terraform/internal/backend"
|
2020-09-30 22:07:54 +02:00
|
|
|
"github.com/hashicorp/terraform/states"
|
2020-08-11 17:43:01 +02:00
|
|
|
"github.com/hashicorp/terraform/states/remote"
|
2020-09-30 22:07:54 +02:00
|
|
|
"github.com/hashicorp/terraform/states/statefile"
|
2018-10-31 16:45:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRemoteClient_impl(t *testing.T) {
|
|
|
|
var _ remote.Client = new(remoteClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoteClient(t *testing.T) {
|
|
|
|
client := testRemoteClient(t)
|
|
|
|
remote.TestClient(t, client)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoteClient_stateLock(t *testing.T) {
|
2019-02-06 09:36:42 +01:00
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
defer bCleanup()
|
2018-10-31 16:45:03 +01:00
|
|
|
|
|
|
|
s1, err := b.StateMgr(backend.DefaultStateName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("expected no error, got %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s2, err := b.StateMgr(backend.DefaultStateName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("expected no error, got %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
remote.TestRemoteLocks(t, s1.(*remote.State).Client, s2.(*remote.State).Client)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoteClient_withRunID(t *testing.T) {
|
|
|
|
// Set the TFE_RUN_ID environment variable before creating the client!
|
|
|
|
if err := os.Setenv("TFE_RUN_ID", generateID("run-")); err != nil {
|
|
|
|
t.Fatalf("error setting env var TFE_RUN_ID: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new test client.
|
|
|
|
client := testRemoteClient(t)
|
|
|
|
|
|
|
|
// Create a new empty state.
|
2020-09-30 22:07:54 +02:00
|
|
|
sf := statefile.New(states.NewState(), "", 0)
|
|
|
|
var buf bytes.Buffer
|
|
|
|
statefile.Write(sf, &buf)
|
2018-10-31 16:45:03 +01:00
|
|
|
|
|
|
|
// Store the new state to verify (this will be done
|
|
|
|
// by the mock that is used) that the run ID is set.
|
2020-09-30 22:07:54 +02:00
|
|
|
if err := client.Put(buf.Bytes()); err != nil {
|
2018-10-31 16:45:03 +01:00
|
|
|
t.Fatalf("expected no error, got %v", err)
|
|
|
|
}
|
|
|
|
}
|