forked from awslabs/fargatecli
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix service connect eni bug * refactor and unit tests
- Loading branch information
Showing
2 changed files
with
145 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package ecs | ||
|
||
import ( | ||
"testing" | ||
|
||
awsecs "github.com/aws/aws-sdk-go/service/ecs" | ||
) | ||
|
||
// Test behavior for when there are no eni details | ||
func TestDetermineENIDetails_Empty(t *testing.T) { | ||
taskResult := awsecs.Task{ | ||
Attachments: make([]*awsecs.Attachment, 0), | ||
} | ||
|
||
found, _, _ := determineENIDetails(&taskResult) | ||
|
||
if found { | ||
t.Error("The blank attachment should not find an eni") | ||
} | ||
} | ||
|
||
// Test behavior for one simple eni attachment | ||
func TestDetermineENIDetails_SimpleENI(t *testing.T) { | ||
taskResult := awsecs.Task{ | ||
Attachments: make([]*awsecs.Attachment, 1), | ||
} | ||
|
||
taskResult.Attachments[0] = &awsecs.Attachment{ | ||
Details: make([]*awsecs.KeyValuePair, 2), | ||
} | ||
|
||
var expectedSubnetName, expectedENIName = detailSubnetId, detailNetworkInterfaceId | ||
var expectedSubnet, expectedENIID = "abc", "123" | ||
var eniType = eniAttachmentType | ||
|
||
taskResult.Attachments[0].Type = &eniType | ||
taskResult.Attachments[0].Details[0] = &awsecs.KeyValuePair{ | ||
Name: &expectedSubnetName, | ||
Value: &expectedSubnet, | ||
} | ||
taskResult.Attachments[0].Details[1] = &awsecs.KeyValuePair{ | ||
Name: &expectedENIName, | ||
Value: &expectedENIID, | ||
} | ||
|
||
found, eniResult, subnetResult := determineENIDetails(&taskResult) | ||
|
||
if !found { | ||
t.Error("The blank attachment should find an eni") | ||
} | ||
|
||
if eniResult != expectedENIID { | ||
t.Errorf("Should find ENIID. Was %s expected %s", eniResult, expectedENIID) | ||
} | ||
|
||
if subnetResult != expectedSubnet { | ||
t.Errorf("Should find subnetid. Was %s expected %s", subnetResult, expectedSubnet) | ||
} | ||
} | ||
|
||
// Test behavior for when there are multiple attachments, the first being ENI, then Service Connect | ||
func TestDetermineENIDetails_ServiceConnect(t *testing.T) { | ||
taskResult := awsecs.Task{ | ||
Attachments: make([]*awsecs.Attachment, 2), | ||
} | ||
|
||
taskResult.Attachments[0] = &awsecs.Attachment{ | ||
Details: make([]*awsecs.KeyValuePair, 2), | ||
} | ||
|
||
taskResult.Attachments[1] = &awsecs.Attachment{ | ||
Details: make([]*awsecs.KeyValuePair, 2), | ||
} | ||
|
||
var expectedSubnetName, expectedENIName = detailSubnetId, detailNetworkInterfaceId | ||
var expectedSubnet, expectedENIID = "abc", "123" | ||
var notExpectedSubnet, noExpectedENIID = "xyz", "456" | ||
var eniType, serviceConnectType = eniAttachmentType, "Service Connect" | ||
|
||
taskResult.Attachments[0].Type = &eniType | ||
taskResult.Attachments[0].Details[0] = &awsecs.KeyValuePair{ | ||
Name: &expectedSubnetName, | ||
Value: &expectedSubnet, | ||
} | ||
taskResult.Attachments[0].Details[1] = &awsecs.KeyValuePair{ | ||
Name: &expectedENIName, | ||
Value: &expectedENIID, | ||
} | ||
|
||
taskResult.Attachments[1].Type = &serviceConnectType | ||
taskResult.Attachments[1].Details[0] = &awsecs.KeyValuePair{ | ||
Name: &expectedSubnetName, | ||
Value: ¬ExpectedSubnet, | ||
} | ||
taskResult.Attachments[1].Details[1] = &awsecs.KeyValuePair{ | ||
Name: &expectedENIName, | ||
Value: &noExpectedENIID, | ||
} | ||
|
||
found, eniResult, subnetResult := determineENIDetails(&taskResult) | ||
|
||
if !found { | ||
t.Error("The blank attachment should find an eni") | ||
} | ||
|
||
if eniResult != expectedENIID { | ||
t.Errorf("Should find ENIID. Was %s expected %s", eniResult, expectedENIID) | ||
} | ||
|
||
if subnetResult != expectedSubnet { | ||
t.Errorf("Should find subnetid. Was %s expected %s", subnetResult, expectedSubnet) | ||
} | ||
} |