Skip to content

Commit

Permalink
providers/aws: unit test for CleanZoneID
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Feb 17, 2015
1 parent 1b4fd28 commit 1b8aa74
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
8 changes: 0 additions & 8 deletions builtin/providers/aws/resource_aws_route53_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,6 @@ func resourceAwsRoute53RecordBuildSet(d *schema.ResourceData) (*route53.Resource
return rec, nil
}

// CleanZoneID is used to remove the leading /hostedzone/
func CleanZoneID(ID string) string {
if strings.HasPrefix(ID, "/hostedzone/") {
ID = strings.TrimPrefix(ID, "/hostedzone/")
}
return ID
}

func FQDN(name string) string {
n := len(name)
if n == 0 || name[n-1] == '.' {
Expand Down
8 changes: 8 additions & 0 deletions builtin/providers/aws/resource_aws_route53_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,11 @@ func CleanChangeID(ID string) string {
}
return ID
}

// CleanZoneID is used to remove the leading /hostedzone/
func CleanZoneID(ID string) string {
if strings.HasPrefix(ID, "/hostedzone/") {
ID = strings.TrimPrefix(ID, "/hostedzone/")
}
return ID
}
16 changes: 16 additions & 0 deletions builtin/providers/aws/resource_aws_route53_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ import (
"github.com/awslabs/aws-sdk-go/gen/route53"
)

func TestCleanZoneID(t *testing.T) {
cases := []struct {
Input, Output string
}{
{"/hostedzone/foo", "foo"},
{"/bar", "/bar"},
}

for _, tc := range cases {
actual := CleanZoneID(tc.Input)
if actual != tc.Output {
t.Fatalf("input: %s\noutput: %s", tc.Input, actual)
}
}
}

func TestAccRoute53Zone(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down

0 comments on commit 1b8aa74

Please sign in to comment.