mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-18 12:42:58 -06:00
ea8ad0b15a
The cloud package intends to implement a new integration for Terraform Cloud/Enterprise. The purpose of this integration is to better support TFC users; it will shed some overly generic UX and architecture, behavior changes that are otherwise backwards incompatible in the remote backend, and technical debt - all of which are vestiges from before Terraform Cloud existed. This initial commit is largely a porting of the existing 'remote' backend, which will serve as an underlying implementation detail and not be a typical user-level backend. This is because to re-implement the literal backend interface is orthogonal to the purpose of this integration, and can always be migrated away from later. As this backend is considered an implementation detail, it will not be registered as a declarable backend. Within these changes it is, for easy of initial development and a clean diff.
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package cloud
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/internal/backend"
|
|
"github.com/hashicorp/terraform/internal/states"
|
|
"github.com/hashicorp/terraform/internal/states/remote"
|
|
"github.com/hashicorp/terraform/internal/states/statefile"
|
|
)
|
|
|
|
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) {
|
|
b, bCleanup := testBackendDefault(t)
|
|
defer bCleanup()
|
|
|
|
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.
|
|
sf := statefile.New(states.NewState(), "", 0)
|
|
var buf bytes.Buffer
|
|
statefile.Write(sf, &buf)
|
|
|
|
// Store the new state to verify (this will be done
|
|
// by the mock that is used) that the run ID is set.
|
|
if err := client.Put(buf.Bytes()); err != nil {
|
|
t.Fatalf("expected no error, got %v", err)
|
|
}
|
|
}
|