Skip to content

Commit

Permalink
service/datasync: Fix lint issues with dataSyncParseLocationURI
Browse files Browse the repository at this point in the history
  • Loading branch information
bflad committed Nov 26, 2018
1 parent c1840c4 commit 17bac54
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 27 deletions.
6 changes: 3 additions & 3 deletions aws/datasync.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"github.com/hashicorp/terraform/helper/schema"
)

func dataSyncParseLocationURI(uri string) (string, string, string, error) {
func dataSyncParseLocationURI(uri string) (string, error) {
parsedURL, err := url.ParseRequestURI(uri)

if err != nil {
return "", "", "", err
return "", err
}

return parsedURL.Scheme, parsedURL.Host, parsedURL.Path, nil
return parsedURL.Path, nil
}

func expandDataSyncEc2Config(l []interface{}) *datasync.Ec2Config {
Expand Down
22 changes: 1 addition & 21 deletions aws/datasync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,39 @@ import (
func TestDataSyncParseLocationURI(t *testing.T) {
testCases := []struct {
LocationURI string
LocationType string
GlobalID string
Subdirectory string
}{
{
LocationURI: "efs://us-east-2.fs-abcd1234/",
LocationType: "efs",
GlobalID: "us-east-2.fs-abcd1234",
Subdirectory: "/",
},
{
LocationURI: "efs://us-east-2.fs-abcd1234/path",
LocationType: "efs",
GlobalID: "us-east-2.fs-abcd1234",
Subdirectory: "/path",
},
{
LocationURI: "nfs://example.com/",
LocationType: "nfs",
GlobalID: "example.com",
Subdirectory: "/",
},
{
LocationURI: "nfs://example.com/path",
LocationType: "nfs",
GlobalID: "example.com",
Subdirectory: "/path",
},
{
LocationURI: "s3://myBucket/",
LocationType: "s3",
GlobalID: "myBucket",
Subdirectory: "/",
},
{
LocationURI: "s3://myBucket/path",
LocationType: "s3",
GlobalID: "myBucket",
Subdirectory: "/path",
},
}

for i, tc := range testCases {
locationType, globalID, subdirectory, err := dataSyncParseLocationURI(tc.LocationURI)
subdirectory, err := dataSyncParseLocationURI(tc.LocationURI)
if err != nil {
t.Fatalf("%d: received error parsing (%s): %s", i, tc.LocationURI, err)
}
if locationType != tc.LocationType {
t.Fatalf("%d: expected type (%s), received: %s", i, tc.LocationType, locationType)
}
if globalID != tc.GlobalID {
t.Fatalf("%d: expected global ID (%s), received: %s", i, tc.GlobalID, globalID)
}
if subdirectory != tc.Subdirectory {
t.Fatalf("%d: expected subdirectory (%s), received: %s", i, tc.Subdirectory, subdirectory)
}
Expand Down
6 changes: 5 additions & 1 deletion aws/resource_aws_datasync_location_efs.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ func resourceAwsDataSyncLocationEfsRead(d *schema.ResourceData, meta interface{}
return fmt.Errorf("error reading DataSync Location EFS (%s) tags: %s", d.Id(), err)
}

_, _, subdirectory, err := dataSyncParseLocationURI(aws.StringValue(output.LocationUri))
subdirectory, err := dataSyncParseLocationURI(aws.StringValue(output.LocationUri))

if err != nil {
return fmt.Errorf("error parsing Location EFS (%s) URI (%s): %s", d.Id(), aws.StringValue(output.LocationUri), err)
}

d.Set("arn", output.LocationArn)

Expand Down
6 changes: 5 additions & 1 deletion aws/resource_aws_datasync_location_nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ func resourceAwsDataSyncLocationNfsRead(d *schema.ResourceData, meta interface{}
return fmt.Errorf("error reading DataSync Location NFS (%s) tags: %s", d.Id(), err)
}

_, _, subdirectory, err := dataSyncParseLocationURI(aws.StringValue(output.LocationUri))
subdirectory, err := dataSyncParseLocationURI(aws.StringValue(output.LocationUri))

if err != nil {
return fmt.Errorf("error parsing Location NFS (%s) URI (%s): %s", d.Id(), aws.StringValue(output.LocationUri), err)
}

d.Set("arn", output.LocationArn)

Expand Down
6 changes: 5 additions & 1 deletion aws/resource_aws_datasync_location_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ func resourceAwsDataSyncLocationS3Read(d *schema.ResourceData, meta interface{})
return fmt.Errorf("error reading DataSync Location S3 (%s) tags: %s", d.Id(), err)
}

_, _, subdirectory, err := dataSyncParseLocationURI(aws.StringValue(output.LocationUri))
subdirectory, err := dataSyncParseLocationURI(aws.StringValue(output.LocationUri))

if err != nil {
return fmt.Errorf("error parsing Location S3 (%s) URI (%s): %s", d.Id(), aws.StringValue(output.LocationUri), err)
}

d.Set("arn", output.LocationArn)

Expand Down

0 comments on commit 17bac54

Please sign in to comment.