Fix tests

This commit is contained in:
Lennart Kats 2024-11-13 09:49:05 +01:00
parent a43bcc4c63
commit c4301b7a44
No known key found for this signature in database
GPG Key ID: 1EB8B57673197023
2 changed files with 12 additions and 6 deletions

View File

@ -42,6 +42,7 @@ func (m *overrideCompute) Apply(ctx context.Context, b *bundle.Bundle) diag.Diag
if b.Config.Bundle.Mode == config.Production { if b.Config.Bundle.Mode == config.Production {
if b.Config.Bundle.ClusterId != "" { if b.Config.Bundle.ClusterId != "" {
// Overriding compute via a command-line flag for production works, but is not recommended.
diags = diags.Extend(diag.Warningf("overriding compute for a target that uses 'mode: production' is not recommended")) diags = diags.Extend(diag.Warningf("overriding compute for a target that uses 'mode: production' is not recommended"))
} }
if env.Get(ctx, "DATABRICKS_CLUSTER_ID") != "" { if env.Get(ctx, "DATABRICKS_CLUSTER_ID") != "" {

View File

@ -144,7 +144,7 @@ func TestOverrideComputeForEachTask(t *testing.T) {
assert.Empty(t, b.Config.Resources.Jobs["job1"].Tasks[0].ForEachTask.Task) assert.Empty(t, b.Config.Resources.Jobs["job1"].Tasks[0].ForEachTask.Task)
} }
func TesOverrideComputeProductionMode(t *testing.T) { func TestOverrideComputeModeProduction(t *testing.T) {
b := &bundle.Bundle{ b := &bundle.Bundle{
Config: config.Root{ Config: config.Root{
Bundle: config.Bundle{ Bundle: config.Bundle{
@ -171,15 +171,18 @@ func TesOverrideComputeProductionMode(t *testing.T) {
m := mutator.OverrideCompute() m := mutator.OverrideCompute()
diags := bundle.Apply(context.Background(), b, m) diags := bundle.Apply(context.Background(), b, m)
require.True(t, diags.HasError()) require.Len(t, diags, 1)
assert.ErrorContains(t, diags.Error(), "overriding compute is not allowed in production mode") assert.Equal(t, "overriding compute for a target that uses 'mode: production' is not recommended", diags[0].Summary)
assert.Equal(t, "cluster2", b.Config.Resources.Jobs["job1"].Tasks[0].ExistingClusterId) assert.Equal(t, "newClusterID", b.Config.Resources.Jobs["job1"].Tasks[0].ExistingClusterId)
} }
func TestOverrideProductionEnv(t *testing.T) { func TestOverrideComputeModeProductionIgnoresVariable(t *testing.T) {
t.Setenv("DATABRICKS_CLUSTER_ID", "newClusterId") t.Setenv("DATABRICKS_CLUSTER_ID", "newClusterId")
b := &bundle.Bundle{ b := &bundle.Bundle{
Config: config.Root{ Config: config.Root{
Bundle: config.Bundle{
Mode: config.Production,
},
Resources: config.Resources{ Resources: config.Resources{
Jobs: map[string]*resources.Job{ Jobs: map[string]*resources.Job{
"job1": {JobSettings: &jobs.JobSettings{ "job1": {JobSettings: &jobs.JobSettings{
@ -200,5 +203,7 @@ func TestOverrideProductionEnv(t *testing.T) {
m := mutator.OverrideCompute() m := mutator.OverrideCompute()
diags := bundle.Apply(context.Background(), b, m) diags := bundle.Apply(context.Background(), b, m)
require.NoError(t, diags.Error()) require.Len(t, diags, 1)
assert.Equal(t, "the DATABRICKS_CLUSTER_ID variable is set but is ignored since the current target uses 'mode: production'", diags[0].Summary)
assert.Equal(t, "cluster2", b.Config.Resources.Jobs["job1"].Tasks[1].ExistingClusterId)
} }