diff --git a/libs/template/file.go b/libs/template/file.go index fb1303ba5f..f635a2de6b 100644 --- a/libs/template/file.go +++ b/libs/template/file.go @@ -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" ) @@ -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", diff --git a/libs/template/file_test.go b/libs/template/file_test.go index 85938895ef..5e3ab395d6 100644 --- a/libs/template/file_test.go +++ b/libs/template/file_test.go @@ -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") @@ -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 := ©File{ - ctx: context.Background(), + ctx: ctx, dstPath: &destinationPath{ root: tmpDir, relPath: "a/b/c", @@ -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") diff --git a/libs/template/renderer.go b/libs/template/renderer.go index 4abf99eb1d..72ef8ee5a9 100644 --- a/libs/template/renderer.go +++ b/libs/template/renderer.go @@ -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) } }