2024-04-22 10:36:39 +00:00
|
|
|
package mutator
|
|
|
|
|
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDefaultQueueing(t *testing.T) {
|
|
|
|
m := DefaultQueueing()
|
|
|
|
assert.IsType(t, &defaultQueueing{}, m)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultQueueingName(t *testing.T) {
|
|
|
|
m := DefaultQueueing()
|
|
|
|
assert.Equal(t, "DefaultQueueing", m.Name())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultQueueingApplyNoJobs(t *testing.T) {
|
|
|
|
b := &bundle.Bundle{
|
|
|
|
Config: config.Root{
|
|
|
|
Resources: config.Resources{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
d := bundle.Apply(context.Background(), b, DefaultQueueing())
|
|
|
|
assert.Len(t, d, 0)
|
|
|
|
assert.Len(t, b.Config.Resources.Jobs, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultQueueingApplyJobsAlreadyEnabled(t *testing.T) {
|
|
|
|
b := &bundle.Bundle{
|
|
|
|
Config: config.Root{
|
|
|
|
Resources: config.Resources{
|
|
|
|
Jobs: map[string]*resources.Job{
|
|
|
|
"job": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Queue: &jobs.QueueSettings{Enabled: true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
d := bundle.Apply(context.Background(), b, DefaultQueueing())
|
|
|
|
assert.Len(t, d, 0)
|
|
|
|
assert.True(t, b.Config.Resources.Jobs["job"].Queue.Enabled)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultQueueingApplyEnableQueueing(t *testing.T) {
|
|
|
|
b := &bundle.Bundle{
|
|
|
|
Config: config.Root{
|
|
|
|
Resources: config.Resources{
|
|
|
|
Jobs: map[string]*resources.Job{
|
2024-05-17 10:10:17 +00:00
|
|
|
"job": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Name: "job",
|
|
|
|
},
|
|
|
|
},
|
2024-04-22 10:36:39 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
d := bundle.Apply(context.Background(), b, DefaultQueueing())
|
|
|
|
assert.Len(t, d, 0)
|
|
|
|
assert.NotNil(t, b.Config.Resources.Jobs["job"].Queue)
|
|
|
|
assert.True(t, b.Config.Resources.Jobs["job"].Queue.Enabled)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultQueueingApplyWithMultipleJobs(t *testing.T) {
|
|
|
|
b := &bundle.Bundle{
|
|
|
|
Config: config.Root{
|
|
|
|
Resources: config.Resources{
|
|
|
|
Jobs: map[string]*resources.Job{
|
|
|
|
"job1": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Queue: &jobs.QueueSettings{Enabled: false},
|
|
|
|
},
|
|
|
|
},
|
2024-05-17 10:10:17 +00:00
|
|
|
"job2": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Name: "job",
|
|
|
|
},
|
|
|
|
},
|
2024-04-22 10:36:39 +00:00
|
|
|
"job3": {
|
|
|
|
JobSettings: &jobs.JobSettings{
|
|
|
|
Queue: &jobs.QueueSettings{Enabled: true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
d := bundle.Apply(context.Background(), b, DefaultQueueing())
|
|
|
|
assert.Len(t, d, 0)
|
|
|
|
assert.False(t, b.Config.Resources.Jobs["job1"].Queue.Enabled)
|
|
|
|
assert.True(t, b.Config.Resources.Jobs["job2"].Queue.Enabled)
|
|
|
|
assert.True(t, b.Config.Resources.Jobs["job3"].Queue.Enabled)
|
|
|
|
}
|