forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'ryandeivert/ryandeivert-add-flow-log-s3…
…-dest' into coveo-master
- Loading branch information
Showing
7 changed files
with
981 additions
and
143 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package aws | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
var ( | ||
ec2ResourceIdRegexp = regexp.MustCompile(`\A([a-z]+)-([a-z0-9]+)\z`) | ||
) | ||
|
||
// parseEc2ResourceId parses an EC2 resource ID into prefix and unique part. | ||
func parseEc2ResourceId(s string) (string, string) { | ||
matches := ec2ResourceIdRegexp.FindStringSubmatch(s) | ||
if matches == nil { | ||
return "", "" | ||
} | ||
return matches[1], matches[2] | ||
} |
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,45 @@ | ||
package aws | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestParseEc2ResourceId(t *testing.T) { | ||
type TestCase struct { | ||
ResourceId string | ||
ExpectedPrefix string | ||
ExpectedUnique string | ||
} | ||
testCases := []TestCase{ | ||
{ | ||
ResourceId: "", | ||
ExpectedPrefix: "", | ||
ExpectedUnique: "", | ||
}, | ||
{ | ||
ResourceId: "vpc12345678", | ||
ExpectedPrefix: "", | ||
ExpectedUnique: "", | ||
}, | ||
{ | ||
ResourceId: "vpc-12345678", | ||
ExpectedPrefix: "vpc", | ||
ExpectedUnique: "12345678", | ||
}, | ||
{ | ||
ResourceId: "i-12345678abcdef00", | ||
ExpectedPrefix: "i", | ||
ExpectedUnique: "12345678abcdef00", | ||
}, | ||
} | ||
|
||
for i, testCase := range testCases { | ||
resultPrefix, resultUnique := parseEc2ResourceId(testCase.ResourceId) | ||
if resultPrefix != testCase.ExpectedPrefix || resultUnique != testCase.ExpectedUnique { | ||
t.Errorf( | ||
"test case %d: got (%s, %s), but want (%s, %s)", | ||
i, resultPrefix, resultUnique, testCase.ExpectedPrefix, testCase.ExpectedUnique, | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.