pulumi/pkg/codegen/internal/test/testdata/plain-object-defaults/go/example/mod1/pulumiTypes.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

168 lines
3.9 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 mod1
import (
"context"
"reflect"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// A test for namespaces (mod 1)
type Typ struct {
Val *string `pulumi:"val"`
}
// Defaults sets the appropriate defaults for Typ
func (val *Typ) Defaults() *Typ {
if val == nil {
return nil
}
tmp := *val
if isZero(tmp.Val) {
val_ := getEnvOrDefault("mod1", nil, "PULUMI_EXAMPLE_MOD1_DEFAULT").(string)
tmp.Val = &val_
}
return &tmp
}
// TypInput is an input type that accepts TypArgs and TypOutput values.
// You can construct a concrete instance of `TypInput` via:
//
// TypArgs{...}
type TypInput interface {
pulumi.Input
ToTypOutput() TypOutput
ToTypOutputWithContext(context.Context) TypOutput
}
// A test for namespaces (mod 1)
type TypArgs struct {
Val pulumi.StringPtrInput `pulumi:"val"`
}
func (TypArgs) ElementType() reflect.Type {
return reflect.TypeOf((*Typ)(nil)).Elem()
}
func (i TypArgs) ToTypOutput() TypOutput {
return i.ToTypOutputWithContext(context.Background())
}
func (i TypArgs) ToTypOutputWithContext(ctx context.Context) TypOutput {
return pulumi.ToOutputWithContext(ctx, i).(TypOutput)
}
func (i TypArgs) ToTypPtrOutput() TypPtrOutput {
return i.ToTypPtrOutputWithContext(context.Background())
}
func (i TypArgs) ToTypPtrOutputWithContext(ctx context.Context) TypPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(TypOutput).ToTypPtrOutputWithContext(ctx)
}
// TypPtrInput is an input type that accepts TypArgs, TypPtr and TypPtrOutput values.
// You can construct a concrete instance of `TypPtrInput` via:
//
// TypArgs{...}
//
// or:
//
// nil
type TypPtrInput interface {
pulumi.Input
ToTypPtrOutput() TypPtrOutput
ToTypPtrOutputWithContext(context.Context) TypPtrOutput
}
type typPtrType TypArgs
func TypPtr(v *TypArgs) TypPtrInput {
return (*typPtrType)(v)
}
func (*typPtrType) ElementType() reflect.Type {
return reflect.TypeOf((**Typ)(nil)).Elem()
}
func (i *typPtrType) ToTypPtrOutput() TypPtrOutput {
return i.ToTypPtrOutputWithContext(context.Background())
}
func (i *typPtrType) ToTypPtrOutputWithContext(ctx context.Context) TypPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(TypPtrOutput)
}
// A test for namespaces (mod 1)
type TypOutput struct{ *pulumi.OutputState }
func (TypOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Typ)(nil)).Elem()
}
func (o TypOutput) ToTypOutput() TypOutput {
return o
}
func (o TypOutput) ToTypOutputWithContext(ctx context.Context) TypOutput {
return o
}
func (o TypOutput) ToTypPtrOutput() TypPtrOutput {
return o.ToTypPtrOutputWithContext(context.Background())
}
func (o TypOutput) ToTypPtrOutputWithContext(ctx context.Context) TypPtrOutput {
return o.ApplyTWithContext(ctx, func(_ context.Context, v Typ) *Typ {
return &v
}).(TypPtrOutput)
}
func (o TypOutput) Val() pulumi.StringPtrOutput {
return o.ApplyT(func(v Typ) *string { return v.Val }).(pulumi.StringPtrOutput)
}
type TypPtrOutput struct{ *pulumi.OutputState }
func (TypPtrOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Typ)(nil)).Elem()
}
func (o TypPtrOutput) ToTypPtrOutput() TypPtrOutput {
return o
}
func (o TypPtrOutput) ToTypPtrOutputWithContext(ctx context.Context) TypPtrOutput {
return o
}
func (o TypPtrOutput) Elem() TypOutput {
return o.ApplyT(func(v *Typ) Typ {
if v != nil {
return *v
}
var ret Typ
return ret
}).(TypOutput)
}
func (o TypPtrOutput) Val() pulumi.StringPtrOutput {
return o.ApplyT(func(v *Typ) *string {
if v == nil {
return nil
}
return v.Val
}).(pulumi.StringPtrOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*TypInput)(nil)).Elem(), TypArgs{})
pulumi.RegisterInputType(reflect.TypeOf((*TypPtrInput)(nil)).Elem(), TypArgs{})
pulumi.RegisterOutputType(TypOutput{})
pulumi.RegisterOutputType(TypPtrOutput{})
}