diff --git a/bundle/config/mutator/apply_transforms.go b/bundle/config/mutator/apply_transforms.go index dacfa6ca56..d55a070ec6 100644 --- a/bundle/config/mutator/apply_transforms.go +++ b/bundle/config/mutator/apply_transforms.go @@ -3,6 +3,7 @@ package mutator import ( "context" "path" + "slices" "sort" "strings" @@ -88,14 +89,11 @@ func (m *applyTransforms) Apply(ctx context.Context, b *bundle.Bundle) diag.Diag for i := range r.Models { r.Models[i].Name = prefix + r.Models[i].Name for _, t := range tags { - exists := false - for _, modelTag := range r.Models[i].Tags { - if modelTag.Key == t.Key { - exists = true - break - } - } + exists := slices.ContainsFunc(r.Models[i].Tags, func(modelTag ml.ModelTag) bool { + return modelTag.Key == t.Key + }) if !exists { + // Only add this tag if the resource didn't include any tag that overrides its value. r.Models[i].Tags = append(r.Models[i].Tags, ml.ModelTag{Key: t.Key, Value: t.Value}) } } diff --git a/bundle/config/mutator/apply_transforms_test.go b/bundle/config/mutator/apply_transforms_test.go index fa27744dbe..05655bf642 100644 --- a/bundle/config/mutator/apply_transforms_test.go +++ b/bundle/config/mutator/apply_transforms_test.go @@ -10,6 +10,7 @@ import ( "github.com/databricks/cli/bundle/config/resources" "github.com/databricks/databricks-sdk-go/service/jobs" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestTransformPrefix(t *testing.T) { @@ -63,9 +64,7 @@ func TestTransformPrefix(t *testing.T) { t.Fatalf("unexpected error: %v", diag) } - if got := b.Config.Resources.Jobs["job1"].Name; got != tt.want { - t.Errorf("got %v, want %v", got, tt.want) - } + require.Equal(t, tt.want, b.Config.Resources.Jobs["job1"].Name) }) } } @@ -134,12 +133,8 @@ func TestTransformTags(t *testing.T) { t.Fatalf("unexpected error: %v", diag) } - got := b.Config.Resources.Jobs["job1"].Tags - for k, v := range tt.want { - if got[k] != v { - t.Errorf("tag %v: got %v, want %v", k, got[k], v) - } - } + tags := b.Config.Resources.Jobs["job1"].Tags + require.Equal(t, tt.want, tags) }) } } @@ -197,9 +192,7 @@ func TestTransformJobsMaxConcurrentRuns(t *testing.T) { t.Fatalf("unexpected error: %v", diag) } - if got := b.Config.Resources.Jobs["job1"].MaxConcurrentRuns; got != tt.want { - t.Errorf("got %v, want %v", got, tt.want) - } + require.Equal(t, tt.want, b.Config.Resources.Jobs["job1"].MaxConcurrentRuns) }) } }