fix renaming test

This commit is contained in:
Shreyas Goenka 2024-11-18 18:11:55 +01:00
parent 76092ccaa7
commit 039057fdd7
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
1 changed files with 18 additions and 11 deletions

View File

@ -3,7 +3,7 @@ package mutator
import ( import (
"context" "context"
"reflect" "reflect"
"strings" "slices"
"testing" "testing"
"github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle"
@ -391,10 +391,17 @@ func TestAllResourcesMocked(t *testing.T) {
} }
} }
// Make sure that we at least rename all resources // Make sure that we at rename all non UC resources
func TestAllResourcesRenamed(t *testing.T) { func TestAllNonUCResourcesAreRenamed(t *testing.T) {
b := mockBundle(config.Development) b := mockBundle(config.Development)
// UC resources should not have a prefix added to their name. Right now
// this list only contains the Volume resource since we have yet to remove
// prefixing support for UC schemas and registered models.
ucFields := []reflect.Type{
reflect.TypeOf(&resources.Volume{}),
}
m := bundle.Seq(ProcessTargetMode(), ApplyPresets()) m := bundle.Seq(ProcessTargetMode(), ApplyPresets())
diags := bundle.Apply(context.Background(), b, m) diags := bundle.Apply(context.Background(), b, m)
require.NoError(t, diags.Error()) require.NoError(t, diags.Error())
@ -407,14 +414,14 @@ func TestAllResourcesRenamed(t *testing.T) {
for _, key := range field.MapKeys() { for _, key := range field.MapKeys() {
resource := field.MapIndex(key) resource := field.MapIndex(key)
nameField := resource.Elem().FieldByName("Name") nameField := resource.Elem().FieldByName("Name")
if nameField.IsValid() && nameField.Kind() == reflect.String { if !nameField.IsValid() || nameField.Kind() != reflect.String {
assert.True( continue
t, }
strings.Contains(nameField.String(), "dev"),
"process_target_mode should rename '%s' in '%s'", if slices.Contains(ucFields, resource.Type()) {
key, assert.NotContains(t, nameField.String(), "dev", "process_target_mode should not rename '%s' in '%s'", key, resources.Type().Field(i).Name)
resources.Type().Field(i).Name, } else {
) assert.Contains(t, nameField.String(), "dev", "process_target_mode should rename '%s' in '%s'", key, resources.Type().Field(i).Name)
} }
} }
} }