Compare commits

..

No commits in common. "e9b0afb337ec152a79235449a4baec9322b6c96c" and "ac37ca0d9825297bf28644caab4206a32563cf84" have entirely different histories.

3 changed files with 16 additions and 8 deletions

View File

@ -909,7 +909,8 @@ func TestDbfsFilerForStreamingUploads(t *testing.T) {
// Write a file to local disk. // Write a file to local disk.
tmpDir := t.TempDir() tmpDir := t.TempDir()
testutil.WriteFile(t, filepath.Join(tmpDir, "foo.txt"), "foobar") err := os.WriteFile(filepath.Join(tmpDir, "foo.txt"), []byte("foobar"), 0o644)
require.NoError(t, err)
fd, err := os.Open(filepath.Join(tmpDir, "foo.txt")) fd, err := os.Open(filepath.Join(tmpDir, "foo.txt"))
require.NoError(t, err) require.NoError(t, err)
@ -940,8 +941,11 @@ func TestDbfsFilerForPutUploads(t *testing.T) {
// Write a file to local disk. // Write a file to local disk.
tmpDir := t.TempDir() tmpDir := t.TempDir()
testutil.WriteFile(t, filepath.Join(tmpDir, "foo.txt"), "foobar") err := os.WriteFile(filepath.Join(tmpDir, "foo.txt"), []byte("foobar"), 0o644)
testutil.WriteFile(t, filepath.Join(tmpDir, "bar.txt"), "barfoo") require.NoError(t, err)
err = os.WriteFile(filepath.Join(tmpDir, "bar.txt"), []byte("barfoo"), 0o644)
require.NoError(t, err)
fdFoo, err := os.Open(filepath.Join(tmpDir, "foo.txt")) fdFoo, err := os.Open(filepath.Join(tmpDir, "foo.txt"))
require.NoError(t, err) require.NoError(t, err)
defer fdFoo.Close() defer fdFoo.Close()

View File

@ -69,9 +69,11 @@ func (info dbfsFileInfo) Sys() any {
} }
// Interface to allow mocking of the Databricks API client. // Interface to allow mocking of the Databricks API client.
//
//nolint:gofumpt
type databricksClient interface { type databricksClient interface {
Do(ctx context.Context, method, path string, headers map[string]string, Do(ctx context.Context, method, path string, headers map[string]string,
requestBody, responseBody any, visitors ...func(*http.Request) error) error requestBody any, responseBody any, visitors ...func(*http.Request) error) error
} }
// DbfsClient implements the [Filer] interface for the DBFS backend. // DbfsClient implements the [Filer] interface for the DBFS backend.
@ -100,7 +102,7 @@ func NewDbfsClient(w *databricks.WorkspaceClient, root string) (Filer, error) {
// The PUT API for DBFS requires setting the content length header beforehand in the HTTP // The PUT API for DBFS requires setting the content length header beforehand in the HTTP
// request. // request.
func contentLength(path, overwriteField string, file *os.File) (int64, error) { func putContentLength(path, overwriteField string, file *os.File) (int64, error) {
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
writer := multipart.NewWriter(buf) writer := multipart.NewWriter(buf)
err := writer.WriteField("path", path) err := writer.WriteField("path", path)
@ -130,7 +132,7 @@ func contentLength(path, overwriteField string, file *os.File) (int64, error) {
func contentLengthVisitor(path, overwriteField string, file *os.File) func(*http.Request) error { func contentLengthVisitor(path, overwriteField string, file *os.File) func(*http.Request) error {
return func(r *http.Request) error { return func(r *http.Request) error {
cl, err := contentLength(path, overwriteField, file) cl, err := putContentLength(path, overwriteField, file)
if err != nil { if err != nil {
return fmt.Errorf("failed to calculate content length: %w", err) return fmt.Errorf("failed to calculate content length: %w", err)
} }

View File

@ -41,7 +41,8 @@ func TestDbfsClientForSmallFiles(t *testing.T) {
// write file to local disk // write file to local disk
tmp := t.TempDir() tmp := t.TempDir()
localPath := filepath.Join(tmp, "hello.txt") localPath := filepath.Join(tmp, "hello.txt")
testutil.WriteFile(t, localPath, "hello world") err := os.WriteFile(localPath, []byte("hello world"), 0o644)
require.NoError(t, err)
// setup DBFS client with mocks // setup DBFS client with mocks
m := mocks.NewMockWorkspaceClient(t) m := mocks.NewMockWorkspaceClient(t)
@ -91,7 +92,8 @@ func TestDbfsClientForLargerFiles(t *testing.T) {
// write file to local disk // write file to local disk
tmp := t.TempDir() tmp := t.TempDir()
localPath := filepath.Join(tmp, "hello.txt") localPath := filepath.Join(tmp, "hello.txt")
testutil.WriteFile(t, localPath, "hello world") err := os.WriteFile(localPath, []byte("hello world"), 0o644)
require.NoError(t, err)
// Modify the max file size to 1 byte to simulate // Modify the max file size to 1 byte to simulate
// a large file that needs to be uploaded in chunks. // a large file that needs to be uploaded in chunks.