mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
test: use T.TempDir to create temporary test directory (#30803)
This commit replaces `ioutil.TempDir` with `t.TempDir` in tests. The
directory created by `t.TempDir` is automatically removed when the test
and all its subtests complete.
Prior to this commit, temporary directory created using `ioutil.TempDir`
needs to be removed manually by calling `os.RemoveAll`, which is omitted
in some tests. The error handling boilerplate e.g.
defer func() {
if err := os.RemoveAll(dir); err != nil {
t.Fatal(err)
}
}
is also tedious, but `t.TempDir` handles this for us nicely.
Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
@@ -75,7 +75,7 @@ func TestUntaint_lockedState(t *testing.T) {
|
||||
)
|
||||
})
|
||||
statePath := testStateFile(t, state)
|
||||
unlock, err := testLockState(testDataDir, statePath)
|
||||
unlock, err := testLockState(t, testDataDir, statePath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -106,8 +106,7 @@ func TestUntaint_lockedState(t *testing.T) {
|
||||
|
||||
func TestUntaint_backup(t *testing.T) {
|
||||
// Get a temp cwd
|
||||
tmp, cwd := testCwd(t)
|
||||
defer testFixCwd(t, tmp, cwd)
|
||||
testCwd(t)
|
||||
|
||||
// Write the temp state
|
||||
state := states.BuildState(func(s *states.SyncState) {
|
||||
@@ -162,8 +161,7 @@ test_instance.foo:
|
||||
|
||||
func TestUntaint_backupDisable(t *testing.T) {
|
||||
// Get a temp cwd
|
||||
tmp, cwd := testCwd(t)
|
||||
defer testFixCwd(t, tmp, cwd)
|
||||
testCwd(t)
|
||||
|
||||
// Write the temp state
|
||||
state := states.BuildState(func(s *states.SyncState) {
|
||||
@@ -234,8 +232,7 @@ func TestUntaint_badState(t *testing.T) {
|
||||
|
||||
func TestUntaint_defaultState(t *testing.T) {
|
||||
// Get a temp cwd
|
||||
tmp, cwd := testCwd(t)
|
||||
defer testFixCwd(t, tmp, cwd)
|
||||
testCwd(t)
|
||||
|
||||
// Write the temp state
|
||||
state := states.BuildState(func(s *states.SyncState) {
|
||||
@@ -282,8 +279,7 @@ test_instance.foo:
|
||||
|
||||
func TestUntaint_defaultWorkspaceState(t *testing.T) {
|
||||
// Get a temp cwd
|
||||
tmp, cwd := testCwd(t)
|
||||
defer testFixCwd(t, tmp, cwd)
|
||||
testCwd(t)
|
||||
|
||||
// Write the temp state
|
||||
state := states.BuildState(func(s *states.SyncState) {
|
||||
@@ -420,8 +416,7 @@ because -allow-missing was set.
|
||||
|
||||
func TestUntaint_stateOut(t *testing.T) {
|
||||
// Get a temp cwd
|
||||
tmp, cwd := testCwd(t)
|
||||
defer testFixCwd(t, tmp, cwd)
|
||||
testCwd(t)
|
||||
|
||||
// Write the temp state
|
||||
state := states.BuildState(func(s *states.SyncState) {
|
||||
|
||||
Reference in New Issue
Block a user