Skip to content

Commit 3d24dfc

Browse files
update tests and wip
1 parent a97b811 commit 3d24dfc

File tree

7 files changed

+177
-129
lines changed

7 files changed

+177
-129
lines changed

internal/testprovider/schema_nested_fully_computed.go

Lines changed: 0 additions & 76 deletions
This file was deleted.

pkg/tests/schema_test.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package tests
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"io"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
"github.com/hexops/autogold/v2"
11+
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/tests/pulcheck"
12+
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen"
13+
pschema "github.com/pulumi/pulumi/pkg/v3/codegen/schema"
14+
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
15+
"github.com/pulumi/pulumi/sdk/v3/go/common/diag/colors"
16+
"github.com/stretchr/testify/assert"
17+
"github.com/stretchr/testify/require"
18+
)
19+
20+
func TestNestedFullyComputed(t *testing.T) {
21+
t.Parallel()
22+
p := &schema.Provider{
23+
Schema: map[string]*schema.Schema{},
24+
ResourcesMap: map[string]*schema.Resource{
25+
"testprovider_res": {
26+
Schema: map[string]*schema.Schema{
27+
"list_block": {
28+
Type: schema.TypeList,
29+
Required: true,
30+
Elem: &schema.Resource{
31+
Schema: map[string]*schema.Schema{
32+
"a1": {
33+
Type: schema.TypeString,
34+
Computed: true,
35+
},
36+
"a2": {
37+
Type: schema.TypeString,
38+
Optional: true,
39+
},
40+
"a3": {
41+
Type: schema.TypeString,
42+
Required: true,
43+
},
44+
},
45+
},
46+
},
47+
"object_block": {
48+
Type: schema.TypeList,
49+
Optional: true,
50+
MaxItems: 1,
51+
Elem: &schema.Resource{
52+
Schema: map[string]*schema.Schema{
53+
"b1": {
54+
Type: schema.TypeString,
55+
Computed: true,
56+
},
57+
"b2": {
58+
Type: schema.TypeString,
59+
Optional: true,
60+
},
61+
"b3": {
62+
Type: schema.TypeString,
63+
Required: true,
64+
},
65+
},
66+
},
67+
},
68+
},
69+
},
70+
},
71+
}
72+
73+
info := pulcheck.BridgedProvider(t, "testprovider", p)
74+
75+
schema, err := tfgen.GenerateSchema(info, diag.DefaultSink(io.Discard, io.Discard, diag.FormatOptions{
76+
Color: colors.Never,
77+
}))
78+
require.NoError(t, err)
79+
80+
marshal := func(s pschema.PackageSpec, w io.Writer) error {
81+
enc := json.NewEncoder(w)
82+
enc.SetIndent("", " ")
83+
return enc.Encode(s)
84+
}
85+
86+
toString := func(s pschema.PackageSpec) string {
87+
buf := bytes.Buffer{}
88+
err := marshal(s, &buf)
89+
assert.NoError(t, err)
90+
return buf.String()
91+
}
92+
93+
autogold.ExpectFile(t, autogold.Raw(toString(schema)))
94+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"name": "testprovider",
3+
"version": "0.0.1",
4+
"attribution": "This Pulumi package is based on the [`testprovider` Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider).",
5+
"meta": {
6+
"moduleFormat": "(.*)(?:/[^/]*)"
7+
},
8+
"language": {
9+
"nodejs": {
10+
"readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider)\n\u003e distributed under [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/). If you encounter a bug or missing feature,\n\u003e please consult the source [`terraform-provider-testprovider` repo](https://github.com/terraform-providers/terraform-provider-testprovider/issues).",
11+
"compatibility": "tfbridge20",
12+
"disableUnionOutputTypes": true
13+
},
14+
"python": {
15+
"readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider)\n\u003e distributed under [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/). If you encounter a bug or missing feature,\n\u003e please consult the source [`terraform-provider-testprovider` repo](https://github.com/terraform-providers/terraform-provider-testprovider/issues).",
16+
"compatibility": "tfbridge20",
17+
"pyproject": {}
18+
}
19+
},
20+
"config": {},
21+
"types": {
22+
"testprovider:index/ResListBlock:ResListBlock": {
23+
"properties": {
24+
"a2": {
25+
"type": "string"
26+
}
27+
},
28+
"type": "object",
29+
"language": {
30+
"nodejs": {
31+
"requiredOutputs": [
32+
"a1"
33+
]
34+
}
35+
}
36+
}
37+
},
38+
"provider": {
39+
"description": "The provider type for the testprovider package. By default, resources use package-wide configuration\nsettings, however an explicit `Provider` instance may be created and passed during resource\nconstruction to achieve fine-grained programmatic control over provider settings. See the\n[documentation](https://www.pulumi.com/docs/reference/programming-model/#providers) for more information.\n"
40+
},
41+
"resources": {
42+
"testprovider:index/res:Res": {
43+
"properties": {
44+
"listBlocks": {
45+
"type": "array",
46+
"items": {
47+
"$ref": "#/types/testprovider:index/ResListBlock:ResListBlock"
48+
}
49+
}
50+
},
51+
"required": [
52+
"listBlocks"
53+
],
54+
"inputProperties": {
55+
"listBlocks": {
56+
"type": "array",
57+
"items": {
58+
"$ref": "#/types/testprovider:index/ResListBlock:ResListBlock"
59+
}
60+
}
61+
},
62+
"requiredInputs": [
63+
"listBlocks"
64+
],
65+
"stateInputs": {
66+
"description": "Input properties used for looking up and filtering Res resources.\n",
67+
"properties": {
68+
"listBlocks": {
69+
"type": "array",
70+
"items": {
71+
"$ref": "#/types/testprovider:index/ResListBlock:ResListBlock"
72+
}
73+
}
74+
},
75+
"type": "object"
76+
}
77+
}
78+
}
79+
}

pkg/tfgen/generate.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,10 @@ func (g *Generator) propertyVariable(parentPath paths.TypePath, key string,
17981798
varInfo = info[key]
17991799
}
18001800

1801+
if !input(shimSchema, varInfo) && !out {
1802+
return nil, nil
1803+
}
1804+
18011805
// If a variable is marked as omitted, omit it.
18021806
//
18031807
// Because the recursive traversal into the fields used by this type are

pkg/tfgen/generate_schema.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ func (nt *schemaNestedTypes) declareType(typePath paths.TypePath, declarer decla
136136
typeName = typ.nestedType.Name().String()
137137
}
138138

139-
if !isInput {
140-
typeName += "Output"
141-
}
142139

143140
typ.name = typeName
144141

@@ -1101,9 +1098,6 @@ func (g *schemaGenerator) schemaType(path paths.TypePath, typ *propertyType, out
11011098
case kindObject:
11021099
mod := modulePlacementForType(g.pkg, path)
11031100
ref := fmt.Sprintf("#/types/%s/%s:%s", mod.String(), typ.name, typ.name)
1104-
if out {
1105-
ref += "Output"
1106-
}
11071101
return pschema.TypeSpec{Ref: ref}
11081102
default:
11091103
contract.Failf("Unrecognized type kind: %v", typ.kind)

pkg/tfgen/generate_schema_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -449,16 +449,6 @@ func TestRequiredInputWithDefault(t *testing.T) {
449449
bridgetesting.AssertEqualsJSONFile(t, "test_data/required-input-with-default-schema.json", schema)
450450
}
451451

452-
func TestNestedFullyComputed(t *testing.T) {
453-
t.Parallel()
454-
provider := testprovider.ProviderNestedFullyComputed()
455-
schema, err := GenerateSchema(provider, diag.DefaultSink(io.Discard, io.Discard, diag.FormatOptions{
456-
Color: colors.Never,
457-
}))
458-
require.NoError(t, err)
459-
bridgetesting.AssertEqualsJSONFile(t, "test_data/nested-fully-computed-schema.json", schema)
460-
}
461-
462452
func TestAppendExample_InsertMiddle(t *testing.T) {
463453
t.Parallel()
464454
descTmpl := `Description text

pkg/tfgen/internal/testprovider/nestedfullycomputed.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)