pulumi/pkg/codegen/internal/test/testdata/dashed-import-schema/go/plant-provider/tree/v1/rubberTree.go
Ian Wahbe 4b7985384c
[codegen/go] Call site defaults for Pulumi Object types (#8411)
* Add test case

* Fix tests

* Add test dependencies correctly

* Feed through error handling

* Include test output

* Get types to line up

* Add remaining test files

* Update changelog

* Correctly find type paths

* Handle transitive objects

* Handle required fields

* Add feature flag for go

* Add required+default test case

* Don't `<any>` cast known types.

* Add more flags.

I realize this should really wait for PR#8400 to merge.

* Add plain object to env-helper test

This test fails right now. My next problem is fixing it.

* Handle plain types

* Handle function inputs

* Fix the indentation

* Handle output types correctly

* Remove unnecessary `!`

* Add test case

* Fix tests

* Add test dependencies correctly

* Feed through error handling

* Include test output

* Get types to line up

* Add remaining test files

* Update changelog

* Correctly find type paths

* Handle transitive objects

* Handle required fields

* Add required+default test case

* Don't `<any>` cast known types.

* Add plain object to env-helper test

This test fails right now. My next problem is fixing it.

* Handle plain types

* Handle function inputs

* Fix the indentation

* Handle output types correctly

* Remove unnecessary `!`

* Start on `genPlainObjectDefaultFunc`

* Add missing change to fix test

* Run tests with merge

* Refactor out assign

* Merge in next _index.md diff

* Change method name to `Defaults`

* Handle enums correctly

* Another attempt at _index.md

* Make module generation deterministic

* Add checks for old values

* Insert defaults in resources

* Fix docs generation

Credit to @praneetloke

* Progress on adding defaults to Resource arguments

* Handle resource argument defaults

* Don't create defaults if disableObjectDefaults

* Rename test folder

* Add test for disable flag

* Fix disable test

* Update docs

* Abstract out nil comparisons

* Use reflection to test for empty values

* Simplify Ptr and pulumi.Any type handling

* Remove unused function

* Apply defaults to functions

* Update new test with master codegen

* Tests + nil check
2021-11-23 15:10:15 -08:00

139 lines
4.1 KiB
Go

// *** WARNING: this file was generated by test. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
package v1
import (
"context"
"reflect"
"dashed-import-schema/plant-provider"
"github.com/pkg/errors"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
type RubberTree struct {
pulumi.CustomResourceState
Container plantprovider.ContainerPtrOutput `pulumi:"container"`
Diameter DiameterOutput `pulumi:"diameter"`
Farm pulumi.StringPtrOutput `pulumi:"farm"`
Size TreeSizePtrOutput `pulumi:"size"`
Type RubberTreeVarietyOutput `pulumi:"type"`
}
// NewRubberTree registers a new resource with the given unique name, arguments, and options.
func NewRubberTree(ctx *pulumi.Context,
name string, args *RubberTreeArgs, opts ...pulumi.ResourceOption) (*RubberTree, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
containerApplier := func(v plantprovider.Container) *plantprovider.Container { return v.Defaults() }
if args.Container != nil {
args.Container = args.Container.ToContainerPtrOutput().Elem().ApplyT(containerApplier).(plantprovider.ContainerPtrOutput)
}
if isZero(args.Diameter) {
args.Diameter = Diameter(6.0)
}
if isZero(args.Farm) {
args.Farm = pulumi.StringPtr("(unknown)")
}
if isZero(args.Size) {
args.Size = TreeSize("medium")
}
if isZero(args.Type) {
args.Type = RubberTreeVariety("Burgundy")
}
var resource RubberTree
err := ctx.RegisterResource("plant:tree/v1:RubberTree", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetRubberTree gets an existing RubberTree resource's state with the given name, ID, and optional
// state properties that are used to uniquely qualify the lookup (nil if not required).
func GetRubberTree(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *RubberTreeState, opts ...pulumi.ResourceOption) (*RubberTree, error) {
var resource RubberTree
err := ctx.ReadResource("plant:tree/v1:RubberTree", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering RubberTree resources.
type rubberTreeState struct {
Farm *string `pulumi:"farm"`
}
type RubberTreeState struct {
Farm pulumi.StringPtrInput
}
func (RubberTreeState) ElementType() reflect.Type {
return reflect.TypeOf((*rubberTreeState)(nil)).Elem()
}
type rubberTreeArgs struct {
Container *plantprovider.Container `pulumi:"container"`
Diameter Diameter `pulumi:"diameter"`
Farm *string `pulumi:"farm"`
Size *TreeSize `pulumi:"size"`
Type RubberTreeVariety `pulumi:"type"`
}
// The set of arguments for constructing a RubberTree resource.
type RubberTreeArgs struct {
Container plantprovider.ContainerPtrInput
Diameter DiameterInput
Farm pulumi.StringPtrInput
Size TreeSizePtrInput
Type RubberTreeVarietyInput
}
func (RubberTreeArgs) ElementType() reflect.Type {
return reflect.TypeOf((*rubberTreeArgs)(nil)).Elem()
}
type RubberTreeInput interface {
pulumi.Input
ToRubberTreeOutput() RubberTreeOutput
ToRubberTreeOutputWithContext(ctx context.Context) RubberTreeOutput
}
func (*RubberTree) ElementType() reflect.Type {
return reflect.TypeOf((**RubberTree)(nil)).Elem()
}
func (i *RubberTree) ToRubberTreeOutput() RubberTreeOutput {
return i.ToRubberTreeOutputWithContext(context.Background())
}
func (i *RubberTree) ToRubberTreeOutputWithContext(ctx context.Context) RubberTreeOutput {
return pulumi.ToOutputWithContext(ctx, i).(RubberTreeOutput)
}
type RubberTreeOutput struct{ *pulumi.OutputState }
func (RubberTreeOutput) ElementType() reflect.Type {
return reflect.TypeOf((**RubberTree)(nil)).Elem()
}
func (o RubberTreeOutput) ToRubberTreeOutput() RubberTreeOutput {
return o
}
func (o RubberTreeOutput) ToRubberTreeOutputWithContext(ctx context.Context) RubberTreeOutput {
return o
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*RubberTreeInput)(nil)).Elem(), &RubberTree{})
pulumi.RegisterOutputType(RubberTreeOutput{})
}