Filter down to Python wheel tasks only for trampoline (#712)

## Changes

Fixes issue introduced in #635.

## Tests

Added new unit test to confirm correct behavior.

Manually deployed sample bundle.
This commit is contained in:
Pieter Noordhuis 2023-08-30 15:51:15 +02:00 committed by GitHub
parent 12368e3382
commit ca2f1dc06c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 8 deletions

View File

@ -69,6 +69,12 @@ func (t *pythonTrampoline) GetTasks(b *bundle.Bundle) []mutator.TaskWithJobKey {
tasks := r.Jobs[k].JobSettings.Tasks tasks := r.Jobs[k].JobSettings.Tasks
for i := range tasks { for i := range tasks {
task := &tasks[i] task := &tasks[i]
// Keep only Python wheel tasks
if task.PythonWheelTask == nil {
continue
}
result = append(result, mutator.TaskWithJobKey{ result = append(result, mutator.TaskWithJobKey{
JobKey: k, JobKey: k,
Task: task, Task: task,

View File

@ -4,6 +4,9 @@ import (
"strings" "strings"
"testing" "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/jobs" "github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -12,9 +15,9 @@ type testCase struct {
Actual []string Actual []string
Expected string Expected string
} }
type NamedParams map[string]string
type testCaseNamed struct { type testCaseNamed struct {
Actual NamedParams Actual map[string]string
Expected string Expected string
} }
@ -27,12 +30,12 @@ var paramsTestCases []testCase = []testCase{
} }
var paramsTestCasesNamed []testCaseNamed = []testCaseNamed{ var paramsTestCasesNamed []testCaseNamed = []testCaseNamed{
{NamedParams{}, `"python"`}, {map[string]string{}, `"python"`},
{NamedParams{"a": "1"}, `"python", "a=1"`}, {map[string]string{"a": "1"}, `"python", "a=1"`},
{NamedParams{"a": "'1'"}, `"python", "a='1'"`}, {map[string]string{"a": "'1'"}, `"python", "a='1'"`},
{NamedParams{"a": `"1"`}, `"python", "a=\"1\""`}, {map[string]string{"a": `"1"`}, `"python", "a=\"1\""`},
{NamedParams{"a": "1", "b": "2"}, `"python", "a=1", "b=2"`}, {map[string]string{"a": "1", "b": "2"}, `"python", "a=1", "b=2"`},
{NamedParams{"data": `{"a": 1}`}, `"python", "data={\"a\": 1}"`}, {map[string]string{"data": `{"a": 1}`}, `"python", "data={\"a\": 1}"`},
} }
func TestGenerateParameters(t *testing.T) { func TestGenerateParameters(t *testing.T) {
@ -64,3 +67,35 @@ func TestGenerateBoth(t *testing.T) {
require.Error(t, err) require.Error(t, err)
require.ErrorContains(t, err, "not allowed to pass both paramaters and named_parameters") require.ErrorContains(t, err, "not allowed to pass both paramaters and named_parameters")
} }
func TestTransformFiltersWheelTasksOnly(t *testing.T) {
trampoline := pythonTrampoline{}
bundle := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"job1": {
JobSettings: &jobs.JobSettings{
Tasks: []jobs.Task{
{
TaskKey: "key1",
PythonWheelTask: &jobs.PythonWheelTask{},
},
{
TaskKey: "key2",
NotebookTask: &jobs.NotebookTask{},
},
},
},
},
},
},
},
}
tasks := trampoline.GetTasks(bundle)
require.Len(t, tasks, 1)
require.Equal(t, "job1", tasks[0].JobKey)
require.Equal(t, "key1", tasks[0].Task.TaskKey)
require.NotNil(t, tasks[0].Task.PythonWheelTask)
}