github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/testing/test/testdata/simple-enum-schema/go-extras/tests/go_test.go (about) 1 package tests 2 3 import ( 4 "sync" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 10 "github.com/pulumi/pulumi/sdk/v3/go/common/resource" 11 "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 12 13 "simple-enum-schema/plant" 14 tree "simple-enum-schema/plant/tree/v1" 15 ) 16 17 func TestEnumUsage(t *testing.T) { 18 t.Run("Success", func(t *testing.T) { 19 require.NoError(t, pulumi.RunErr(func(ctx *pulumi.Context) error { 20 rubberTree, err := tree.NewRubberTree(ctx, "blah", &tree.RubberTreeArgs{ 21 Container: &plant.ContainerArgs{ 22 Color: plant.ContainerColorRed, 23 Material: pulumi.String("ceramic"), 24 Size: plant.ContainerSizeFourInch, 25 }, 26 Farm: tree.Farm_Plants_R_Us, 27 Type: tree.RubberTreeVarietyRuby, 28 }) 29 require.NoError(t, err) 30 require.NotNil(t, rubberTree) 31 var wg sync.WaitGroup 32 wg.Add(1) 33 pulumi.All( 34 rubberTree.URN(), 35 rubberTree.Container.Material(), 36 rubberTree.Container.Color(), 37 rubberTree.Container.Size(), 38 rubberTree.Container.Brightness(), 39 rubberTree.Type, 40 ).ApplyT(func(all []interface{}) error { 41 urn := all[0].(pulumi.URN) 42 material := all[1].(*string) 43 color := all[2].(*string) 44 size := all[3].(*plant.ContainerSize) 45 brightness := all[4].(*plant.ContainerBrightness) 46 typ := all[5].(tree.RubberTreeVariety) 47 assert.Equal(t, *material, "ceramic", "unexpected material on resource: %v", urn) 48 assert.Equal(t, *color, "red", "unexpected color on resource: %v", urn) 49 assert.Equal(t, *size, plant.ContainerSizeFourInch, "unexpected size on resource: %v", urn) 50 assert.Equal(t, *brightness, plant.ContainerBrightness(1.0)) 51 assert.Equal(t, typ, tree.RubberTreeVarietyRuby, "unexpected type on resource: %v", urn) 52 wg.Done() 53 return nil 54 }) 55 wg.Wait() 56 return nil 57 }, pulumi.WithMocks("project", "stack", mocks(0)))) 58 }) 59 60 t.Run("StringsForRelaxedEnum", func(t *testing.T) { 61 require.NoError(t, pulumi.RunErr(func(ctx *pulumi.Context) error { 62 rubberTree, err := tree.NewRubberTree(ctx, "blah", &tree.RubberTreeArgs{ 63 Container: plant.ContainerArgs{ 64 Color: pulumi.String("Magenta"), 65 Material: pulumi.String("ceramic"), 66 Size: plant.ContainerSize(22), 67 }, 68 Farm: tree.Farm_Plants_R_Us, 69 Type: tree.RubberTreeVarietyRuby, 70 }) 71 require.NoError(t, err) 72 require.NotNil(t, rubberTree) 73 var wg sync.WaitGroup 74 wg.Add(1) 75 pulumi.All( 76 rubberTree.URN(), 77 rubberTree.Container.Material(), 78 rubberTree.Container.Color(), 79 rubberTree.Container.Size(), 80 rubberTree.Type, 81 ).ApplyT(func(all []interface{}) error { 82 urn := all[0].(pulumi.URN) 83 material := all[1].(*string) 84 color := all[2].(*string) 85 size := all[3].(*plant.ContainerSize) 86 typ := all[4].(tree.RubberTreeVariety) 87 assert.Equal(t, *material, "ceramic", "unexpected material on resource: %v", urn) 88 assert.Equal(t, *color, "Magenta", "unexpected color on resource: %v", urn) 89 assert.Equal(t, *size, plant.ContainerSize(22), "unexpected size on resource: %v", urn) 90 assert.Equal(t, typ, tree.RubberTreeVarietyRuby, "unexpected type on resource: %v", urn) 91 wg.Done() 92 return nil 93 }) 94 wg.Wait() 95 return nil 96 }, pulumi.WithMocks("project", "stack", mocks(1)))) 97 }) 98 99 t.Run("StringsForStrictEnum", func(t *testing.T) { 100 require.NoError(t, pulumi.RunErr(func(ctx *pulumi.Context) error { 101 rubberTree, err := tree.NewRubberTree(ctx, "blah", &tree.RubberTreeArgs{ 102 Container: plant.ContainerArgs{ 103 Color: pulumi.String("Magenta"), 104 Material: pulumi.String("ceramic"), 105 Size: plant.ContainerSize(22), 106 }, 107 Farm: tree.Farm_Plants_R_Us, 108 Type: tree.RubberTreeVarietyBurgundy, 109 }) 110 require.NoError(t, err) 111 require.NotNil(t, rubberTree) 112 var wg sync.WaitGroup 113 wg.Add(1) 114 pulumi.All( 115 rubberTree.URN(), 116 rubberTree.Container.Material(), 117 rubberTree.Container.Color(), 118 rubberTree.Container.Size(), 119 rubberTree.Type, 120 ).ApplyT(func(all []interface{}) error { 121 urn := all[0].(pulumi.URN) 122 material := all[1].(*string) 123 color := all[2].(*string) 124 size := all[3].(*plant.ContainerSize) 125 typ := all[4].(tree.RubberTreeVariety) 126 assert.Equal(t, *material, "ceramic", "unexpected material on resource: %v", urn) 127 assert.Equal(t, *color, "Magenta", "unexpected color on resource: %v", urn) 128 assert.Equal(t, *size, plant.ContainerSize(22), "unexpected size on resource: %v", urn) 129 assert.Equal(t, typ, tree.RubberTreeVarietyBurgundy, "unexpected type on resource: %v", urn) 130 wg.Done() 131 return nil 132 }) 133 wg.Wait() 134 return nil 135 }, pulumi.WithMocks("project", "stack", mocks(1)))) 136 }) 137 138 t.Run("EnumOutputs", func(t *testing.T) { 139 require.NoError(t, pulumi.RunErr(func(ctx *pulumi.Context) error { 140 rubberTree, err := tree.NewRubberTree(ctx, "blah", &tree.RubberTreeArgs{ 141 Container: plant.ContainerArgs{ 142 Color: plant.ContainerColor("Magenta").ToContainerColorOutput().ToStringOutput(), 143 Material: pulumi.String("ceramic").ToStringOutput(), 144 Size: plant.ContainerSize(22).ToContainerSizeOutput(), 145 }, 146 Farm: tree.Farm_Plants_R_Us.ToFarmPtrOutput().ToStringPtrOutput(), 147 Type: tree.RubberTreeVarietyBurgundy.ToRubberTreeVarietyOutput(), 148 }) 149 require.NoError(t, err) 150 require.NotNil(t, rubberTree) 151 var wg sync.WaitGroup 152 wg.Add(1) 153 pulumi.All( 154 rubberTree.URN(), 155 rubberTree.Container.Material(), 156 rubberTree.Container.Color(), 157 rubberTree.Container.Size(), 158 rubberTree.Type, 159 ).ApplyT(func(all []interface{}) error { 160 urn := all[0].(pulumi.URN) 161 material := all[1].(*string) 162 color := all[2].(*string) 163 size := all[3].(*plant.ContainerSize) 164 typ := all[4].(tree.RubberTreeVariety) 165 assert.Equal(t, *material, "ceramic", "unexpected material on resource: %v", urn) 166 assert.Equal(t, *color, "Magenta", "unexpected color on resource: %v", urn) 167 assert.Equal(t, *size, plant.ContainerSize(22), "unexpected size on resource: %v", urn) 168 assert.Equal(t, typ, tree.RubberTreeVarietyBurgundy, "unexpected type on resource: %v", urn) 169 wg.Done() 170 return nil 171 }) 172 wg.Wait() 173 return nil 174 }, pulumi.WithMocks("project", "stack", mocks(1)))) 175 }) 176 } 177 178 type mocks int 179 180 func (mocks) NewResource(args pulumi.MockResourceArgs) (string, resource.PropertyMap, error) { 181 return args.Name + "_id", args.Inputs, nil 182 } 183 184 func (mocks) Call(args pulumi.MockCallArgs) (resource.PropertyMap, error) { 185 return args.Args, nil 186 }