-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathsync_test.go
More file actions
99 lines (86 loc) · 2.93 KB
/
Copy pathsync_test.go
File metadata and controls
99 lines (86 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package sync
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/libs/cmdctx"
"github.com/databricks/cli/libs/vfs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSyncOptionsFromBundle(t *testing.T) {
tempDir := t.TempDir()
b := &bundle.Bundle{
BundleRootPath: tempDir,
BundleRoot: vfs.MustNew(tempDir),
SyncRootPath: tempDir,
SyncRoot: vfs.MustNew(tempDir),
Config: config.Root{
Bundle: config.Bundle{
Target: "default",
},
Workspace: config.Workspace{
FilePath: "/Users/jane@doe.com/path",
},
},
}
f := syncFlags{concurrency: 5}
opts, err := f.syncOptionsFromBundle(New(), []string{}, b)
require.NoError(t, err)
assert.Equal(t, tempDir, opts.LocalRoot.Native())
assert.Equal(t, "/Users/jane@doe.com/path", opts.RemotePath)
assert.Equal(t, filepath.Join(tempDir, ".databricks", "bundle", "default"), opts.SnapshotBasePath)
assert.Equal(t, 5, opts.Concurrency)
assert.NotNil(t, opts.WorkspaceClient)
}
func TestSyncOptionsFromArgsRequiredTwoArgs(t *testing.T) {
var err error
f := syncFlags{}
_, err = f.syncOptionsFromArgs(New(), []string{})
require.ErrorContains(t, err, "accepts 2 arg(s), received 0")
_, err = f.syncOptionsFromArgs(New(), []string{"foo"})
require.ErrorContains(t, err, "accepts 2 arg(s), received 1")
_, err = f.syncOptionsFromArgs(New(), []string{"foo", "bar", "qux"})
require.ErrorContains(t, err, "accepts 2 arg(s), received 3")
}
func TestSyncOptionsFromArgs(t *testing.T) {
local := t.TempDir()
remote := "/remote"
f := syncFlags{concurrency: 7}
cmd := New()
cmd.SetContext(cmdctx.SetWorkspaceClient(t.Context(), nil))
opts, err := f.syncOptionsFromArgs(cmd, []string{local, remote})
require.NoError(t, err)
assert.Equal(t, local, opts.LocalRoot.Native())
assert.Equal(t, remote, opts.RemotePath)
assert.Equal(t, 7, opts.Concurrency)
}
func TestExcludeFromFlag(t *testing.T) {
// Create a temporary directory
tempDir := t.TempDir()
local := filepath.Join(tempDir, "local")
require.NoError(t, os.MkdirAll(local, 0o755))
remote := "/remote"
// Create a temporary exclude-from file
excludeFromPath := filepath.Join(tempDir, "exclude-patterns.txt")
excludePatterns := []string{
"*.log",
"build/",
"temp/*.tmp",
}
require.NoError(t, os.WriteFile(excludeFromPath, []byte(strings.Join(excludePatterns, "\n")), 0o644))
// Set up the flags
f := syncFlags{excludeFrom: excludeFromPath}
cmd := New()
cmd.SetContext(cmdctx.SetWorkspaceClient(t.Context(), nil))
// Test with both exclude flag and exclude-from flag
f.exclude = []string{"node_modules/"}
opts, err := f.syncOptionsFromArgs(cmd, []string{local, remote})
require.NoError(t, err)
// Should include both exclude flag and exclude-from patterns
expected := []string{"node_modules/", "*.log", "build/", "temp/*.tmp"}
assert.ElementsMatch(t, expected, opts.Exclude)
}