pulumi/pkg/codegen/internal/test/testdata/simple-enum-schema/go-extras/tests/go_test.go
Anton Tayanovskyy 49298fb433
Codegen testing upgrades (#7989)
* Multi-pass, in-place checks for SDK codegen tests; toward working Python checks

* Remove temp debug output

* Upgrade Node

* Update dotnet; need to follow up on version.txt quirks

* WIP

* Sounds like we can use non-github package names to ensure things are local

* Fix simple-enum-schema

* Fix dash-named-schema

* Fix nested-module

* Start building a test-running pass

* Infer skipping tests from skipping compiles

* Move tree schma tests to a proper place

* Address lint issues on Go code

* Build against local Go SDK

* Update pkg/codegen/internal/test/sdk_driver.go

Co-authored-by: Ian Wahbe <ian@wahbe.com>

* Make go tests work by copying them into the tree from go-extras

* Fix lint

* Fix bad merge

* Manifest-based file discovery

* Remove version-related TODO from dotnet codegen

* Add doc comment

* Do not overwrite go.mod if found from mixins

* Accept python codegen change

* Accept node codegen

* Ignore lint issue

* Accept docs changes

Co-authored-by: Ian Wahbe <ian@wahbe.com>
2021-09-22 13:55:20 -04:00

186 lines
6.3 KiB
Go

package tests
import (
"sync"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"simple-enum-schema/plant"
tree "simple-enum-schema/plant/tree/v1"
)
func TestEnumUsage(t *testing.T) {
t.Run("Success", func(t *testing.T) {
require.NoError(t, pulumi.RunErr(func(ctx *pulumi.Context) error {
rubberTree, err := tree.NewRubberTree(ctx, "blah", &tree.RubberTreeArgs{
Container: &plant.ContainerArgs{
Color: plant.ContainerColorRed,
Material: pulumi.String("ceramic"),
Size: plant.ContainerSizeFourInch,
},
Farm: tree.Farm_Plants_R_Us,
Type: tree.RubberTreeVarietyRuby,
})
require.NoError(t, err)
require.NotNil(t, rubberTree)
var wg sync.WaitGroup
wg.Add(1)
pulumi.All(
rubberTree.URN(),
rubberTree.Container.Material(),
rubberTree.Container.Color(),
rubberTree.Container.Size(),
rubberTree.Container.Brightness(),
rubberTree.Type,
).ApplyT(func(all []interface{}) error {
urn := all[0].(pulumi.URN)
material := all[1].(*string)
color := all[2].(*string)
size := all[3].(*plant.ContainerSize)
brightness := all[4].(*plant.ContainerBrightness)
typ := all[5].(tree.RubberTreeVariety)
assert.Equal(t, *material, "ceramic", "unexpected material on resource: %v", urn)
assert.Equal(t, *color, "red", "unexpected color on resource: %v", urn)
assert.Equal(t, *size, plant.ContainerSizeFourInch, "unexpected size on resource: %v", urn)
assert.Nil(t, brightness)
assert.Equal(t, typ, tree.RubberTreeVarietyRuby, "unexpected type on resource: %v", urn)
wg.Done()
return nil
})
wg.Wait()
return nil
}, pulumi.WithMocks("project", "stack", mocks(0))))
})
t.Run("StringsForRelaxedEnum", func(t *testing.T) {
require.NoError(t, pulumi.RunErr(func(ctx *pulumi.Context) error {
rubberTree, err := tree.NewRubberTree(ctx, "blah", &tree.RubberTreeArgs{
Container: plant.ContainerArgs{
Color: pulumi.String("Magenta"),
Material: pulumi.String("ceramic"),
Size: plant.ContainerSize(22),
},
Farm: tree.Farm_Plants_R_Us,
Type: tree.RubberTreeVarietyRuby,
})
require.NoError(t, err)
require.NotNil(t, rubberTree)
var wg sync.WaitGroup
wg.Add(1)
pulumi.All(
rubberTree.URN(),
rubberTree.Container.Material(),
rubberTree.Container.Color(),
rubberTree.Container.Size(),
rubberTree.Type,
).ApplyT(func(all []interface{}) error {
urn := all[0].(pulumi.URN)
material := all[1].(*string)
color := all[2].(*string)
size := all[3].(*plant.ContainerSize)
typ := all[4].(tree.RubberTreeVariety)
assert.Equal(t, *material, "ceramic", "unexpected material on resource: %v", urn)
assert.Equal(t, *color, "Magenta", "unexpected color on resource: %v", urn)
assert.Equal(t, *size, plant.ContainerSize(22), "unexpected size on resource: %v", urn)
assert.Equal(t, typ, tree.RubberTreeVarietyRuby, "unexpected type on resource: %v", urn)
wg.Done()
return nil
})
wg.Wait()
return nil
}, pulumi.WithMocks("project", "stack", mocks(1))))
})
t.Run("StringsForStrictEnum", func(t *testing.T) {
require.NoError(t, pulumi.RunErr(func(ctx *pulumi.Context) error {
rubberTree, err := tree.NewRubberTree(ctx, "blah", &tree.RubberTreeArgs{
Container: plant.ContainerArgs{
Color: pulumi.String("Magenta"),
Material: pulumi.String("ceramic"),
Size: plant.ContainerSize(22),
},
Farm: tree.Farm_Plants_R_Us,
Type: tree.RubberTreeVarietyBurgundy,
})
require.NoError(t, err)
require.NotNil(t, rubberTree)
var wg sync.WaitGroup
wg.Add(1)
pulumi.All(
rubberTree.URN(),
rubberTree.Container.Material(),
rubberTree.Container.Color(),
rubberTree.Container.Size(),
rubberTree.Type,
).ApplyT(func(all []interface{}) error {
urn := all[0].(pulumi.URN)
material := all[1].(*string)
color := all[2].(*string)
size := all[3].(*plant.ContainerSize)
typ := all[4].(tree.RubberTreeVariety)
assert.Equal(t, *material, "ceramic", "unexpected material on resource: %v", urn)
assert.Equal(t, *color, "Magenta", "unexpected color on resource: %v", urn)
assert.Equal(t, *size, plant.ContainerSize(22), "unexpected size on resource: %v", urn)
assert.Equal(t, typ, tree.RubberTreeVarietyBurgundy, "unexpected type on resource: %v", urn)
wg.Done()
return nil
})
wg.Wait()
return nil
}, pulumi.WithMocks("project", "stack", mocks(1))))
})
t.Run("EnumOutputs", func(t *testing.T) {
require.NoError(t, pulumi.RunErr(func(ctx *pulumi.Context) error {
rubberTree, err := tree.NewRubberTree(ctx, "blah", &tree.RubberTreeArgs{
Container: plant.ContainerArgs{
Color: plant.ContainerColor("Magenta").ToContainerColorOutput().ToStringOutput(),
Material: pulumi.String("ceramic").ToStringOutput(),
Size: plant.ContainerSize(22).ToContainerSizeOutput(),
},
Farm: tree.Farm_Plants_R_Us.ToFarmPtrOutput().ToStringPtrOutput(),
Type: tree.RubberTreeVarietyBurgundy.ToRubberTreeVarietyOutput(),
})
require.NoError(t, err)
require.NotNil(t, rubberTree)
var wg sync.WaitGroup
wg.Add(1)
pulumi.All(
rubberTree.URN(),
rubberTree.Container.Material(),
rubberTree.Container.Color(),
rubberTree.Container.Size(),
rubberTree.Type,
).ApplyT(func(all []interface{}) error {
urn := all[0].(pulumi.URN)
material := all[1].(*string)
color := all[2].(*string)
size := all[3].(*plant.ContainerSize)
typ := all[4].(tree.RubberTreeVariety)
assert.Equal(t, *material, "ceramic", "unexpected material on resource: %v", urn)
assert.Equal(t, *color, "Magenta", "unexpected color on resource: %v", urn)
assert.Equal(t, *size, plant.ContainerSize(22), "unexpected size on resource: %v", urn)
assert.Equal(t, typ, tree.RubberTreeVarietyBurgundy, "unexpected type on resource: %v", urn)
wg.Done()
return nil
})
wg.Wait()
return nil
}, pulumi.WithMocks("project", "stack", mocks(1))))
})
}
type mocks int
func (mocks) NewResource(args pulumi.MockResourceArgs) (string, resource.PropertyMap, error) {
return args.Name + "_id", args.Inputs, nil
}
func (mocks) Call(args pulumi.MockCallArgs) (resource.PropertyMap, error) {
return args.Args, nil
}