Skip to content

Commit 13996bd

Browse files
committed
fix tests
1 parent 46e1fdb commit 13996bd

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

libs/template/file.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"path/filepath"
1010
"strings"
1111

12+
"github.com/databricks/cli/cmd/root"
1213
"github.com/databricks/cli/libs/env"
1314
"github.com/databricks/cli/libs/filer"
14-
"github.com/databricks/databricks-sdk-go"
1515
"github.com/databricks/databricks-sdk-go/service/workspace"
1616
)
1717

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

121121
func importNotebook(ctx context.Context, path string, content []byte) error {
122-
w, err := databricks.NewWorkspaceClient()
123-
if err != nil {
124-
return err
125-
}
122+
w := root.WorkspaceClient(ctx)
126123

127124
return w.Workspace.Import(ctx, workspace.Import{
128125
Format: "AUTO",

libs/template/file_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func testInMemoryFile(t *testing.T, perm fs.FileMode) {
2424
perm: perm,
2525
content: []byte("123"),
2626
}
27-
err := f.PersistToDisk()
27+
err := f.PersistToDisk(context.Background())
2828
assert.NoError(t, err)
2929

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

4243
f := &copyFile{
43-
ctx: context.Background(),
44+
ctx: ctx,
4445
dstPath: &destinationPath{
4546
root: tmpDir,
4647
relPath: "a/b/c",
@@ -49,7 +50,7 @@ func testCopyFile(t *testing.T, perm fs.FileMode) {
4950
srcPath: "source",
5051
srcFiler: templateFiler,
5152
}
52-
err = f.PersistToDisk()
53+
err = f.PersistToDisk(ctx)
5354
assert.NoError(t, err)
5455

5556
assertFileContent(t, filepath.Join(tmpDir, "a/b/c"), "qwerty")

libs/template/renderer.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ func (r *renderer) persistToDisk() error {
313313
_, err := os.Stat(path)
314314
if err == nil {
315315
return fmt.Errorf("failed to initialize template, one or more files already exist: %s", path)
316-
}
317-
if err != nil && !errors.Is(err, fs.ErrNotExist) {
316+
} else if !errors.Is(err, fs.ErrNotExist) {
318317
return fmt.Errorf("error while verifying file %s does not already exist: %w", path, err)
319318
}
320319
}

0 commit comments

Comments
 (0)