pulumi/tests/integration/construct_component_methods_errors/go/component.go
Justin Van Patten ba39ed9ad4
Add tests that return failures from Call (#8424)
- [sdk/nodejs] - Allow returning failures from Call in the provider without setting result outputs.
- [sdk/go] - Allow specifying Call failures from the provider.
- Add tests that return failures from Call.
2021-11-16 08:58:46 -08:00

68 lines
1.7 KiB
Go

// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
package main
import (
"reflect"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
type Component struct {
pulumi.ResourceState
}
func NewComponent(
ctx *pulumi.Context, name string, opts ...pulumi.ResourceOption) (*Component, error) {
var resource Component
err := ctx.RegisterRemoteComponentResource("testcomponent:index:Component", name, nil, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
func (c *Component) GetMessage(ctx *pulumi.Context, args *ComponentGetMessageArgs) (ComponentGetMessageResultOutput, error) {
out, err := ctx.Call("testcomponent:index:Component/getMessage", args, ComponentGetMessageResultOutput{}, c)
if err != nil {
return ComponentGetMessageResultOutput{}, err
}
return out.(ComponentGetMessageResultOutput), nil
}
type componentGetMessageArgs struct {
Echo string `pulumi:"echo"`
}
type ComponentGetMessageArgs struct {
Echo pulumi.StringInput
}
func (ComponentGetMessageArgs) ElementType() reflect.Type {
return reflect.TypeOf((*componentGetMessageArgs)(nil)).Elem()
}
type ComponentGetMessageResult struct {
Message string `pulumi:"message"`
}
type ComponentGetMessageResultOutput struct{ *pulumi.OutputState }
func (ComponentGetMessageResultOutput) ElementType() reflect.Type {
return reflect.TypeOf((*ComponentGetMessageResult)(nil)).Elem()
}
func (o ComponentGetMessageResultOutput) Message() pulumi.StringOutput {
return o.ApplyT(func(v ComponentGetMessageResult) string { return v.Message }).(pulumi.StringOutput)
}
func (*Component) ElementType() reflect.Type {
return reflect.TypeOf((*Component)(nil))
}
func init() {
pulumi.RegisterOutputType(ComponentGetMessageResultOutput{})
}