Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lennartkats-db committed Jun 19, 2024
1 parent 4dc5f41 commit 82e1d49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
12 changes: 5 additions & 7 deletions bundle/config/mutator/apply_transforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mutator
import (
"context"
"path"
"slices"
"sort"
"strings"

Expand Down Expand Up @@ -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})
}
}
Expand Down
17 changes: 5 additions & 12 deletions bundle/config/mutator/apply_transforms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})
}
}
Expand Down Expand Up @@ -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)
})
}
}
Expand Down Expand Up @@ -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)
})
}
}
Expand Down

0 comments on commit 82e1d49

Please sign in to comment.