mirror of https://github.com/databricks/cli.git
add apply target mode prefix functionality
This commit is contained in:
parent
d04b6b08ea
commit
9b66cd523b
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue