mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-27 09:21:14 -06:00
cleanup temp files from backend tests
This commit is contained in:
parent
e9e4ee4940
commit
28c46d1a90
@ -18,7 +18,8 @@ import (
|
||||
)
|
||||
|
||||
func TestLocal_applyBasic(t *testing.T) {
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
p := TestLocalProvider(t, b, "test")
|
||||
|
||||
p.ApplyReturn = &terraform.InstanceState{ID: "yes"}
|
||||
@ -58,7 +59,9 @@ test_instance.foo:
|
||||
}
|
||||
|
||||
func TestLocal_applyEmptyDir(t *testing.T) {
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
|
||||
p := TestLocalProvider(t, b, "test")
|
||||
|
||||
p.ApplyReturn = &terraform.InstanceState{ID: "yes"}
|
||||
@ -85,7 +88,8 @@ func TestLocal_applyEmptyDir(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLocal_applyEmptyDirDestroy(t *testing.T) {
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
p := TestLocalProvider(t, b, "test")
|
||||
|
||||
p.ApplyReturn = nil
|
||||
@ -111,7 +115,8 @@ func TestLocal_applyEmptyDirDestroy(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLocal_applyError(t *testing.T) {
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
p := TestLocalProvider(t, b, "test")
|
||||
|
||||
var lock sync.Mutex
|
||||
@ -169,7 +174,9 @@ func TestLocal_applyBackendFail(t *testing.T) {
|
||||
mod, modCleanup := module.TestTree(t, "./test-fixtures/apply")
|
||||
defer modCleanup()
|
||||
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get current working directory")
|
||||
|
@ -15,7 +15,8 @@ import (
|
||||
)
|
||||
|
||||
func TestLocal_planBasic(t *testing.T) {
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
p := TestLocalProvider(t, b, "test")
|
||||
|
||||
mod, modCleanup := module.TestTree(t, "./test-fixtures/plan")
|
||||
@ -40,7 +41,8 @@ func TestLocal_planBasic(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLocal_planInAutomation(t *testing.T) {
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
TestLocalProvider(t, b, "test")
|
||||
|
||||
mod, modCleanup := module.TestTree(t, "./test-fixtures/plan")
|
||||
@ -103,7 +105,8 @@ func TestLocal_planInAutomation(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLocal_planNoConfig(t *testing.T) {
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
TestLocalProvider(t, b, "test")
|
||||
|
||||
op := testOperationPlan()
|
||||
@ -126,7 +129,8 @@ func TestLocal_planNoConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLocal_planRefreshFalse(t *testing.T) {
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
p := TestLocalProvider(t, b, "test")
|
||||
terraform.TestStateFile(t, b.StatePath, testPlanState())
|
||||
|
||||
@ -155,7 +159,8 @@ func TestLocal_planRefreshFalse(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLocal_planDestroy(t *testing.T) {
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
p := TestLocalProvider(t, b, "test")
|
||||
terraform.TestStateFile(t, b.StatePath, testPlanState())
|
||||
|
||||
@ -200,7 +205,8 @@ func TestLocal_planDestroy(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLocal_planOutPathNoChange(t *testing.T) {
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
TestLocalProvider(t, b, "test")
|
||||
terraform.TestStateFile(t, b.StatePath, testPlanState())
|
||||
|
||||
@ -237,7 +243,8 @@ func TestLocal_planOutPathNoChange(t *testing.T) {
|
||||
// checks to make sure the correct resource count is ultimately given to the
|
||||
// UI.
|
||||
func TestLocal_planScaleOutNoDupeCount(t *testing.T) {
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
TestLocalProvider(t, b, "test")
|
||||
state := &terraform.State{
|
||||
Version: 2,
|
||||
|
@ -11,7 +11,9 @@ import (
|
||||
)
|
||||
|
||||
func TestLocal_refresh(t *testing.T) {
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
|
||||
p := TestLocalProvider(t, b, "test")
|
||||
terraform.TestStateFile(t, b.StatePath, testRefreshState())
|
||||
|
||||
@ -42,7 +44,8 @@ test_instance.foo:
|
||||
}
|
||||
|
||||
func TestLocal_refreshNilModule(t *testing.T) {
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
p := TestLocalProvider(t, b, "test")
|
||||
terraform.TestStateFile(t, b.StatePath, testRefreshState())
|
||||
|
||||
@ -71,7 +74,8 @@ test_instance.foo:
|
||||
|
||||
// GH-12174
|
||||
func TestLocal_refreshNilModuleWithInput(t *testing.T) {
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
p := TestLocalProvider(t, b, "test")
|
||||
terraform.TestStateFile(t, b.StatePath, testRefreshState())
|
||||
|
||||
@ -101,7 +105,8 @@ test_instance.foo:
|
||||
}
|
||||
|
||||
func TestLocal_refreshInput(t *testing.T) {
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
p := TestLocalProvider(t, b, "test")
|
||||
terraform.TestStateFile(t, b.StatePath, testRefreshState())
|
||||
|
||||
@ -145,7 +150,8 @@ test_instance.foo:
|
||||
}
|
||||
|
||||
func TestLocal_refreshValidate(t *testing.T) {
|
||||
b := TestLocal(t)
|
||||
b, cleanup := TestLocal(t)
|
||||
defer cleanup()
|
||||
p := TestLocalProvider(t, b, "test")
|
||||
terraform.TestStateFile(t, b.StatePath, testRefreshState())
|
||||
|
||||
|
@ -2,6 +2,7 @@ package local
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@ -15,15 +16,22 @@ import (
|
||||
//
|
||||
// No operations will be called on the returned value, so you can still set
|
||||
// public fields without any locks.
|
||||
func TestLocal(t *testing.T) *Local {
|
||||
func TestLocal(t *testing.T) (*Local, func()) {
|
||||
tempDir := testTempDir(t)
|
||||
return &Local{
|
||||
local := &Local{
|
||||
StatePath: filepath.Join(tempDir, "state.tfstate"),
|
||||
StateOutPath: filepath.Join(tempDir, "state.tfstate"),
|
||||
StateBackupPath: filepath.Join(tempDir, "state.tfstate.bak"),
|
||||
StateWorkspaceDir: filepath.Join(tempDir, "state.tfstate.d"),
|
||||
ContextOpts: &terraform.ContextOpts{},
|
||||
}
|
||||
cleanup := func() {
|
||||
if err := os.RemoveAll(tempDir); err != nil {
|
||||
t.Fatal("error clecanup up test:", err)
|
||||
}
|
||||
}
|
||||
|
||||
return local, cleanup
|
||||
}
|
||||
|
||||
// TestLocalProvider modifies the ContextOpts of the *Local parameter to
|
||||
|
Loading…
Reference in New Issue
Block a user