diff --git a/internal/filer_test.go b/internal/filer_test.go index 3361de5b..27530425 100644 --- a/internal/filer_test.go +++ b/internal/filer_test.go @@ -511,6 +511,7 @@ func TestAccFilerWorkspaceFilesExtensionsReadDir(t *testing.T) { content string }{ {"dir1/dir2/dir3/file.txt", "file content"}, + {"dir1/notebook.py", "# Databricks notebook source\nprint('first upload'))"}, {"foo.py", "print('foo')"}, {"foo.r", "print('foo')"}, {"foo.scala", "println('foo')"}, @@ -523,6 +524,16 @@ func TestAccFilerWorkspaceFilesExtensionsReadDir(t *testing.T) { {"sqlNb.sql", "-- Databricks notebook source\n SELECT \"first upload\""}, } + // Assert that every file has a unique basename + basenames := map[string]struct{}{} + for _, f := range files { + basename := path.Base(f.name) + if _, ok := basenames[basename]; ok { + t.Fatalf("basename %s is not unique", basename) + } + basenames[basename] = struct{}{} + } + ctx := context.Background() wf, _ := setupWsfsExtensionsFiler(t) @@ -534,7 +545,6 @@ func TestAccFilerWorkspaceFilesExtensionsReadDir(t *testing.T) { // Read entries entries, err := wf.ReadDir(ctx, ".") require.NoError(t, err) - assert.Len(t, entries, len(files)) names := []string{} for _, e := range entries { names = append(names, e.Name()) @@ -552,6 +562,18 @@ func TestAccFilerWorkspaceFilesExtensionsReadDir(t *testing.T) { "scalaNb.scala", "sqlNb.sql", }, names) + + // Read entries in subdirectory + entries, err = wf.ReadDir(ctx, "dir1") + require.NoError(t, err) + names = []string{} + for _, e := range entries { + names = append(names, e.Name()) + } + assert.Equal(t, []string{ + "dir2", + "notebook.py", + }, names) } func setupFilerWithExtensionsTest(t *testing.T) filer.Filer { diff --git a/libs/filer/workspace_files_extensions_client.go b/libs/filer/workspace_files_extensions_client.go index bad748b1..3ce6913a 100644 --- a/libs/filer/workspace_files_extensions_client.go +++ b/libs/filer/workspace_files_extensions_client.go @@ -235,7 +235,7 @@ func (w *workspaceFilesExtensionsClient) ReadDir(ctx context.Context, name strin // If the object is a notebook, include an extension in the entry. if sysInfo.ObjectType == workspace.ObjectTypeNotebook { - stat, err := w.getNotebookStatByNameWithoutExt(ctx, entries[i].Name()) + stat, err := w.getNotebookStatByNameWithoutExt(ctx, path.Join(name, entries[i].Name())) if err != nil { return nil, err }