From e9b72895dc0569bbd7aeff81e4a1bef792b729bf Mon Sep 17 00:00:00 2001 From: Ilya Kuznetsov Date: Fri, 15 Nov 2024 12:32:44 +0100 Subject: [PATCH] test: Process target mode --- bundle/config/mutator/apply_presets_test.go | 2 +- .../mutator/process_target_mode_test.go | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/bundle/config/mutator/apply_presets_test.go b/bundle/config/mutator/apply_presets_test.go index 65ac912985..9c4dcddd72 100644 --- a/bundle/config/mutator/apply_presets_test.go +++ b/bundle/config/mutator/apply_presets_test.go @@ -374,7 +374,7 @@ func TestApplyPresetsResourceNotDefined(t *testing.T) { } func TestApplyPresetsInPlaceDeployment(t *testing.T) { - testContext := context.TODO() + testContext := context.Background() enabled := true disabled := false remotePath := "/Users/files" diff --git a/bundle/config/mutator/process_target_mode_test.go b/bundle/config/mutator/process_target_mode_test.go index 36cea8122b..81a2208a8d 100644 --- a/bundle/config/mutator/process_target_mode_test.go +++ b/bundle/config/mutator/process_target_mode_test.go @@ -9,6 +9,7 @@ import ( "github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/bundle/config/resources" + "github.com/databricks/cli/libs/dbr" "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/tags" "github.com/databricks/cli/libs/vfs" @@ -517,3 +518,31 @@ func TestPipelinesDevelopmentDisabled(t *testing.T) { 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 +}