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