2023-12-19 07:38:52 +00:00
|
|
|
package metadata
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"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/stretchr/testify/assert"
|
2024-03-25 14:18:47 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-12-19 07:38:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAnnotateJobsMutator(t *testing.T) {
|
|
|
|
b := &bundle.Bundle{
|
|
|
|
Config: config.Root{
|
|
|
|
Workspace: config.Workspace{
|
|
|
|
StatePath: "/a/b/c",
|
|
|
|
},
|
|
|
|
Resources: config.Resources{
|
|
|
|
Jobs: map[string]*resources.Job{
|
|
|
|
"my-job-1": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Name: "My Job One",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"my-job-2": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Name: "My Job Two",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-03-25 14:18:47 +00:00
|
|
|
diags := AnnotateJobs().Apply(context.Background(), b)
|
|
|
|
require.NoError(t, diags.Error())
|
2023-12-19 07:38:52 +00:00
|
|
|
|
|
|
|
assert.Equal(t,
|
|
|
|
&jobs.JobDeployment{
|
|
|
|
Kind: jobs.JobDeploymentKindBundle,
|
|
|
|
MetadataFilePath: "/a/b/c/metadata.json",
|
|
|
|
},
|
|
|
|
b.Config.Resources.Jobs["my-job-1"].JobSettings.Deployment)
|
|
|
|
assert.Equal(t, jobs.JobSettingsEditModeUiLocked, b.Config.Resources.Jobs["my-job-1"].EditMode)
|
|
|
|
assert.Equal(t, jobs.FormatMultiTask, b.Config.Resources.Jobs["my-job-1"].Format)
|
|
|
|
|
|
|
|
assert.Equal(t,
|
|
|
|
&jobs.JobDeployment{
|
|
|
|
Kind: jobs.JobDeploymentKindBundle,
|
|
|
|
MetadataFilePath: "/a/b/c/metadata.json",
|
|
|
|
},
|
|
|
|
b.Config.Resources.Jobs["my-job-2"].JobSettings.Deployment)
|
|
|
|
assert.Equal(t, jobs.JobSettingsEditModeUiLocked, b.Config.Resources.Jobs["my-job-2"].EditMode)
|
|
|
|
assert.Equal(t, jobs.FormatMultiTask, b.Config.Resources.Jobs["my-job-2"].Format)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAnnotateJobsMutatorJobWithoutSettings(t *testing.T) {
|
|
|
|
b := &bundle.Bundle{
|
|
|
|
Config: config.Root{
|
|
|
|
Resources: config.Resources{
|
|
|
|
Jobs: map[string]*resources.Job{
|
|
|
|
"my-job-1": {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-03-25 14:18:47 +00:00
|
|
|
diags := AnnotateJobs().Apply(context.Background(), b)
|
|
|
|
require.NoError(t, diags.Error())
|
2023-12-19 07:38:52 +00:00
|
|
|
}
|