diff --git a/pkg/actuators/machine/instaces_test.go b/pkg/actuators/machine/instaces_test.go index 267f9fa1f1..0b239a96b3 100644 --- a/pkg/actuators/machine/instaces_test.go +++ b/pkg/actuators/machine/instaces_test.go @@ -265,6 +265,9 @@ func TestLaunchInstance(t *testing.T) { subnetErr error imageOutput *ec2.DescribeImagesOutput imageErr error + instancesOutput *ec2.Reservation + instancesErr error + succeeds bool }{ { name: "Security groups with filters", @@ -282,6 +285,8 @@ func TestLaunchInstance(t *testing.T) { }, }, }, + instancesOutput: stubReservation("ami-a9acbbd6", "i-02fcb933c5da7085c"), + succeeds: true, }, { name: "Security groups with filters with error", @@ -319,6 +324,8 @@ func TestLaunchInstance(t *testing.T) { }, }, }, + instancesOutput: stubReservation("ami-a9acbbd6", "i-02fcb933c5da7085c"), + succeeds: true, }, { name: "Subnet with filters with error", @@ -330,16 +337,23 @@ func TestLaunchInstance(t *testing.T) { { name: "AMI with filters", providerConfig: stubPCAMI(providerconfigv1.AWSResourceReference{ - Filters: []providerconfigv1.Filter{}, + Filters: []providerconfigv1.Filter{ + { + Name: "foo", + Values: []string{"bar"}, + }, + }, }), imageOutput: &ec2.DescribeImagesOutput{ Images: []*ec2.Image{ { - CreationDate: aws.String(time.RFC3339), + CreationDate: aws.String("2006-01-02T15:04:05Z"), ImageId: aws.String("ami-1111"), }, }, }, + instancesOutput: stubReservation("ami-a9acbbd6", "i-02fcb933c5da7085c"), + succeeds: true, }, { name: "AMI with filters with error", @@ -384,6 +398,8 @@ func TestLaunchInstance(t *testing.T) { }, }, }, + instancesOutput: stubReservation("ami-a9acbbd6", "i-02fcb933c5da7085c"), + succeeds: true, }, { name: "AMI not specified", @@ -398,9 +414,19 @@ func TestLaunchInstance(t *testing.T) { mockAWSClient.EXPECT().DescribeSecurityGroups(gomock.Any()).Return(tc.securityGroupOutput, tc.securityGroupErr).AnyTimes() mockAWSClient.EXPECT().DescribeSubnets(gomock.Any()).Return(tc.subnetOutput, tc.subnetErr).AnyTimes() mockAWSClient.EXPECT().DescribeImages(gomock.Any()).Return(tc.imageOutput, tc.imageErr).AnyTimes() - mockAWSClient.EXPECT().RunInstances(gomock.Any()) + mockAWSClient.EXPECT().RunInstances(gomock.Any()).Return(tc.instancesOutput, tc.instancesErr).AnyTimes() - launchInstance(machine, tc.providerConfig, nil, mockAWSClient) + _, launchErr := launchInstance(machine, tc.providerConfig, nil, mockAWSClient) + t.Log(launchErr) + if launchErr == nil { + if !tc.succeeds { + t.Errorf("Call to launchInstance did not fail as expected") + } + } else { + if tc.succeeds { + t.Errorf("Call to launchInstance did not succeed as expected") + } + } }) } }