-
Notifications
You must be signed in to change notification settings - Fork 50
Add more shim layer tests for pf #2231
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -32,7 +32,6 @@ import ( | |||
|
|
||||
| // Test how various PF-based schemata translate to the shim.Schema layer. | ||||
| func TestSchemaShimRepresentations(t *testing.T) { | ||||
|
|
||||
| type testCase struct { | ||||
| name string | ||||
| provider provider.Provider | ||||
|
|
@@ -41,16 +40,38 @@ func TestSchemaShimRepresentations(t *testing.T) { | |||
|
|
||||
| testCases := []testCase{ | ||||
| { | ||||
| "single-nested-block", | ||||
| "simple-attribute", | ||||
| &pb.Provider{ | ||||
| AllResources: []pb.Resource{{ | ||||
| ResourceSchema: schema.Schema{ | ||||
| Blocks: map[string]schema.Block{ | ||||
| "single_nested_block": schema.SingleNestedBlock{ | ||||
| Attributes: map[string]schema.Attribute{ | ||||
| "a1": schema.Float64Attribute{ | ||||
| Optional: true, | ||||
| }, | ||||
| Attributes: map[string]schema.Attribute{ | ||||
| "simple_attribute": schema.StringAttribute{ | ||||
| Optional: true, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }}, | ||||
| }, | ||||
| autogold.Expect(`{ | ||||
| "resources": { | ||||
| "_": { | ||||
| "simple_attribute": { | ||||
| "optional": true, | ||||
| "type": 4 | ||||
| } | ||||
| } | ||||
| } | ||||
| }`), | ||||
| }, | ||||
| { | ||||
| "object-attribute", | ||||
| &pb.Provider{ | ||||
| AllResources: []pb.Resource{{ | ||||
| ResourceSchema: schema.Schema{ | ||||
| Attributes: map[string]schema.Attribute{ | ||||
| "object_attribute": schema.ObjectAttribute{ | ||||
| AttributeTypes: map[string]attr.Type{ | ||||
| "a1": types.StringType, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
|
|
@@ -60,51 +81,132 @@ func TestSchemaShimRepresentations(t *testing.T) { | |||
| autogold.Expect(`{ | ||||
| "resources": { | ||||
| "_": { | ||||
| "single_nested_block": { | ||||
| "object_attribute": { | ||||
| "element": { | ||||
| "resource": { | ||||
| "a1": { | ||||
| "optional": true, | ||||
| "type": 3 | ||||
| "type": 4 | ||||
| } | ||||
| } | ||||
| }, | ||||
| "optional": true, | ||||
| "type": 6 | ||||
| } | ||||
| } | ||||
| } | ||||
| }`), | ||||
| }, | ||||
| { | ||||
| "list-nested-block", | ||||
| "list-attribute", | ||||
| &pb.Provider{ | ||||
| AllResources: []pb.Resource{{ | ||||
| ResourceSchema: schema.Schema{ | ||||
| Blocks: map[string]schema.Block{ | ||||
| "list_nested_block": schema.ListNestedBlock{ | ||||
| NestedObject: schema.NestedBlockObject{ | ||||
| Attributes: map[string]schema.Attribute{ | ||||
| "a1": schema.Float64Attribute{ | ||||
| Optional: true, | ||||
| AllResources: []pb.Resource{ | ||||
| { | ||||
| ResourceSchema: schema.Schema{ | ||||
| Attributes: map[string]schema.Attribute{ | ||||
| "list_attribute": schema.ListAttribute{ | ||||
| Optional: true, | ||||
| ElementType: types.StringType, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| autogold.Expect(`{ | ||||
| "resources": { | ||||
| "_": { | ||||
| "list_attribute": { | ||||
| "element": { | ||||
| "schema": { | ||||
| "type": 4 | ||||
| } | ||||
| }, | ||||
| "optional": true, | ||||
| "type": 5 | ||||
| } | ||||
| } | ||||
| } | ||||
| }`), | ||||
| }, | ||||
| { | ||||
| "list-attribute-object-element", | ||||
| &pb.Provider{ | ||||
| AllResources: []pb.Resource{ | ||||
| { | ||||
| ResourceSchema: schema.Schema{ | ||||
| Attributes: map[string]schema.Attribute{ | ||||
| "list_attribute": schema.ListAttribute{ | ||||
| Optional: true, | ||||
| ElementType: types.ObjectType{ | ||||
| AttrTypes: map[string]attr.Type{ | ||||
| "a1": types.StringType, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }}, | ||||
| }, | ||||
| }, | ||||
| autogold.Expect(`{ | ||||
| "resources": { | ||||
| "_": { | ||||
| "list_nested_block": { | ||||
| "list_attribute": { | ||||
| "element": { | ||||
| "resource": { | ||||
| "a1": { | ||||
| "optional": true, | ||||
| "type": 3 | ||||
| } | ||||
| "schema": { | ||||
| "element": { | ||||
| "resource": { | ||||
| "a1": { | ||||
| "type": 4 | ||||
| } | ||||
| } | ||||
| }, | ||||
| "type": 6 | ||||
| } | ||||
| }, | ||||
| "optional": true, | ||||
| "type": 5 | ||||
| } | ||||
| } | ||||
| } | ||||
| }`), | ||||
| }, | ||||
| { | ||||
| "list-nested-attribute", | ||||
| &pb.Provider{ | ||||
| AllResources: []pb.Resource{ | ||||
| { | ||||
| ResourceSchema: schema.Schema{ | ||||
| Attributes: map[string]schema.Attribute{ | ||||
| "list_nested_attribute": schema.ListNestedAttribute{ | ||||
| Optional: true, | ||||
| NestedObject: schema.NestedAttributeObject{ | ||||
| Attributes: map[string]schema.Attribute{ | ||||
| "a1": schema.StringAttribute{ | ||||
| Optional: true, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| autogold.Expect(`{ | ||||
| "resources": { | ||||
| "_": { | ||||
| "list_nested_attribute": { | ||||
| "element": { | ||||
| "schema": { | ||||
| "element": { | ||||
| "resource": { | ||||
| "a1": { | ||||
| "optional": true, | ||||
| "type": 4 | ||||
| } | ||||
| } | ||||
| }, | ||||
| "type": 6 | ||||
| } | ||||
| }, | ||||
| "optional": true, | ||||
|
|
@@ -157,14 +259,55 @@ func TestSchemaShimRepresentations(t *testing.T) { | |||
| }`), | ||||
| }, | ||||
| { | ||||
| "object-attribute", | ||||
| "single-nested-attribute", | ||||
| &pb.Provider{ | ||||
| AllResources: []pb.Resource{ | ||||
| { | ||||
| ResourceSchema: schema.Schema{ | ||||
| Attributes: map[string]schema.Attribute{ | ||||
| "single_nested_attribute": schema.SingleNestedAttribute{ | ||||
| Optional: true, | ||||
| Attributes: map[string]schema.Attribute{ | ||||
| "a1": schema.StringAttribute{ | ||||
| Optional: true, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| autogold.Expect(`{ | ||||
| "resources": { | ||||
| "_": { | ||||
| "single_nested_attribute": { | ||||
| "element": { | ||||
| "resource": { | ||||
| "a1": { | ||||
| "optional": true, | ||||
| "type": 4 | ||||
| } | ||||
| } | ||||
| }, | ||||
| "optional": true, | ||||
| "type": 6 | ||||
| } | ||||
| } | ||||
| } | ||||
| }`), | ||||
| }, | ||||
| { | ||||
| "single-nested-block", | ||||
| &pb.Provider{ | ||||
| AllResources: []pb.Resource{{ | ||||
| ResourceSchema: schema.Schema{ | ||||
| Attributes: map[string]schema.Attribute{ | ||||
| "object_attribute": schema.ObjectAttribute{ | ||||
| AttributeTypes: map[string]attr.Type{ | ||||
| "a1": types.StringType, | ||||
| Blocks: map[string]schema.Block{ | ||||
| "single_nested_block": schema.SingleNestedBlock{ | ||||
| Attributes: map[string]schema.Attribute{ | ||||
| "a1": schema.StringAttribute{ | ||||
| Optional: true, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
|
|
@@ -174,18 +317,59 @@ func TestSchemaShimRepresentations(t *testing.T) { | |||
| autogold.Expect(`{ | ||||
| "resources": { | ||||
| "_": { | ||||
| "object_attribute": { | ||||
| "single_nested_block": { | ||||
| "element": { | ||||
| "resource": { | ||||
| "a1": { | ||||
| "optional": true, | ||||
| "type": 4 | ||||
| } | ||||
| } | ||||
| }, | ||||
| "optional": true, | ||||
| "type": 6 | ||||
| } | ||||
| } | ||||
| } | ||||
| }`), | ||||
| }, | ||||
| { | ||||
| "list-nested-block", | ||||
| &pb.Provider{ | ||||
| AllResources: []pb.Resource{{ | ||||
| ResourceSchema: schema.Schema{ | ||||
| Blocks: map[string]schema.Block{ | ||||
| "list_nested_block": schema.ListNestedBlock{ | ||||
| NestedObject: schema.NestedBlockObject{ | ||||
| Attributes: map[string]schema.Attribute{ | ||||
| "a1": schema.StringAttribute{ | ||||
| Optional: true, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| }}, | ||||
| }, | ||||
| // TODO: Why is this different to list-nested-attribute? Should it be? | ||||
| autogold.Expect(`{ | ||||
| "resources": { | ||||
| "_": { | ||||
| "list_nested_block": { | ||||
| "element": { | ||||
| "resource": { | ||||
| "a1": { | ||||
| "optional": true, | ||||
| "type": 4 | ||||
| } | ||||
| } | ||||
| }, | ||||
| "optional": true, | ||||
| "type": 5 | ||||
|
Contributor
Author
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. Note this is a list type - this means that the CastToTypeObject
Member
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. Is this out of date? |
||||
| } | ||||
| } | ||||
| } | ||||
| }`), | ||||
| }, | ||||
| } | ||||
|
|
||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this expected? I wonder why the list-nested-attribute has 2 more layers of nesting in the shim layer.
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.
Ah, this is probably
elemSchemaspulumi-terraform-bridge/pkg/tfbridge/schema.go
Line 268 in c9ce9b5
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.
Or not,
elemSchemasis called after the shim schema is constructed.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.
Found it in
pulumi-terraform-bridge/pf/internal/schemashim/attr_schema.go
Line 85 in 18db7c5
vs blocks:
pulumi-terraform-bridge/pf/internal/schemashim/block_schema.go
Line 56 in 18db7c5
Trying to see what happens if attr shims match the block ones here: #2232
Uh oh!
There was an error while loading. Please reload this page.
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.
Explored further in #2232, seems plausible that these should actually match and the attribute one seems wrong here. Wondering how this affects
schema.goThere 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.
Did you reach a conclusion here?