mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
ffe056bacb
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package local
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/internal/backend"
|
|
"github.com/hashicorp/terraform/internal/command/arguments"
|
|
"github.com/hashicorp/terraform/internal/command/clistate"
|
|
"github.com/hashicorp/terraform/internal/command/views"
|
|
"github.com/hashicorp/terraform/internal/initwd"
|
|
"github.com/hashicorp/terraform/internal/terminal"
|
|
)
|
|
|
|
func TestLocalContext(t *testing.T) {
|
|
configDir := "./testdata/empty"
|
|
b, cleanup := TestLocal(t)
|
|
defer cleanup()
|
|
|
|
_, configLoader, configCleanup := initwd.MustLoadConfigForTests(t, configDir)
|
|
defer configCleanup()
|
|
|
|
streams, _ := terminal.StreamsForTesting(t)
|
|
view := views.NewView(streams)
|
|
stateLocker := clistate.NewLocker(0, views.NewStateLocker(arguments.ViewHuman, view))
|
|
|
|
op := &backend.Operation{
|
|
ConfigDir: configDir,
|
|
ConfigLoader: configLoader,
|
|
Workspace: backend.DefaultStateName,
|
|
StateLocker: stateLocker,
|
|
}
|
|
|
|
_, _, diags := b.Context(op)
|
|
if diags.HasErrors() {
|
|
t.Fatalf("unexpected error: %s", diags.Err().Error())
|
|
}
|
|
|
|
// Context() retains a lock on success
|
|
assertBackendStateLocked(t, b)
|
|
}
|
|
|
|
func TestLocalContext_error(t *testing.T) {
|
|
configDir := "./testdata/apply"
|
|
b, cleanup := TestLocal(t)
|
|
defer cleanup()
|
|
|
|
_, configLoader, configCleanup := initwd.MustLoadConfigForTests(t, configDir)
|
|
defer configCleanup()
|
|
|
|
streams, _ := terminal.StreamsForTesting(t)
|
|
view := views.NewView(streams)
|
|
stateLocker := clistate.NewLocker(0, views.NewStateLocker(arguments.ViewHuman, view))
|
|
|
|
op := &backend.Operation{
|
|
ConfigDir: configDir,
|
|
ConfigLoader: configLoader,
|
|
Workspace: backend.DefaultStateName,
|
|
StateLocker: stateLocker,
|
|
}
|
|
|
|
_, _, diags := b.Context(op)
|
|
if !diags.HasErrors() {
|
|
t.Fatal("unexpected success")
|
|
}
|
|
|
|
// Context() unlocks the state on failure
|
|
assertBackendStateUnlocked(t, b)
|
|
}
|