github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/testing/test/testdata/simple-resource-schema/go-extras/tests/codegen_test.go (about) 1 // Copyright 2016-2021, Pulumi Corporation. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package codegentest 16 17 import ( 18 "fmt" 19 "testing" 20 21 "github.com/stretchr/testify/assert" 22 23 "github.com/pulumi/pulumi/sdk/v3/go/common/resource" 24 "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 25 26 "simple-resource-schema/example" 27 ) 28 29 type mocks int 30 31 func pulumiTest(t *testing.T, body func(ctx *pulumi.Context) error) { 32 err := pulumi.RunErr(body, pulumi.WithMocks("project", "stack", mocks(0))) 33 assert.NoError(t, err) 34 } 35 36 func (mocks) NewResource(args pulumi.MockResourceArgs) (string, resource.PropertyMap, error) { 37 return args.ID, args.Inputs, nil 38 } 39 func (mocks) Call(args pulumi.MockCallArgs) (resource.PropertyMap, error) { 40 panic("Call not supported") 41 } 42 43 func TestHasDefaultPluginDownloadURL(t *testing.T) { 44 pulumiTest(t, func(ctx *pulumi.Context) error { 45 r, err := example.NewResource(ctx, "resource", &example.ResourceArgs{}) 46 assert.NoError(t, err) 47 assert.Contains(t, fmt.Sprintf("%#v", r), `pluginDownloadURL:"example.com/download"`) 48 return nil 49 }) 50 } 51 52 func TestCanOverrideDefaultPluginDownloadURL(t *testing.T) { 53 pulumiTest(t, func(ctx *pulumi.Context) error { 54 r, err := example.NewResource(ctx, "resource", &example.ResourceArgs{}, 55 pulumi.PluginDownloadURL("example.com/other")) 56 assert.NoError(t, err) 57 assert.Contains(t, fmt.Sprintf("%#v", r), `pluginDownloadURL:"example.com/other"`) 58 return nil 59 }) 60 }