2024-02-05 15:29:45 +00:00
|
|
|
package libraries
|
2024-04-22 11:44:34 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/config"
|
|
|
|
"github.com/databricks/cli/bundle/config/resources"
|
|
|
|
"github.com/databricks/cli/internal/testutil"
|
|
|
|
"github.com/databricks/databricks-sdk-go/service/compute"
|
|
|
|
"github.com/databricks/databricks-sdk-go/service/jobs"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestValidateEnvironments(t *testing.T) {
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
testutil.Touch(t, tmpDir, "wheel.whl")
|
|
|
|
|
|
|
|
b := &bundle.Bundle{
|
|
|
|
RootPath: tmpDir,
|
|
|
|
Config: config.Root{
|
|
|
|
Resources: config.Resources{
|
|
|
|
Jobs: map[string]*resources.Job{
|
|
|
|
"job": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Environments: []jobs.JobEnvironment{
|
|
|
|
{
|
|
|
|
Spec: &compute.Environment{
|
|
|
|
Dependencies: []string{
|
|
|
|
"./wheel.whl",
|
|
|
|
"simplejson",
|
|
|
|
"/Workspace/Users/foo@bar.com/artifacts/test.whl",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
diags := bundle.Apply(context.Background(), b, ValidateLocalLibrariesExist())
|
|
|
|
require.Nil(t, diags)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidateEnvironmentsNoFile(t *testing.T) {
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
|
|
|
|
b := &bundle.Bundle{
|
|
|
|
RootPath: tmpDir,
|
|
|
|
Config: config.Root{
|
|
|
|
Resources: config.Resources{
|
|
|
|
Jobs: map[string]*resources.Job{
|
|
|
|
"job": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Environments: []jobs.JobEnvironment{
|
|
|
|
{
|
|
|
|
Spec: &compute.Environment{
|
|
|
|
Dependencies: []string{
|
|
|
|
"./wheel.whl",
|
|
|
|
"simplejson",
|
|
|
|
"/Workspace/Users/foo@bar.com/artifacts/test.whl",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
diags := bundle.Apply(context.Background(), b, ValidateLocalLibrariesExist())
|
|
|
|
require.Len(t, diags, 1)
|
|
|
|
require.Equal(t, "file ./wheel.whl is referenced in environments section but doesn't exist on the local file system", diags[0].Summary)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidateTaskLibraries(t *testing.T) {
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
testutil.Touch(t, tmpDir, "wheel.whl")
|
|
|
|
|
|
|
|
b := &bundle.Bundle{
|
|
|
|
RootPath: tmpDir,
|
|
|
|
Config: config.Root{
|
|
|
|
Resources: config.Resources{
|
|
|
|
Jobs: map[string]*resources.Job{
|
|
|
|
"job": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Tasks: []jobs.Task{
|
|
|
|
{
|
|
|
|
Libraries: []compute.Library{
|
|
|
|
{
|
|
|
|
Whl: "./wheel.whl",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Whl: "/Workspace/Users/foo@bar.com/artifacts/test.whl",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
diags := bundle.Apply(context.Background(), b, ValidateLocalLibrariesExist())
|
|
|
|
require.Nil(t, diags)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidateTaskLibrariesNoFile(t *testing.T) {
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
|
|
|
|
b := &bundle.Bundle{
|
|
|
|
RootPath: tmpDir,
|
|
|
|
Config: config.Root{
|
|
|
|
Resources: config.Resources{
|
|
|
|
Jobs: map[string]*resources.Job{
|
|
|
|
"job": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Tasks: []jobs.Task{
|
|
|
|
{
|
|
|
|
Libraries: []compute.Library{
|
|
|
|
{
|
|
|
|
Whl: "./wheel.whl",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Whl: "/Workspace/Users/foo@bar.com/artifacts/test.whl",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
diags := bundle.Apply(context.Background(), b, ValidateLocalLibrariesExist())
|
|
|
|
require.Len(t, diags, 1)
|
|
|
|
require.Equal(t, "file ./wheel.whl is referenced in libraries section but doesn't exist on the local file system", diags[0].Summary)
|
|
|
|
}
|