mirror of https://github.com/databricks/cli.git
add support for delete'
This commit is contained in:
parent
350cb8e4db
commit
58349b209c
|
@ -752,12 +752,31 @@ func TestAccWorkspaceFilesExtensionsNotebooksAreNotStatAsFiles(t *testing.T) {
|
|||
err := wf.Write(ctx, "foo.ipynb", strings.NewReader(readFile(t, "testdata/notebooks/py1.ipynb")))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Reading foo should fail. Even though the WSFS name for the notebook is foo
|
||||
// reading the notebook should only work with the .ipynb extension.
|
||||
// Stating foo should fail. Even though the WSFS name for the notebook is foo
|
||||
// stating the notebook should only work with the .ipynb extension.
|
||||
_, err = wf.Stat(ctx, "foo")
|
||||
assert.ErrorIs(t, err, fs.ErrNotExist)
|
||||
|
||||
_, err = wf.Read(ctx, "foo.ipynb")
|
||||
_, err = wf.Stat(ctx, "foo.ipynb")
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestAccWorkspaceFilesExtensionsNotebooksAreNotDeletedAsFiles(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := context.Background()
|
||||
wf, _ := setupWsfsExtensionsFiler(t)
|
||||
|
||||
// Create a notebook
|
||||
err := wf.Write(ctx, "foo.ipynb", strings.NewReader(readFile(t, "testdata/notebooks/py1.ipynb")))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Deleting foo should fail. Even though the WSFS name for the notebook is foo
|
||||
// deleting the notebook should only work with the .ipynb extension.
|
||||
err = wf.Delete(ctx, "foo")
|
||||
assert.ErrorIs(t, err, fs.ErrNotExist)
|
||||
|
||||
err = wf.Delete(ctx, "foo.ipynb")
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
|
@ -287,7 +287,18 @@ func (w *workspaceFilesExtensionsClient) Delete(ctx context.Context, name string
|
|||
return ReadOnlyError{"delete"}
|
||||
}
|
||||
|
||||
err := w.wsfs.Delete(ctx, name, mode...)
|
||||
// Ensure that the file / notebook exists. We do this check here to avoid
|
||||
// deleting the a notebook called `foo` when the user actually wanted to
|
||||
// delete a file called `foo`.
|
||||
//
|
||||
// To delete a notebook called `foo` in the workspace the user should use the
|
||||
// name with the extension included like `foo.ipynb` or `foo.sql`.
|
||||
_, err := w.Stat(ctx, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = w.wsfs.Delete(ctx, name, mode...)
|
||||
|
||||
// If the file is not found, it might be a notebook.
|
||||
if errors.As(err, &FileDoesNotExistError{}) {
|
||||
|
|
Loading…
Reference in New Issue