mirror of https://github.com/databricks/cli.git
Fix listing notebooks in a subdirectory (#1468)
## 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.
This commit is contained in:
parent
aa36aee159
commit
448d41027d
|
@ -511,6 +511,7 @@ func TestAccFilerWorkspaceFilesExtensionsReadDir(t *testing.T) {
|
||||||
content string
|
content string
|
||||||
}{
|
}{
|
||||||
{"dir1/dir2/dir3/file.txt", "file content"},
|
{"dir1/dir2/dir3/file.txt", "file content"},
|
||||||
|
{"dir1/notebook.py", "# Databricks notebook source\nprint('first upload'))"},
|
||||||
{"foo.py", "print('foo')"},
|
{"foo.py", "print('foo')"},
|
||||||
{"foo.r", "print('foo')"},
|
{"foo.r", "print('foo')"},
|
||||||
{"foo.scala", "println('foo')"},
|
{"foo.scala", "println('foo')"},
|
||||||
|
@ -523,6 +524,16 @@ func TestAccFilerWorkspaceFilesExtensionsReadDir(t *testing.T) {
|
||||||
{"sqlNb.sql", "-- Databricks notebook source\n SELECT \"first upload\""},
|
{"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()
|
ctx := context.Background()
|
||||||
wf, _ := setupWsfsExtensionsFiler(t)
|
wf, _ := setupWsfsExtensionsFiler(t)
|
||||||
|
|
||||||
|
@ -534,7 +545,6 @@ func TestAccFilerWorkspaceFilesExtensionsReadDir(t *testing.T) {
|
||||||
// Read entries
|
// Read entries
|
||||||
entries, err := wf.ReadDir(ctx, ".")
|
entries, err := wf.ReadDir(ctx, ".")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Len(t, entries, len(files))
|
|
||||||
names := []string{}
|
names := []string{}
|
||||||
for _, e := range entries {
|
for _, e := range entries {
|
||||||
names = append(names, e.Name())
|
names = append(names, e.Name())
|
||||||
|
@ -552,6 +562,18 @@ func TestAccFilerWorkspaceFilesExtensionsReadDir(t *testing.T) {
|
||||||
"scalaNb.scala",
|
"scalaNb.scala",
|
||||||
"sqlNb.sql",
|
"sqlNb.sql",
|
||||||
}, names)
|
}, 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 {
|
func setupFilerWithExtensionsTest(t *testing.T) filer.Filer {
|
||||||
|
|
|
@ -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 the object is a notebook, include an extension in the entry.
|
||||||
if sysInfo.ObjectType == workspace.ObjectTypeNotebook {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue