2024-09-27 09:32:54 +00:00
|
|
|
package trampoline
|
2023-09-26 14:32:20 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/config"
|
|
|
|
"github.com/databricks/cli/bundle/config/resources"
|
|
|
|
"github.com/databricks/databricks-sdk-go/service/compute"
|
|
|
|
"github.com/databricks/databricks-sdk-go/service/jobs"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNoTransformByDefault(t *testing.T) {
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
|
|
|
|
b := &bundle.Bundle{
|
2024-09-27 10:03:05 +00:00
|
|
|
BundleRootPath: filepath.Join(tmpDir, "parent", "my_bundle"),
|
|
|
|
SyncRootPath: filepath.Join(tmpDir, "parent"),
|
2023-09-26 14:32:20 +00:00
|
|
|
Config: config.Root{
|
|
|
|
Bundle: config.Bundle{
|
|
|
|
Target: "development",
|
|
|
|
},
|
2024-08-21 15:33:25 +00:00
|
|
|
Workspace: config.Workspace{
|
|
|
|
FilePath: "/Workspace/files",
|
|
|
|
},
|
2023-09-26 14:32:20 +00:00
|
|
|
Resources: config.Resources{
|
|
|
|
Jobs: map[string]*resources.Job{
|
|
|
|
"job1": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Tasks: []jobs.Task{
|
|
|
|
{
|
|
|
|
TaskKey: "key1",
|
|
|
|
PythonWheelTask: &jobs.PythonWheelTask{
|
|
|
|
PackageName: "test_package",
|
|
|
|
EntryPoint: "main",
|
|
|
|
},
|
|
|
|
Libraries: []compute.Library{
|
|
|
|
{Whl: "/Workspace/Users/test@test.com/bundle/dist/test.whl"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
trampoline := TransformWheelTask()
|
2024-03-25 14:18:47 +00:00
|
|
|
diags := bundle.Apply(context.Background(), b, trampoline)
|
|
|
|
require.NoError(t, diags.Error())
|
2023-09-26 14:32:20 +00:00
|
|
|
|
|
|
|
task := b.Config.Resources.Jobs["job1"].Tasks[0]
|
|
|
|
require.NotNil(t, task.PythonWheelTask)
|
|
|
|
require.Equal(t, "test_package", task.PythonWheelTask.PackageName)
|
|
|
|
require.Equal(t, "main", task.PythonWheelTask.EntryPoint)
|
|
|
|
require.Equal(t, "/Workspace/Users/test@test.com/bundle/dist/test.whl", task.Libraries[0].Whl)
|
|
|
|
|
|
|
|
require.Nil(t, task.NotebookTask)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTransformWithExperimentalSettingSetToTrue(t *testing.T) {
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
|
|
|
|
b := &bundle.Bundle{
|
2024-09-27 10:03:05 +00:00
|
|
|
BundleRootPath: filepath.Join(tmpDir, "parent", "my_bundle"),
|
|
|
|
SyncRootPath: filepath.Join(tmpDir, "parent"),
|
2023-09-26 14:32:20 +00:00
|
|
|
Config: config.Root{
|
|
|
|
Bundle: config.Bundle{
|
|
|
|
Target: "development",
|
|
|
|
},
|
2024-08-21 15:33:25 +00:00
|
|
|
Workspace: config.Workspace{
|
|
|
|
FilePath: "/Workspace/files",
|
|
|
|
},
|
2023-09-26 14:32:20 +00:00
|
|
|
Resources: config.Resources{
|
|
|
|
Jobs: map[string]*resources.Job{
|
|
|
|
"job1": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Tasks: []jobs.Task{
|
|
|
|
{
|
|
|
|
TaskKey: "key1",
|
|
|
|
PythonWheelTask: &jobs.PythonWheelTask{
|
|
|
|
PackageName: "test_package",
|
|
|
|
EntryPoint: "main",
|
|
|
|
},
|
|
|
|
Libraries: []compute.Library{
|
|
|
|
{Whl: "/Workspace/Users/test@test.com/bundle/dist/test.whl"},
|
2024-03-04 12:34:03 +00:00
|
|
|
{Jar: "/Workspace/Users/test@test.com/bundle/dist/test.jar"},
|
2023-09-26 14:32:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Experimental: &config.Experimental{
|
|
|
|
PythonWheelWrapper: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
trampoline := TransformWheelTask()
|
2024-03-25 14:18:47 +00:00
|
|
|
diags := bundle.Apply(context.Background(), b, trampoline)
|
|
|
|
require.NoError(t, diags.Error())
|
2023-09-26 14:32:20 +00:00
|
|
|
|
|
|
|
task := b.Config.Resources.Jobs["job1"].Tasks[0]
|
|
|
|
require.Nil(t, task.PythonWheelTask)
|
|
|
|
require.NotNil(t, task.NotebookTask)
|
2024-08-21 15:33:25 +00:00
|
|
|
require.Equal(t, "/Workspace/files/my_bundle/.databricks/bundle/development/.internal/notebook_job1_key1", task.NotebookTask.NotebookPath)
|
2023-09-26 14:32:20 +00:00
|
|
|
|
2024-03-04 12:34:03 +00:00
|
|
|
require.Len(t, task.Libraries, 1)
|
|
|
|
require.Equal(t, "/Workspace/Users/test@test.com/bundle/dist/test.jar", task.Libraries[0].Jar)
|
2023-09-26 14:32:20 +00:00
|
|
|
}
|