Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix branch name symmetry issue for Amplify #20426

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
})
}
}