https://pulumi.com logo
#golang
Title
# golang
f

fierce-ability-58936

08/21/2023, 3:49 AM
Still can't figure out how to do unit testing with remote component resources. This will panic. I've tried different things to mock the underlying bucket, which didn't work.
Copy code
package main

import (
	"testing"

	"<http://github.com/pulumi/pulumi-awsx/sdk/go/awsx/cloudtrail|github.com/pulumi/pulumi-awsx/sdk/go/awsx/cloudtrail>"
	"<http://github.com/pulumi/pulumi/sdk/v3/go/common/resource|github.com/pulumi/pulumi/sdk/v3/go/common/resource>"
	"<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi|github.com/pulumi/pulumi/sdk/v3/go/pulumi>"
	"<http://github.com/stretchr/testify/assert|github.com/stretchr/testify/assert>"
)

type mocks int

// Create the mock.
func (mocks) NewResource(args pulumi.MockResourceArgs) (string, resource.PropertyMap, error) {
	outputs := args.Inputs.Mappable()
	if args.TypeToken == "awsx:cloudtrail:Trail" {
		//outputs["bucket"] = (&s3.Bucket{Bucket: pulumi.String("fake").ToStringOutput()}).ToBucketOutput()
		//outputs["bucket"] = &s3.Bucket{}
	}
	return args.Name + "_id", resource.NewPropertyMapFromMap(outputs), nil
}

func (mocks) Call(args pulumi.MockCallArgs) (resource.PropertyMap, error) {
	outputs := map[string]interface{}{}
	return resource.NewPropertyMapFromMap(outputs), nil
}

func TestCloudTrail(t *testing.T) {
	err := pulumi.RunErr(func(ctx *pulumi.Context) error {
		trail, err := cloudtrail.NewTrail(ctx, "test-trail-go", &cloudtrail.TrailArgs{
			IncludeGlobalServiceEvents: pulumi.Bool(false),
			EnableLogging:              pulumi.Bool(true),
		})
		assert.NoError(t, err)
		assert.NotNil(t, trail.Bucket.Bucket())

		return nil
	}, pulumi.WithMocks("project", "stack", mocks(0)))

	assert.NoError(t, err)
}
b

billowy-army-68599

08/21/2023, 2:45 PM
could you file a github issue for this?
f

fierce-ability-58936

08/21/2023, 8:31 PM
Oh I thought I was doing something wrong.
2 Views