mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-20 10:19:27 -05:00
This adds a new context.Context argument to the Backend.StateMgr method, updates all of the implementations to match, and then updates all of the callers to pass in a context. A small number of callers don't yet have context plumbed to them so those use context.TODO() as a placeholder for now, so we can more easily find and fix them in later commits once we have contexts more thoroughly plumbed. Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
// Copyright (c) The OpenTofu Authors
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package remote
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/opentofu/opentofu/internal/backend"
|
|
"github.com/opentofu/opentofu/internal/cloud"
|
|
"github.com/opentofu/opentofu/internal/encryption"
|
|
"github.com/opentofu/opentofu/internal/states"
|
|
"github.com/opentofu/opentofu/internal/states/remote"
|
|
"github.com/opentofu/opentofu/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(t.Context(), backend.DefaultStateName)
|
|
if err != nil {
|
|
t.Fatalf("expected no error, got %v", err)
|
|
}
|
|
|
|
s2, err := b.StateMgr(t.Context(), 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_Put_withRunID(t *testing.T) {
|
|
// Set the TFE_RUN_ID environment variable before creating the client!
|
|
t.Setenv("TFE_RUN_ID", cloud.GenerateID("run-"))
|
|
|
|
// 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, encryption.StateEncryptionDisabled())
|
|
|
|
// 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)
|
|
}
|
|
}
|