sparse-intern-71089
10/21/2020, 8:20 PMlemon-agent-27707
10/21/2020, 8:36 PMgifted-city-99717
10/22/2020, 2:40 PM// create a new network
func (resource *Network) create(ctx *pulumi.Context, name string, args *NetworkArgs) error {
var err error
resource.Vpc, err = args.VpcCreator(ctx, name+"-vpc", &ec2.VpcArgs{
CidrBlock: pulumi.String("10.99.0.0/16"),
EnableDnsHostnames: pulumi.Bool(true),
EnableClassiclinkDnsSupport: pulumi.Bool(true),
}, pulumi.Parent(resource))
if err != nil {
return errors.Wrap(err, "Cannot create VPC")
}
_ = resource.Vpc.DefaultSecurityGroupId.ApplyString(func(s string) string {
resource.SecurityGroupIds = append(resource.SecurityGroupIds, s)
return s
})
// ...
}
// test code
t.Run("create adds default security group to network", func(t *testing.T) {
mock := mock{}
n := Network{}
fakeVpc := &ec2.Vpc{}
expects := []string{fakeVpc.DefaultSecurityGroupId}
args := &NetworkArgs{
NumAvailabilityZones: 2,
VpcCreator: mock.FakeVpcCreator(fakeVpc, nil),
}
err := n.create(ctx, name, args)
assert.Equal(t, expects, n.SecurityGroupIds)
...
})
lemon-agent-27707
10/22/2020, 2:57 PMNewResource
and other mocks https://github.com/pulumi/examples/blob/master/testing-unit-go/main_test.go#L16-L22gifted-city-99717
10/23/2020, 3:27 PMt.Run
’s live inside a err := pulumi.RunErr
that’s passing in mocksNo matter how you like to participate in developer communities, Pulumi wants to meet you there. If you want to meet other Pulumi users to share use-cases and best practices, contribute code or documentation, see us at an event, or just tell a story about something cool you did with Pulumi, you are part of our community.
Powered by