Skip to content

Commit a7aa4b3

Browse files
committed
Fix test creating terraform.tfstate in source directory
The test TestParseResourcesStateWithExistingStateFile was creating a terraform.tfstate file in the test source directory instead of in the temporary directory. This was introduced in PR #3797 when the code was changed from using b.StateLocalPath(ctx) to b.StateFilenameTerraform(ctx). The bug was that StateFilenameTerraform returns two values (remote filename, local path), but the test only captured the first value (filename) instead of the second value (full local path). This fix: - Captures the second return value (full local path) instead of the first - Creates the parent directory structure with os.MkdirAll - Writes the file to the correct location in the temp directory - Uses proper file permissions consistent with the codebase (0o700/0o600)
1 parent fb3b270 commit a7aa4b3

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)