mirror of https://github.com/databricks/cli.git
Compare commits
3 Commits
ac37ca0d98
...
e9b0afb337
Author | SHA1 | Date |
---|---|---|
|
e9b0afb337 | |
|
ee9499bc68 | |
|
f4623ebbb9 |
|
@ -909,8 +909,7 @@ func TestDbfsFilerForStreamingUploads(t *testing.T) {
|
||||||
|
|
||||||
// Write a file to local disk.
|
// Write a file to local disk.
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
err := os.WriteFile(filepath.Join(tmpDir, "foo.txt"), []byte("foobar"), 0o644)
|
testutil.WriteFile(t, filepath.Join(tmpDir, "foo.txt"), "foobar")
|
||||||
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)
|
||||||
|
@ -941,11 +940,8 @@ func TestDbfsFilerForPutUploads(t *testing.T) {
|
||||||
|
|
||||||
// Write a file to local disk.
|
// Write a file to local disk.
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
err := os.WriteFile(filepath.Join(tmpDir, "foo.txt"), []byte("foobar"), 0o644)
|
testutil.WriteFile(t, filepath.Join(tmpDir, "foo.txt"), "foobar")
|
||||||
require.NoError(t, err)
|
testutil.WriteFile(t, filepath.Join(tmpDir, "bar.txt"), "barfoo")
|
||||||
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()
|
||||||
|
|
|
@ -69,11 +69,9 @@ 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 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.
|
// 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
|
// The PUT API for DBFS requires setting the content length header beforehand in the HTTP
|
||||||
// request.
|
// request.
|
||||||
func putContentLength(path, overwriteField string, file *os.File) (int64, error) {
|
func contentLength(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)
|
||||||
|
@ -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 {
|
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 := putContentLength(path, overwriteField, file)
|
cl, err := contentLength(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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,7 @@ 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")
|
||||||
err := os.WriteFile(localPath, []byte("hello world"), 0o644)
|
testutil.WriteFile(t, localPath, "hello world")
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// setup DBFS client with mocks
|
// setup DBFS client with mocks
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
@ -92,8 +91,7 @@ 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")
|
||||||
err := os.WriteFile(localPath, []byte("hello world"), 0o644)
|
testutil.WriteFile(t, localPath, "hello world")
|
||||||
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.
|
||||||
|
|
Loading…
Reference in New Issue