2024-04-18 15:13:16 +00:00
|
|
|
package validate
|
|
|
|
|
|
|
|
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/libs/diag"
|
|
|
|
"github.com/databricks/databricks-sdk-go/service/jobs"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestJobClusterKeyDefined(t *testing.T) {
|
|
|
|
b := &bundle.Bundle{
|
|
|
|
Config: config.Root{
|
|
|
|
Resources: config.Resources{
|
|
|
|
Jobs: map[string]*resources.Job{
|
|
|
|
"job1": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Name: "job1",
|
|
|
|
JobClusters: []jobs.JobCluster{
|
|
|
|
{JobClusterKey: "do-not-exist"},
|
|
|
|
},
|
|
|
|
Tasks: []jobs.Task{
|
|
|
|
{JobClusterKey: "do-not-exist"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
diags := bundle.ApplyReadOnly(context.Background(), bundle.ReadOnly(b), JobClusterKeyDefined())
|
2025-01-02 11:03:41 +00:00
|
|
|
require.Empty(t, diags)
|
2024-04-18 15:13:16 +00:00
|
|
|
require.NoError(t, diags.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJobClusterKeyNotDefined(t *testing.T) {
|
|
|
|
b := &bundle.Bundle{
|
|
|
|
Config: config.Root{
|
|
|
|
Resources: config.Resources{
|
|
|
|
Jobs: map[string]*resources.Job{
|
|
|
|
"job1": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Name: "job1",
|
|
|
|
Tasks: []jobs.Task{
|
|
|
|
{JobClusterKey: "do-not-exist"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
diags := bundle.ApplyReadOnly(context.Background(), bundle.ReadOnly(b), JobClusterKeyDefined())
|
|
|
|
require.Len(t, diags, 1)
|
|
|
|
require.NoError(t, diags.Error())
|
2025-01-02 11:03:41 +00:00
|
|
|
require.Equal(t, diag.Warning, diags[0].Severity)
|
|
|
|
require.Equal(t, "job_cluster_key do-not-exist is not defined", diags[0].Summary)
|
2024-04-18 15:13:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestJobClusterKeyDefinedInDifferentJob(t *testing.T) {
|
|
|
|
b := &bundle.Bundle{
|
|
|
|
Config: config.Root{
|
|
|
|
Resources: config.Resources{
|
|
|
|
Jobs: map[string]*resources.Job{
|
|
|
|
"job1": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Name: "job1",
|
|
|
|
Tasks: []jobs.Task{
|
|
|
|
{JobClusterKey: "do-not-exist"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"job2": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Name: "job2",
|
|
|
|
JobClusters: []jobs.JobCluster{
|
|
|
|
{JobClusterKey: "do-not-exist"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
diags := bundle.ApplyReadOnly(context.Background(), bundle.ReadOnly(b), JobClusterKeyDefined())
|
|
|
|
require.Len(t, diags, 1)
|
|
|
|
require.NoError(t, diags.Error())
|
2025-01-02 11:03:41 +00:00
|
|
|
require.Equal(t, diag.Warning, diags[0].Severity)
|
|
|
|
require.Equal(t, "job_cluster_key do-not-exist is not defined", diags[0].Summary)
|
2024-04-18 15:13:16 +00:00
|
|
|
}
|