Skip to content

Commit

Permalink
Merge pull request #145 from ingvagabund/verify-lunchinstance
Browse files Browse the repository at this point in the history
Verify launchInstance failed/succeeded properly
  • Loading branch information
openshift-merge-robot authored Jan 19, 2019
2 parents 8aec94e + efb2aa7 commit acf4a8e
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 @@ -266,6 +266,9 @@ func TestLaunchInstance(t *testing.T) {
azErr error
imageOutput *ec2.DescribeImagesOutput
imageErr error
instancesOutput *ec2.Reservation
instancesErr error
succeeds bool
}{
{
name: "Security groups with filters",
Expand All @@ -283,6 +286,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 @@ -320,6 +325,8 @@ func TestLaunchInstance(t *testing.T) {
},
},
},
instancesOutput: stubReservation("ami-a9acbbd6", "i-02fcb933c5da7085c"),
succeeds: true,
},
{
name: "Subnet with filters with error",
Expand All @@ -338,16 +345,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 @@ -392,6 +406,8 @@ func TestLaunchInstance(t *testing.T) {
},
},
},
instancesOutput: stubReservation("ami-a9acbbd6", "i-02fcb933c5da7085c"),
succeeds: true,
},
{
name: "AMI not specified",
Expand All @@ -407,9 +423,19 @@ func TestLaunchInstance(t *testing.T) {
mockAWSClient.EXPECT().DescribeAvailabilityZones(gomock.Any()).Return(nil, tc.azErr).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 acf4a8e

Please sign in to comment.