Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 214
Properly deal with nil values in convert.FromTyped#1511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
bf6e1b5b0ccdb6f3c6ca0d185e969836da9a13196e34728ad61c85b0File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,7 +18,7 @@ import ( | ||
| func allResourceTypes(t *testing.T) []string { | ||
| // Compute supported resource types based on the `Resources{}` struct. | ||
| r := config.Resources{} | ||
| r := &config.Resources{} | ||
| rv, err := convert.FromTyped(r, dyn.NilValue) | ||
| require.NoError(t, err) | ||
| normalized, _ := convert.Normalize(r, rv, convert.IncludeMissingFields) | ||
| @@ -154,6 +154,11 @@ func TestRunAsErrorForUnsupportedResources(t *testing.T) { | ||
| v, err := convert.FromTyped(base, dyn.NilValue) | ||
| require.NoError(t, err) | ||
| // Define top level resources key in the bundle configuration. | ||
| // This is not part of the typed configuration, so we need to add it manually. | ||
| v, err = dyn.Set(v, "resources", dyn.V(map[string]dyn.Value{})) | ||
| require.NoError(t, err) | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needed because the | ||
| for _, rt := range allResourceTypes(t) { | ||
| // Skip allowed resources | ||
| if slices.Contains(allowList, rt) { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -455,6 +455,24 @@ func TestBundleToTerraformModelServingPermissions(t *testing.T) { | ||
| var src = resources.ModelServingEndpoint{ | ||
| CreateServingEndpoint: &serving.CreateServingEndpoint{ | ||
| Name: "name", | ||
| // Need to specify this to satisfy the equivalence test: | ||
| // The previous method of generation includes the "create" field | ||
| // because it is required (not marked as `omitempty`). | ||
| // The previous method used [json.Marshal] from the standard library | ||
| // and as such observed the `omitempty` tag. | ||
| // The new method leverages [dyn.Value] where any field that is not | ||
| // explicitly set is not part of the value. | ||
| Config: serving.EndpointCoreConfigInput{ | ||
| ServedModels: []serving.ServedModelInput{ | ||
| { | ||
| ModelName: "model_name", | ||
| ModelVersion: "1", | ||
| ScaleToZeroEnabled: true, | ||
| WorkloadSize: "Small", | ||
| }, | ||
| }, | ||
| }, | ||
pietern marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }, | ||
| Permissions: []resources.Permission{ | ||
| { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -66,6 +66,11 @@ func (m *filterCurrentUser) Apply(ctx context.Context, b *bundle.Bundle) diag.Di | ||
| err := b.Config.Mutate(func(v dyn.Value) (dyn.Value, error) { | ||
| rv, err := dyn.Get(v, "resources") | ||
| if err != nil { | ||
| // If the resources key is not found, we can skip this mutator. | ||
| if dyn.IsNoSuchKeyError(err) { | ||
| return v, nil | ||
| } | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needed because "resources" may not exist (this is the case in some tests). | ||
| return dyn.InvalidValue, err | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed because an empty struct with a nil reference returns a nil value.