Skip to content

Commit

Permalink
Verify launchInstance failed/succeeded properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ingvagabund committed Jan 17, 2019
1 parent 0e01946 commit efb2aa7
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions pkg/actuators/machine/instaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -282,6 +285,8 @@ func TestLaunchInstance(t *testing.T) {
},
},
},
instancesOutput: stubReservation("ami-a9acbbd6", "i-02fcb933c5da7085c"),
succeeds: true,
},
{
name: "Security groups with filters with error",
Expand Down Expand Up @@ -319,6 +324,8 @@ func TestLaunchInstance(t *testing.T) {
},
},
},
instancesOutput: stubReservation("ami-a9acbbd6", "i-02fcb933c5da7085c"),
succeeds: true,
},
{
name: "Subnet with filters with error",
Expand All @@ -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",
Expand Down Expand Up @@ -384,6 +398,8 @@ func TestLaunchInstance(t *testing.T) {
},
},
},
instancesOutput: stubReservation("ami-a9acbbd6", "i-02fcb933c5da7085c"),
succeeds: true,
},
{
name: "AMI not specified",
Expand All @@ -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")
}
}
})
}
}
Expand Down

0 comments on commit efb2aa7

Please sign in to comment.