Skip to content

Commit ad5bab5

Browse files
authored
Fix test creating terraform.tfstate in source directory (#3855)
## Changes PR #3797 replaced a function that returns a state file path with one that returns both a filename and a path. The test used only the filename, causing the state file to be created in the wrong directory. In the current state, it creates the file in `$PWD`, equal to the directory where the test file is located. The path in `localPath` is located inside the bundle cache directory, which is initialized to somewhere inside `t.TempDir()` above.
1 parent d28763f commit ad5bab5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

bundle/deploy/terraform/util_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package terraform
33
import (
44
"context"
55
"os"
6+
"path/filepath"
67
"testing"
78

89
"github.com/databricks/cli/bundle"
@@ -86,10 +87,12 @@ func TestParseResourcesStateWithExistingStateFile(t *testing.T) {
8687
}
8788
]
8889
}`)
89-
name, _ := b.StateFilenameTerraform(ctx)
90-
err := os.WriteFile(name, data, os.ModePerm)
90+
_, localPath := b.StateFilenameTerraform(ctx)
91+
err := os.MkdirAll(filepath.Dir(localPath), 0o700)
9192
assert.NoError(t, err)
92-
state, err := parseResourcesState(ctx, name)
93+
err = os.WriteFile(localPath, data, 0o600)
94+
assert.NoError(t, err)
95+
state, err := parseResourcesState(ctx, localPath)
9396
assert.NoError(t, err)
9497
expected := ExportedResourcesMap{
9598
"pipelines": map[string]ResourceState{

0 commit comments

Comments
 (0)