Use []byte for files in workspace (#162)

This commit is contained in:
Pieter Noordhuis 2023-01-05 12:03:31 +01:00 committed by GitHub
parent a9b82aa1c7
commit a59136f77f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 9 deletions

View File

@ -81,7 +81,7 @@ func TestAccFilerWorkspaceFiles(t *testing.T) {
}
// Write should fail because the root path doesn't yet exist.
err = f.Write(ctx, "/foo/bar", strings.NewReader(`"hello world"`))
err = f.Write(ctx, "/foo/bar", strings.NewReader(`hello world`))
assert.True(t, errors.As(err, &filer.NoSuchDirectoryError{}))
// Read should fail because the root path doesn't yet exist.
@ -89,18 +89,18 @@ func TestAccFilerWorkspaceFiles(t *testing.T) {
assert.True(t, apierr.IsMissing(err))
// Write with CreateParentDirectories flag should succeed.
err = f.Write(ctx, "/foo/bar", strings.NewReader(`"hello world"`), filer.CreateParentDirectories)
err = f.Write(ctx, "/foo/bar", strings.NewReader(`hello world`), filer.CreateParentDirectories)
assert.NoError(t, err)
filerTest{t, f}.assertContents(ctx, "/foo/bar", `"hello world"`)
filerTest{t, f}.assertContents(ctx, "/foo/bar", `hello world`)
// Write should fail because there is an existing file at the specified path.
err = f.Write(ctx, "/foo/bar", strings.NewReader(`"hello universe"`))
err = f.Write(ctx, "/foo/bar", strings.NewReader(`hello universe`))
assert.True(t, errors.As(err, &filer.FileAlreadyExistsError{}))
// Write with OverwriteIfExists should succeed.
err = f.Write(ctx, "/foo/bar", strings.NewReader(`"hello universe"`), filer.OverwriteIfExists)
err = f.Write(ctx, "/foo/bar", strings.NewReader(`hello universe`), filer.OverwriteIfExists)
assert.NoError(t, err)
filerTest{t, f}.assertContents(ctx, "/foo/bar", `"hello universe"`)
filerTest{t, f}.assertContents(ctx, "/foo/bar", `hello universe`)
// Delete should fail if the file doesn't exist.
err = f.Delete(ctx, "/doesnt_exist")

View File

@ -3,7 +3,6 @@ package filer
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
@ -107,8 +106,7 @@ func (w *WorkspaceFilesClient) Read(ctx context.Context, name string) (io.Reader
strings.TrimLeft(absPath, "/"),
)
// Update to []byte after https://github.com/databricks/databricks-sdk-go/pull/247 is merged.
var res json.RawMessage
var res []byte
err = w.apiClient.Do(ctx, http.MethodGet, urlPath, nil, &res)
if err != nil {
return nil, err