Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libs/filer/workspace_files_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ func (w *WorkspaceFilesClient) Stat(ctx context.Context, name string) (fs.FileIn
if aerr.StatusCode == http.StatusNotFound {
return nil, fileDoesNotExistError{absPath}
}

return nil, err
}

return stat, nil
Expand Down
50 changes: 50 additions & 0 deletions libs/filer/workspace_files_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"testing"
"time"

"github.com/databricks/cli/libs/testserver"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/apierr"
"github.com/databricks/databricks-sdk-go/config"
"github.com/databricks/databricks-sdk-go/service/workspace"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -131,3 +133,51 @@ func TestWorkspaceFilesClient_wsfsUnmarshal(t *testing.T) {
assert.False(t, info.IsDir())
assert.NotNil(t, info.Sys())
}

func statWithError(t *testing.T, statusCode int, errorCode string) error {
t.Helper()

server := testserver.New(t)
server.Handle("GET", "/api/2.0/workspace/get-status", func(req testserver.Request) any {
return testserver.Response{
StatusCode: statusCode,
Body: map[string]string{
"error_code": errorCode,
"message": "test error",
},
}
})
testserver.AddDefaultHandlers(server)

client, err := databricks.NewWorkspaceClient(&databricks.Config{
Host: server.URL,
Token: "testtoken",
})
require.NoError(t, err)

f, err := NewWorkspaceFilesClient(client, "/test")
require.NoError(t, err)

_, err = f.Stat(t.Context(), "file")
require.Error(t, err)
return err
}

func TestWorkspaceFilesClientStatForbidden(t *testing.T) {
err := statWithError(t, 403, "PERMISSION_DENIED")
var apiErr *apierr.APIError
require.ErrorAs(t, err, &apiErr)
assert.Equal(t, 403, apiErr.StatusCode)
}

func TestWorkspaceFilesClientStatInternalError(t *testing.T) {
err := statWithError(t, 500, "INTERNAL_ERROR")
var apiErr *apierr.APIError
require.ErrorAs(t, err, &apiErr)
assert.Equal(t, 500, apiErr.StatusCode)
}

func TestWorkspaceFilesClientStatNotFound(t *testing.T) {
err := statWithError(t, 404, "RESOURCE_DOES_NOT_EXIST")
assert.ErrorIs(t, err, fs.ErrNotExist)
}
Loading