2023-08-29 08:26:09 +00:00
|
|
|
package libraries
|
|
|
|
|
|
|
|
import (
|
2024-02-05 15:29:45 +00:00
|
|
|
"context"
|
|
|
|
"path/filepath"
|
2023-08-29 08:26:09 +00:00
|
|
|
"testing"
|
|
|
|
|
2024-02-05 15:29:45 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/config"
|
|
|
|
"github.com/databricks/cli/bundle/config/resources"
|
2023-08-29 08:26:09 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/service/compute"
|
2024-02-05 15:29:45 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/service/jobs"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-08-29 08:26:09 +00:00
|
|
|
)
|
|
|
|
|
2024-02-05 15:29:45 +00:00
|
|
|
func TestMapFilesToTaskLibrariesNoGlob(t *testing.T) {
|
|
|
|
b := &bundle.Bundle{
|
2024-03-27 09:03:24 +00:00
|
|
|
RootPath: "testdata",
|
2024-02-05 15:29:45 +00:00
|
|
|
Config: config.Root{
|
|
|
|
Resources: config.Resources{
|
|
|
|
Jobs: map[string]*resources.Job{
|
|
|
|
"job1": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Tasks: []jobs.Task{
|
|
|
|
{
|
|
|
|
Libraries: []compute.Library{
|
|
|
|
{
|
|
|
|
Whl: "library1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Whl: "library2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Whl: "/absolute/path/in/workspace/library3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Libraries: []compute.Library{
|
|
|
|
{
|
|
|
|
Whl: "library1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Whl: "library2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"job2": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Tasks: []jobs.Task{
|
|
|
|
{
|
|
|
|
Libraries: []compute.Library{
|
|
|
|
{
|
|
|
|
Whl: "library1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Whl: "library2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-08-29 08:26:09 +00:00
|
|
|
}
|
2024-02-05 15:29:45 +00:00
|
|
|
|
|
|
|
out := MapFilesToTaskLibraries(context.Background(), b)
|
|
|
|
assert.Len(t, out, 2)
|
|
|
|
|
|
|
|
// Pointer equality for "library1"
|
|
|
|
assert.Equal(t, []*compute.Library{
|
|
|
|
&b.Config.Resources.Jobs["job1"].JobSettings.Tasks[0].Libraries[0],
|
|
|
|
&b.Config.Resources.Jobs["job1"].JobSettings.Tasks[1].Libraries[0],
|
|
|
|
&b.Config.Resources.Jobs["job2"].JobSettings.Tasks[0].Libraries[0],
|
|
|
|
}, out[filepath.Clean("testdata/library1")])
|
|
|
|
|
|
|
|
// Pointer equality for "library2"
|
|
|
|
assert.Equal(t, []*compute.Library{
|
|
|
|
&b.Config.Resources.Jobs["job1"].JobSettings.Tasks[0].Libraries[1],
|
|
|
|
&b.Config.Resources.Jobs["job1"].JobSettings.Tasks[1].Libraries[1],
|
|
|
|
&b.Config.Resources.Jobs["job2"].JobSettings.Tasks[0].Libraries[1],
|
|
|
|
}, out[filepath.Clean("testdata/library2")])
|
2023-08-29 08:26:09 +00:00
|
|
|
}
|