add apply target mode prefix functionality

This commit is contained in:
Shreyas Goenka 2024-09-09 15:11:57 +02:00
parent d04b6b08ea
commit 9b66cd523b
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
2 changed files with 63 additions and 0 deletions

View File

@ -160,6 +160,13 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos
// the Databricks UI and via the SQL API.
}
// Apply the prefix to volumes
for i := range r.Volumes {
r.Volumes[i].Name = normalizePrefix(prefix) + r.Volumes[i].Name
// HTTP API for volumes doesn't yet support tags. It's only supported in
// the Databricks UI and via the SQL API.
}
return nil
}

View File

@ -125,6 +125,62 @@ func TestApplyPresetsPrefixForUcSchema(t *testing.T) {
}
}
func TestApplyPresetsPrefixForUcVolumes(t *testing.T) {
tests := []struct {
name string
prefix string
volume *resources.Volume
want string
}{
{
name: "add prefix to volume",
prefix: "[prefix]",
volume: &resources.Volume{
CreateVolumeRequestContent: &catalog.CreateVolumeRequestContent{
Name: "volume1",
},
},
want: "prefix_volume1",
},
{
name: "add empty prefix to volume",
prefix: "",
volume: &resources.Volume{
CreateVolumeRequestContent: &catalog.CreateVolumeRequestContent{
Name: "volume1",
},
},
want: "volume1",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
b := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Volumes: map[string]*resources.Volume{
"volume1": tt.volume,
},
},
Presets: config.Presets{
NamePrefix: tt.prefix,
},
},
}
ctx := context.Background()
diag := bundle.Apply(ctx, b, mutator.ApplyPresets())
if diag.HasError() {
t.Fatalf("unexpected error: %v", diag)
}
require.Equal(t, tt.want, b.Config.Resources.Volumes["volume1"].Name)
})
}
}
func TestApplyPresetsTags(t *testing.T) {
tests := []struct {
name string