Skip to content

Commit

Permalink
Fix listing notebooks in a subdirectory (#1468)
Browse files Browse the repository at this point in the history
## Changes

This worked fine if the notebooks are located in the filer's root and
didn't if they are nested in a directory.

This change adds test coverage and fixes the underlying issue.

## Tests

Ran integration test manually.
  • Loading branch information
pietern authored Jun 4, 2024
1 parent aa36aee commit 448d410
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion internal/filer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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')"},
Expand All @@ -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)

Expand All @@ -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())
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion libs/filer/workspace_files_extensions_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 448d410

Please sign in to comment.