From 39251cf162e9b391bb3156f671b8ff43195eec3c Mon Sep 17 00:00:00 2001 From: Venelin Date: Mon, 22 Jul 2024 17:19:02 +0300 Subject: [PATCH 1/6] pf extract inputs from outputs tests --- pf/tests/extract_inputs_test.go | 421 ++++++++++++++++++++++++++++++++ 1 file changed, 421 insertions(+) create mode 100644 pf/tests/extract_inputs_test.go diff --git a/pf/tests/extract_inputs_test.go b/pf/tests/extract_inputs_test.go new file mode 100644 index 000000000..5ddc4f9d5 --- /dev/null +++ b/pf/tests/extract_inputs_test.go @@ -0,0 +1,421 @@ +package tfbridgetests + +import ( + "context" + "testing" + + "github.com/hashicorp/terraform-plugin-framework/attr" + rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listdefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hexops/autogold/v2" + "github.com/pulumi/pulumi-terraform-bridge/pf/internal/schemashim" + pb "github.com/pulumi/pulumi-terraform-bridge/pf/tests/internal/providerbuilder" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi/sdk/v3/go/common/resource" + "github.com/stretchr/testify/require" +) + +func TestExtractInputsFromOutputsPF(t *testing.T) { + type testCase struct { + name string + props resource.PropertyMap + resSchema rschema.Schema + expect autogold.Value + } + + testCases := []testCase{ + { + name: "string", + props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": "bar"}), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.StringAttribute{Optional: true}, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: "bar"}, + }), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for foo in the inputs. + { + name: "string with default", + props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": "bar"}), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.StringAttribute{Optional: true, Default: stringdefault.StaticString("bar")}, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: "bar"}, + }), + }, + { + name: "string with empty value", + props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": ""}), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.StringAttribute{Optional: true}, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, + { + name: "string computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": "bar"}), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.StringAttribute{Computed: true}, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, + { + name: "list attribute", + props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": []interface{}{"bar"}}), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ListAttribute{ + Optional: true, + ElementType: types.StringType, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: "bar", + }}}, + }), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for foo in the inputs. + { + name: "list attribute with default", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": []interface{}{"bar"}, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ListAttribute{ + Optional: true, + ElementType: types.StringType, + Default: listdefault.StaticValue(types.ListValueMust(types.StringType, []attr.Value{types.StringValue("bar")})), + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: "bar", + }}}, + }), + }, + { + name: "list attribute computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": []interface{}{"bar"}, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ListAttribute{ + ElementType: types.StringType, + Computed: true, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, + { + name: "list nested attribute", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": []interface{}{ + map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ListNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }, + }}}, + }), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for foo in the inputs. + { + name: "list nested attribute with defaults", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": []interface{}{ + map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ListNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + Default: listdefault.StaticValue(types.ListValueMust(types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "bar": types.StringType, + }, + }, []attr.Value{types.ObjectValueMust( + map[string]attr.Type{ + "bar": types.StringType, + }, + map[string]attr.Value{ + "bar": types.StringValue("baz"), + }, + )})), + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }, + }}}, + }), + }, + { + name: "list nested attribute computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": []interface{}{ + map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ListNestedAttribute{ + Computed: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, + { + name: "list nested attribute nested computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": []interface{}{ + map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ListNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Computed: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}, + }}}, + }), + }, + { + name: "set nested attribute", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": []interface{}{ + map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.SetNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }, + }}}, + }), + }, + { + name: "map nested attribute", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "bar": "baz", + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.MapNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }}, + }), + }, + { + name: "object attribute", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "bar": "baz", + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ObjectAttribute{ + Optional: true, + AttributeTypes: map[string]attr.Type{ + "bar": types.StringType, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, + { + name: "single nested attribute", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "bar": "baz", + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.SingleNestedAttribute{ + Optional: true, + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }}, + }), + }, + // BLOCKS + // { + // name: "list nested block", + // }, + // { + // name: "set nested block", + // }, + // { + // name: "single nested block", + // }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + prov := &pb.Provider{ + AllResources: []pb.Resource{ + { + Name: "test", + ResourceSchema: tc.resSchema, + }, + }, + } + + shimmedProvider := schemashim.ShimSchemaOnlyProvider(context.Background(), prov) + res := shimmedProvider.ResourcesMap().Get("_test") + result, err := tfbridge.ExtractInputsFromOutputs(nil, tc.props, res.Schema(), nil, false) + require.NoError(t, err) + tc.expect.Equal(t, result) + }) + } +} From b5ce289cf831c70de05404476671a37eba9db136 Mon Sep 17 00:00:00 2001 From: Venelin Date: Mon, 22 Jul 2024 17:35:49 +0300 Subject: [PATCH 2/6] map tests --- pf/tests/extract_inputs_test.go | 192 +++++++++++++++++++++++++++++++- 1 file changed, 188 insertions(+), 4 deletions(-) diff --git a/pf/tests/extract_inputs_test.go b/pf/tests/extract_inputs_test.go index 5ddc4f9d5..61f2cdf66 100644 --- a/pf/tests/extract_inputs_test.go +++ b/pf/tests/extract_inputs_test.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/attr" rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/listdefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/mapdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hexops/autogold/v2" @@ -101,7 +102,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}}, }), }, - // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for foo in the inputs. + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. { name: "list attribute with default", props: resource.NewPropertyMapFromMap(map[string]interface{}{ @@ -175,7 +176,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}}, }), }, - // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for foo in the inputs. + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. { name: "list nested attribute with defaults", props: resource.NewPropertyMapFromMap(map[string]interface{}{ @@ -221,6 +222,40 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}}, }), }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. + { + name: "list nested attribute with nested defaults", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": []interface{}{ + map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ListNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true, Default: stringdefault.StaticString("baz")}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }, + }}}, + }), + }, { name: "list nested attribute computed", props: resource.NewPropertyMapFromMap(map[string]interface{}{ @@ -311,7 +346,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { name: "map nested attribute", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ - "bar": "baz", + "key1": map[string]interface{}{"bar": "baz"}, }, }), resSchema: rschema.Schema{ @@ -334,7 +369,156 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + resource.PropertyKey("key1"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }}, + }}, + }), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. + { + name: "map nested attribute with default", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "key1": map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.MapNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + Default: mapdefault.StaticValue(types.MapValueMust( + types.ObjectType{ + AttrTypes: map[string]attr.Type{"bar": types.StringType}, + }, map[string]attr.Value{ + "key1": types.ObjectValueMust( + map[string]attr.Type{ + "bar": types.StringType, + }, + map[string]attr.Value{ + "bar": types.StringValue("baz"), + }, + ), + }, + )), + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("key1"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }}, + }}, + }), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. + { + name: "map nested attribute with nested default", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "key1": map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.MapNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true, Default: stringdefault.StaticString("baz")}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("key1"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + }}, + }}, + }), + }, + { + name: "map nested attribute computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "key1": map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.MapNestedAttribute{ + Computed: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, + { + name: "map nested attribute nested computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "key1": map[string]interface{}{"bar": "baz"}, + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.MapNestedAttribute{ + Optional: true, + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Computed: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("foo"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("key1"): resource.PropertyValue{V: resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}}, }}, }), }, From e40f6a0f99f41171c612cf62e92e8182b2e4dcff Mon Sep 17 00:00:00 2001 From: Venelin Date: Mon, 22 Jul 2024 17:40:39 +0300 Subject: [PATCH 3/6] more tests --- pf/tests/extract_inputs_test.go | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/pf/tests/extract_inputs_test.go b/pf/tests/extract_inputs_test.go index 61f2cdf66..34dcae222 100644 --- a/pf/tests/extract_inputs_test.go +++ b/pf/tests/extract_inputs_test.go @@ -543,6 +543,27 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { V: []resource.PropertyValue{}, }}), }, + { + name: "object attribute computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "bar": "baz", + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.ObjectAttribute{ + Computed: true, + AttributeTypes: map[string]attr.Type{ + "bar": types.StringType, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, { name: "single nested attribute", props: resource.NewPropertyMapFromMap(map[string]interface{}{ @@ -572,6 +593,49 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}, }), }, + { + name: "single nested attribute computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "bar": "baz", + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.SingleNestedAttribute{ + Computed: true, + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, + { + name: "single nested attribute nested computed", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "foo": map[string]interface{}{ + "bar": "baz", + }, + }), + resSchema: rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "foo": rschema.SingleNestedAttribute{ + Optional: true, + Attributes: map[string]rschema.Attribute{ + "bar": rschema.StringAttribute{Computed: true}, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: Add default tests here. // BLOCKS // { // name: "list nested block", From 4a59ef9afd43ead1d4694ee50b65488ce1c27ee7 Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 23 Jul 2024 11:41:37 +0300 Subject: [PATCH 4/6] rename tests, add block tests --- pf/tests/extract_inputs_test.go | 335 ++++++++++++++++++++++++++++---- 1 file changed, 296 insertions(+), 39 deletions(-) diff --git a/pf/tests/extract_inputs_test.go b/pf/tests/extract_inputs_test.go index 34dcae222..fda5368a9 100644 --- a/pf/tests/extract_inputs_test.go +++ b/pf/tests/extract_inputs_test.go @@ -27,8 +27,9 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { } testCases := []testCase{ + // ATTRIBUTES { - name: "string", + name: "string extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": "bar"}), resSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ @@ -44,7 +45,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }, // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for foo in the inputs. { - name: "string with default", + name: "string with default not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": "bar"}), resSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ @@ -55,11 +56,11 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("foo"): resource.PropertyValue{V: "bar"}, + resource.PropertyKey("foo"): resource.PropertyValue{V: "bar"}, // wrong }), }, { - name: "string with empty value", + name: "string with empty value not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": ""}), resSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ @@ -71,7 +72,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}), }, { - name: "string computed", + name: "string computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": "bar"}), resSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ @@ -83,7 +84,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}), }, { - name: "list attribute", + name: "list attribute extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{"foo": []interface{}{"bar"}}), resSchema: rschema.Schema{ Attributes: map[string]rschema.Attribute{ @@ -104,7 +105,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }, // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. { - name: "list attribute with default", + name: "list attribute with default not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": []interface{}{"bar"}, }), @@ -122,12 +123,12 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { V: []resource.PropertyValue{}, }, resource.PropertyKey("foo"): resource.PropertyValue{V: []resource.PropertyValue{{ - V: "bar", + V: "bar", // wrong }}}, }), }, { - name: "list attribute computed", + name: "list attribute computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": []interface{}{"bar"}, }), @@ -144,7 +145,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}), }, { - name: "list nested attribute", + name: "list nested attribute extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": []interface{}{ map[string]interface{}{"bar": "baz"}, @@ -178,7 +179,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }, // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. { - name: "list nested attribute with defaults", + name: "list nested attribute with defaults not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": []interface{}{ map[string]interface{}{"bar": "baz"}, @@ -217,14 +218,14 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, // wrong }, }}}, }), }, // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. { - name: "list nested attribute with nested defaults", + name: "list nested attribute with nested defaults not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": []interface{}{ map[string]interface{}{"bar": "baz"}, @@ -251,13 +252,13 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, // wrong }, }}}, }), }, { - name: "list nested attribute computed", + name: "list nested attribute computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": []interface{}{ map[string]interface{}{"bar": "baz"}, @@ -280,7 +281,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}), }, { - name: "list nested attribute nested computed", + name: "list nested attribute nested computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": []interface{}{ map[string]interface{}{"bar": "baz"}, @@ -310,7 +311,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }), }, { - name: "set nested attribute", + name: "set nested attribute extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": []interface{}{ map[string]interface{}{"bar": "baz"}, @@ -343,7 +344,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }), }, { - name: "map nested attribute", + name: "map nested attribute extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "key1": map[string]interface{}{"bar": "baz"}, @@ -380,7 +381,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }, // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. { - name: "map nested attribute with default", + name: "map nested attribute with default not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "key1": map[string]interface{}{"bar": "baz"}, @@ -404,7 +405,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { "bar": types.StringType, }, map[string]attr.Value{ - "bar": types.StringValue("baz"), + "bar": types.StringValue("baz"), // wrong }, ), }, @@ -431,7 +432,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }, // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. { - name: "map nested attribute with nested default", + name: "map nested attribute with nested default not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "key1": map[string]interface{}{"bar": "baz"}, @@ -461,13 +462,13 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, + resource.PropertyKey("bar"): resource.PropertyValue{V: "baz"}, // wrong }}, }}, }), }, { - name: "map nested attribute computed", + name: "map nested attribute computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "key1": map[string]interface{}{"bar": "baz"}, @@ -490,7 +491,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}), }, { - name: "map nested attribute nested computed", + name: "map nested attribute nested computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "key1": map[string]interface{}{"bar": "baz"}, @@ -523,7 +524,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }), }, { - name: "object attribute", + name: "object attribute extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "bar": "baz", @@ -544,7 +545,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}), }, { - name: "object attribute computed", + name: "object attribute computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "bar": "baz", @@ -565,7 +566,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}), }, { - name: "single nested attribute", + name: "single nested attribute extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "bar": "baz", @@ -594,7 +595,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }), }, { - name: "single nested attribute computed", + name: "single nested attribute computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "bar": "baz", @@ -615,7 +616,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}), }, { - name: "single nested attribute nested computed", + name: "single nested attribute nested computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "foo": map[string]interface{}{ "bar": "baz", @@ -635,17 +636,273 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { V: []resource.PropertyValue{}, }}), }, - // TODO[pulumi/pulumi-terraform-bridge#2218]: Add default tests here. + // TODO[pulumi/pulumi-terraform-bridge#2218]: Add missing defaults tests here once defaults are fixed. // BLOCKS - // { - // name: "list nested block", - // }, - // { - // name: "set nested block", - // }, - // { - // name: "single nested block", - // }, + { + name: "list nested block not extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": []interface{}{ + map[string]interface{}{"nested_field": "nested_value"}, + }, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.ListNestedBlock{ + NestedObject: rschema.NestedBlockObject{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("block_field"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + }, + }}}, + }), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. + { + name: "list nested block with defaults not extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": []interface{}{ + map[string]interface{}{"nested_field": "nested_value"}, + }, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.ListNestedBlock{ + NestedObject: rschema.NestedBlockObject{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Optional: true, Default: stringdefault.StaticString("nested_value")}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("block_field"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + }, + }}}, + }), + }, + { + name: "list nested block computed not extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": []interface{}{ + map[string]interface{}{"nested_field": "nested_value"}, + }, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.ListNestedBlock{ + NestedObject: rschema.NestedBlockObject{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Computed: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("block_field"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + }, + }}}, + }), + }, + { + name: "set nested block extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": []interface{}{ + map[string]interface{}{"nested_field": "nested_value"}, + }, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.SetNestedBlock{ + NestedObject: rschema.NestedBlockObject{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("block_field"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + }, + }}}, + }), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. + { + name: "set nested block with defaults not extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": []interface{}{ + map[string]interface{}{"nested_field": "nested_value"}, + }, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.SetNestedBlock{ + NestedObject: rschema.NestedBlockObject{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Optional: true, Default: stringdefault.StaticString("nested_value")}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("block_field"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + }, + }}}, + }), + }, + { + name: "set nested block computed not extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": []interface{}{ + map[string]interface{}{"nested_field": "nested_value"}, + }, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.SetNestedBlock{ + NestedObject: rschema.NestedBlockObject{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Computed: true}, + }, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("block_field"): resource.PropertyValue{V: []resource.PropertyValue{{ + V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + }, + }}}, + }), + }, + { + name: "single nested block extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": map[string]interface{}{"nested_field": "nested_value"}, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.SingleNestedBlock{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Optional: true}, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("block_field"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + }}, + }), + }, + // TODO[pulumi/pulumi-terraform-bridge#2218]: This should not yield values for properties with defaults in the inputs. + { + name: "single nested block with default not extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": map[string]interface{}{"nested_field": "nested_value"}, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.SingleNestedBlock{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Optional: true, Default: stringdefault.StaticString("nested_value")}, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("block_field"): resource.PropertyValue{V: resource.PropertyMap{ + resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + }}, + }), + }, + { + name: "single nested block computed not extracted", + props: resource.NewPropertyMapFromMap(map[string]interface{}{ + "block_field": map[string]interface{}{"nested_field": "nested_value"}, + }), + resSchema: rschema.Schema{ + Blocks: map[string]rschema.Block{ + "block_field": rschema.SingleNestedBlock{ + Attributes: map[string]rschema.Attribute{ + "nested_field": rschema.StringAttribute{Computed: true}, + }, + }, + }, + }, + expect: autogold.Expect(resource.PropertyMap{resource.PropertyKey("__defaults"): resource.PropertyValue{ + V: []resource.PropertyValue{}, + }}), + }, } for _, tc := range testCases { From 7fac4a1db3c97e0d4a65741971fca993d66a58a8 Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 23 Jul 2024 12:20:03 +0300 Subject: [PATCH 5/6] add more todos --- pf/tests/extract_inputs_test.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pf/tests/extract_inputs_test.go b/pf/tests/extract_inputs_test.go index fda5368a9..cd6a4ffad 100644 --- a/pf/tests/extract_inputs_test.go +++ b/pf/tests/extract_inputs_test.go @@ -638,6 +638,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }, // TODO[pulumi/pulumi-terraform-bridge#2218]: Add missing defaults tests here once defaults are fixed. // BLOCKS + // TODO[pulumi/pulumi-terraform-bridge#2180]: This should not yield values for computed properties { name: "list nested block not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ @@ -665,7 +666,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, // wrong }, }}}, }), @@ -698,11 +699,12 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, // wrong }, }}}, }), }, + // TODO[pulumi/pulumi-terraform-bridge#2180]: This should not yield values for computed properties { name: "list nested block computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ @@ -730,7 +732,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, // wrong }, }}}, }), @@ -795,7 +797,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, // wrong }, }}}, }), @@ -881,7 +883,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, // wrong }}, }), }, From f07cf0cf9420a92f64024a34d468359ce18e0ee1 Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 23 Jul 2024 12:23:47 +0300 Subject: [PATCH 6/6] fix todos --- pf/tests/extract_inputs_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pf/tests/extract_inputs_test.go b/pf/tests/extract_inputs_test.go index cd6a4ffad..c514a0423 100644 --- a/pf/tests/extract_inputs_test.go +++ b/pf/tests/extract_inputs_test.go @@ -638,9 +638,8 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }, // TODO[pulumi/pulumi-terraform-bridge#2218]: Add missing defaults tests here once defaults are fixed. // BLOCKS - // TODO[pulumi/pulumi-terraform-bridge#2180]: This should not yield values for computed properties { - name: "list nested block not extracted", + name: "list nested block extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ "block_field": []interface{}{ map[string]interface{}{"nested_field": "nested_value"}, @@ -666,7 +665,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, // wrong + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, }, }}}, }), @@ -802,6 +801,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { }}}, }), }, + // TODO[pulumi/pulumi-terraform-bridge#2180]: This should not yield values for computed properties { name: "set nested block computed not extracted", props: resource.NewPropertyMapFromMap(map[string]interface{}{ @@ -829,7 +829,7 @@ func TestExtractInputsFromOutputsPF(t *testing.T) { resource.PropertyKey("__defaults"): resource.PropertyValue{ V: []resource.PropertyValue{}, }, - resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, + resource.PropertyKey("nested_field"): resource.PropertyValue{V: "nested_value"}, //wrong }, }}}, }),