Compare commits

...

3 Commits

Author SHA1 Message Date
Shreyas Goenka e9b0afb337
- 2025-01-03 00:03:16 +05:30
Shreyas Goenka ee9499bc68
use write testutil 2025-01-03 00:01:55 +05:30
Shreyas Goenka f4623ebbb9
cleanup 2025-01-02 23:56:58 +05:30
3 changed files with 8 additions and 16 deletions

View File

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

View File

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

View File

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