From eae60a797ae339f221fa601283e74c9656b189f5 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Tue, 11 Mar 2025 10:13:31 +0100 Subject: [PATCH] Make fake_workspace create all parent folders exist when importing a file (#2465) ## Changes When a file is imported, FakeWorkspace now automatically identifies and records all parent directories in the directories map, ensuring the directory structure is properly maintained without requiring explicit directory creation. ## Why During an acceptance test, production code might want to check a root folder for existence, this change makes sure that root folder is marked as existing when at least one file is imported into the workspace ## Tests Tests for another change using this improvement are green: https://github.com/databricks/cli/pull/2463 --- libs/testserver/fake_workspace.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libs/testserver/fake_workspace.go b/libs/testserver/fake_workspace.go index 80e88941d..c483cbc6e 100644 --- a/libs/testserver/fake_workspace.go +++ b/libs/testserver/fake_workspace.go @@ -81,6 +81,19 @@ func (s *FakeWorkspace) WorkspaceFilesImportFile(path string, body []byte) { path = "/" + path } s.files[path] = body + + // Add all directories in the path to the directories map + parts := strings.Split(path, "/") + currentPath := "" + for i, part := range parts { + // Skip empty parts and the last part (which is the file itself) + if part == "" || i == len(parts)-1 { + continue + } + + currentPath = currentPath + "/" + part + s.directories[currentPath] = true + } } func (s *FakeWorkspace) WorkspaceFilesExportFile(path string) []byte {