mirror of https://github.com/databricks/cli.git
Compare commits
4 Commits
1bb1d2c453
...
99dacc144f
Author | SHA1 | Date |
---|---|---|
Ilya Kuznetsov | 99dacc144f | |
Andrew Nester | 7f3fb10c4a | |
Ilya Kuznetsov | e9b72895dc | |
Ilya Kuznetsov | 8cd95eb0ea |
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/databricks/cli/bundle/config"
|
"github.com/databricks/cli/bundle/config"
|
||||||
"github.com/databricks/cli/bundle/config/mutator"
|
"github.com/databricks/cli/bundle/config/mutator"
|
||||||
"github.com/databricks/cli/bundle/config/resources"
|
"github.com/databricks/cli/bundle/config/resources"
|
||||||
|
"github.com/databricks/cli/libs/dbr"
|
||||||
"github.com/databricks/cli/libs/vfs"
|
"github.com/databricks/cli/libs/vfs"
|
||||||
"github.com/databricks/databricks-sdk-go/service/catalog"
|
"github.com/databricks/databricks-sdk-go/service/catalog"
|
||||||
"github.com/databricks/databricks-sdk-go/service/jobs"
|
"github.com/databricks/databricks-sdk-go/service/jobs"
|
||||||
|
@ -371,3 +372,86 @@ func TestApplyPresetsResourceNotDefined(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestApplyPresetsInPlaceDeployment(t *testing.T) {
|
||||||
|
testContext := context.Background()
|
||||||
|
enabled := true
|
||||||
|
disabled := false
|
||||||
|
remotePath := "/Users/files"
|
||||||
|
workspacePath := "/Workspace/user.name@company.com"
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
bundlePath string
|
||||||
|
ctx context.Context
|
||||||
|
name string
|
||||||
|
initialValue *bool
|
||||||
|
expectedValue *bool
|
||||||
|
expectedFilePath string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "preset enabled, bundle in Workspace, databricks runtime",
|
||||||
|
bundlePath: workspacePath,
|
||||||
|
ctx: dbr.MockRuntime(testContext, true),
|
||||||
|
initialValue: &enabled,
|
||||||
|
expectedValue: &enabled,
|
||||||
|
expectedFilePath: workspacePath,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "preset enabled, bundle not in Workspace, databricks runtime",
|
||||||
|
bundlePath: "/Users/user.name@company.com",
|
||||||
|
ctx: dbr.MockRuntime(testContext, true),
|
||||||
|
initialValue: &enabled,
|
||||||
|
expectedValue: &disabled,
|
||||||
|
expectedFilePath: remotePath,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "preset enabled, bundle in Workspace, not databricks runtime",
|
||||||
|
bundlePath: workspacePath,
|
||||||
|
ctx: dbr.MockRuntime(testContext, false),
|
||||||
|
initialValue: &enabled,
|
||||||
|
expectedValue: &disabled,
|
||||||
|
expectedFilePath: remotePath,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "preset disabled, bundle in Workspace, databricks runtime",
|
||||||
|
bundlePath: workspacePath,
|
||||||
|
ctx: dbr.MockRuntime(testContext, true),
|
||||||
|
initialValue: &disabled,
|
||||||
|
expectedValue: &disabled,
|
||||||
|
expectedFilePath: remotePath,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "preset nil, bundle in Workspace, databricks runtime",
|
||||||
|
bundlePath: workspacePath,
|
||||||
|
ctx: dbr.MockRuntime(testContext, true),
|
||||||
|
initialValue: nil,
|
||||||
|
expectedValue: nil,
|
||||||
|
expectedFilePath: remotePath,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
b := &bundle.Bundle{
|
||||||
|
Config: config.Root{
|
||||||
|
Presets: config.Presets{
|
||||||
|
InPlaceDeployment: tt.initialValue,
|
||||||
|
},
|
||||||
|
Workspace: config.Workspace{
|
||||||
|
FilePath: remotePath,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
SyncRoot: vfs.MustNew(tt.bundlePath),
|
||||||
|
SyncRootPath: tt.bundlePath,
|
||||||
|
}
|
||||||
|
|
||||||
|
diags := bundle.Apply(tt.ctx, b, mutator.ApplyPresets())
|
||||||
|
if diags.HasError() {
|
||||||
|
t.Fatalf("unexpected error: %v", diags)
|
||||||
|
}
|
||||||
|
|
||||||
|
require.Equal(t, tt.expectedFilePath, b.Config.Workspace.FilePath)
|
||||||
|
require.Equal(t, tt.expectedValue, b.Config.Presets.InPlaceDeployment)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,11 @@ func (m *prependWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) di
|
||||||
return dyn.InvalidValue, fmt.Errorf("expected string, got %s", v.Kind())
|
return dyn.InvalidValue, fmt.Errorf("expected string, got %s", v.Kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip prefixing if the path does not start with /, it might be variable reference or smth else.
|
||||||
|
if !strings.HasPrefix(path, "/") {
|
||||||
|
return pv, nil
|
||||||
|
}
|
||||||
|
|
||||||
for _, prefix := range skipPrefixes {
|
for _, prefix := range skipPrefixes {
|
||||||
if strings.HasPrefix(path, prefix) {
|
if strings.HasPrefix(path, prefix) {
|
||||||
return pv, nil
|
return pv, nil
|
||||||
|
|
|
@ -31,6 +31,14 @@ func TestPrependWorkspacePrefix(t *testing.T) {
|
||||||
path: "/Volumes/Users/test",
|
path: "/Volumes/Users/test",
|
||||||
expected: "/Volumes/Users/test",
|
expected: "/Volumes/Users/test",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "~/test",
|
||||||
|
expected: "~/test",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "${workspace.file_path}/test",
|
||||||
|
expected: "${workspace.file_path}/test",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/databricks/cli/bundle"
|
"github.com/databricks/cli/bundle"
|
||||||
"github.com/databricks/cli/bundle/config"
|
"github.com/databricks/cli/bundle/config"
|
||||||
"github.com/databricks/cli/bundle/config/resources"
|
"github.com/databricks/cli/bundle/config/resources"
|
||||||
|
"github.com/databricks/cli/libs/dbr"
|
||||||
"github.com/databricks/cli/libs/diag"
|
"github.com/databricks/cli/libs/diag"
|
||||||
"github.com/databricks/cli/libs/tags"
|
"github.com/databricks/cli/libs/tags"
|
||||||
"github.com/databricks/cli/libs/vfs"
|
"github.com/databricks/cli/libs/vfs"
|
||||||
|
@ -524,3 +525,31 @@ func TestPipelinesDevelopmentDisabled(t *testing.T) {
|
||||||
|
|
||||||
assert.False(t, b.Config.Resources.Pipelines["pipeline1"].PipelineSpec.Development)
|
assert.False(t, b.Config.Resources.Pipelines["pipeline1"].PipelineSpec.Development)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInPlaceDeploymentEnabled(t *testing.T) {
|
||||||
|
b, diags := processInPlaceBundle(true)
|
||||||
|
require.NoError(t, diags.Error())
|
||||||
|
assert.True(t, *b.Config.Presets.InPlaceDeployment)
|
||||||
|
assert.Equal(t, b.Config.Workspace.FilePath, b.SyncRootPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInPlaceDeploymentDisabled(t *testing.T) {
|
||||||
|
b, diags := processInPlaceBundle(false)
|
||||||
|
require.NoError(t, diags.Error())
|
||||||
|
assert.False(t, *b.Config.Presets.InPlaceDeployment)
|
||||||
|
assert.NotEqual(t, b.Config.Workspace.FilePath, b.SyncRootPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
func processInPlaceBundle(presetEnabled bool) (*bundle.Bundle, diag.Diagnostics) {
|
||||||
|
b := mockBundle(config.Development)
|
||||||
|
|
||||||
|
workspacePath := "/Workspace/lennart@company.com/"
|
||||||
|
b.SyncRoot = vfs.MustNew(workspacePath)
|
||||||
|
b.SyncRootPath = workspacePath
|
||||||
|
b.Config.Presets.InPlaceDeployment = &presetEnabled
|
||||||
|
|
||||||
|
ctx := dbr.MockRuntime(context.Background(), true)
|
||||||
|
m := bundle.Seq(ProcessTargetMode(), ApplyPresets())
|
||||||
|
diags := bundle.Apply(ctx, b, m)
|
||||||
|
return b, diags
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue