Skip to content

Commit

Permalink
Merge pull request #20426 from imiosga/b-aws_amplify_branch-name_symm…
Browse files Browse the repository at this point in the history
…etry-20410

Fix branch name symmetry issue for Amplify
  • Loading branch information
ewbankkit authored Aug 4, 2021
2 parents ab33b98 + 0f0ca0e commit 76437e2
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/20426.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
aws/resource_aws_amplify_branch: Correctly handle branch names that contain '/'
```
2 changes: 1 addition & 1 deletion aws/internal/service/amplify/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func BranchCreateResourceID(appID, branchName string) string {
}

func BranchParseResourceID(id string) (string, string, error) {
parts := strings.Split(id, branchResourceIDSeparator)
parts := strings.SplitN(id, branchResourceIDSeparator, 2)

if len(parts) == 2 && parts[0] != "" && parts[1] != "" {
return parts[0], parts[1], nil
Expand Down
68 changes: 68 additions & 0 deletions aws/internal/service/amplify/id_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package amplify_test

import (
"testing"

tfamplify "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/amplify"
)

func TestBranchParseResourceID(t *testing.T) {
testCases := []struct {
TestName string
InputID string
ExpectError bool
ExpectedAppID string
ExpectedBranchName string
}{
{
TestName: "empty ID",
InputID: "",
ExpectError: true,
},
{
TestName: "incorrect format",
InputID: "test",
ExpectError: true,
},
{
TestName: "valid ID",
InputID: tfamplify.BranchCreateResourceID("appID", "branchName"),
ExpectedAppID: "appID",
ExpectedBranchName: "branchName",
},
{
TestName: "valid ID one slash",
InputID: tfamplify.BranchCreateResourceID("appID", "part1/part_2"),
ExpectedAppID: "appID",
ExpectedBranchName: "part1/part_2",
},
{
TestName: "valid ID three slashes",
InputID: tfamplify.BranchCreateResourceID("appID", "part1/part_2/part-3/part4"),
ExpectedAppID: "appID",
ExpectedBranchName: "part1/part_2/part-3/part4",
},
}

for _, testCase := range testCases {
t.Run(testCase.TestName, func(t *testing.T) {
gotAppID, gotBranchName, err := tfamplify.BranchParseResourceID(testCase.InputID)

if err == nil && testCase.ExpectError {
t.Fatalf("expected error")
}

if err != nil && !testCase.ExpectError {
t.Fatalf("unexpected error")
}

if gotAppID != testCase.ExpectedAppID {
t.Errorf("got AppID %s, expected %s", gotAppID, testCase.ExpectedAppID)
}

if gotBranchName != testCase.ExpectedBranchName {
t.Errorf("got BranchName %s, expected %s", gotBranchName, testCase.ExpectedBranchName)
}
})
}
}

0 comments on commit 76437e2

Please sign in to comment.