Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fjakobs committed Sep 4, 2024
1 parent 46e1fdb commit 13996bd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
7 changes: 2 additions & 5 deletions libs/template/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"path/filepath"
"strings"

"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/env"
"github.com/databricks/cli/libs/filer"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/workspace"
)

Expand Down Expand Up @@ -119,10 +119,7 @@ func writeFile(ctx context.Context, path string, content []byte) error {
}

func importNotebook(ctx context.Context, path string, content []byte) error {
w, err := databricks.NewWorkspaceClient()
if err != nil {
return err
}
w := root.WorkspaceClient(ctx)

return w.Workspace.Import(ctx, workspace.Import{
Format: "AUTO",
Expand Down
7 changes: 4 additions & 3 deletions libs/template/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func testInMemoryFile(t *testing.T, perm fs.FileMode) {
perm: perm,
content: []byte("123"),
}
err := f.PersistToDisk()
err := f.PersistToDisk(context.Background())
assert.NoError(t, err)

assertFileContent(t, filepath.Join(tmpDir, "a/b/c"), "123")
Expand All @@ -38,9 +38,10 @@ func testCopyFile(t *testing.T, perm fs.FileMode) {
require.NoError(t, err)
err = os.WriteFile(filepath.Join(tmpDir, "source"), []byte("qwerty"), perm)
require.NoError(t, err)
ctx := context.Background()

f := &copyFile{
ctx: context.Background(),
ctx: ctx,
dstPath: &destinationPath{
root: tmpDir,
relPath: "a/b/c",
Expand All @@ -49,7 +50,7 @@ func testCopyFile(t *testing.T, perm fs.FileMode) {
srcPath: "source",
srcFiler: templateFiler,
}
err = f.PersistToDisk()
err = f.PersistToDisk(ctx)
assert.NoError(t, err)

assertFileContent(t, filepath.Join(tmpDir, "a/b/c"), "qwerty")
Expand Down
3 changes: 1 addition & 2 deletions libs/template/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ func (r *renderer) persistToDisk() error {
_, err := os.Stat(path)
if err == nil {
return fmt.Errorf("failed to initialize template, one or more files already exist: %s", path)
}
if err != nil && !errors.Is(err, fs.ErrNotExist) {
} else if !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("error while verifying file %s does not already exist: %w", path, err)
}
}
Expand Down

0 comments on commit 13996bd

Please sign in to comment.