Convert job task libraries to TF JSON (#132)

This commit is contained in:
Pieter Noordhuis 2022-12-12 16:36:59 +01:00 committed by GitHub
parent b42768801d
commit d713521d63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 0 deletions

View File

@ -30,6 +30,13 @@ func BundleToTerraform(config *config.Root) *schema.Root {
for _, v := range src.Tasks {
var t schema.ResourceJobTask
conv(v, &t)
for _, v_ := range v.Libraries {
var l schema.ResourceJobTaskLibrary
conv(v_, &l)
t.Library = append(t.Library, l)
}
dst.Task = append(dst.Task, t)
}

View File

@ -7,7 +7,9 @@ import (
"github.com/databricks/bricks/bundle/config/resources"
"github.com/databricks/databricks-sdk-go/service/clusters"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/databricks/databricks-sdk-go/service/libraries"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestConvertJob(t *testing.T) {
@ -43,3 +45,37 @@ func TestConvertJob(t *testing.T) {
assert.Equal(t, "https://github.com/foo/bar", out.Resource.Job["my_job"].GitSource.Url)
assert.Nil(t, out.Data)
}
func TestConvertJobTaskLibraries(t *testing.T) {
var src = resources.Job{
JobSettings: &jobs.JobSettings{
Name: "my job",
Tasks: []jobs.JobTaskSettings{
{
TaskKey: "key",
Libraries: []libraries.Library{
{
Pypi: &libraries.PythonPyPiLibrary{
Package: "mlflow",
},
},
},
},
},
},
}
var config = config.Root{
Resources: config.Resources{
Jobs: map[string]resources.Job{
"my_job": src,
},
},
}
out := BundleToTerraform(&config)
assert.Equal(t, "my job", out.Resource.Job["my_job"].Name)
require.Len(t, out.Resource.Job["my_job"].Task, 1)
require.Len(t, out.Resource.Job["my_job"].Task[0].Library, 1)
assert.Equal(t, "mlflow", out.Resource.Job["my_job"].Task[0].Library[0].Pypi.Package)
}