Skip to content

Commit

Permalink
data-source/aws_iam_server_certificate: Fixes for tfproviderlint R002 (
Browse files Browse the repository at this point in the history
…#11920)

Reference: #9952

Remove extraneous pointer value dereferences, which cause potential panics and are extraneous as `Set()` automatically handles pointer types including when `nil`.

Previously:

```
aws/data_source_aws_iam_server_certificate.go:142:15: R002: ResourceData.Set() pointer value dereference is extraneous
aws/data_source_aws_iam_server_certificate.go:143:16: R002: ResourceData.Set() pointer value dereference is extraneous
aws/data_source_aws_iam_server_certificate.go:144:16: R002: ResourceData.Set() pointer value dereference is extraneous
```

Also removes extraneous time conversion function.

Output from acceptance testing:

```
--- PASS: TestAccAWSDataSourceIAMServerCertificate_matchNamePrefix (4.36s)
--- PASS: TestAccAWSDataSourceIAMServerCertificate_basic (16.79s)
--- PASS: TestAccAWSDataSourceIAMServerCertificate_path (17.37s)
```
  • Loading branch information
bflad authored Feb 26, 2020
1 parent 03b75be commit ddc62cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
6 changes: 3 additions & 3 deletions aws/data_source_aws_iam_server_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ func dataSourceAwsIAMServerCertificateRead(d *schema.ResourceData, meta interfac

metadata := metadatas[0]
d.SetId(*metadata.ServerCertificateId)
d.Set("arn", *metadata.Arn)
d.Set("path", *metadata.Path)
d.Set("name", *metadata.ServerCertificateName)
d.Set("arn", metadata.Arn)
d.Set("path", metadata.Path)
d.Set("name", metadata.ServerCertificateName)
if metadata.Expiration != nil {
d.Set("expiration_date", metadata.Expiration.Format(time.RFC3339))
}
Expand Down
10 changes: 3 additions & 7 deletions aws/data_source_aws_iam_server_certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,19 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func timePtr(t time.Time) *time.Time {
return &t
}

func TestResourceSortByExpirationDate(t *testing.T) {
certs := []*iam.ServerCertificateMetadata{
{
ServerCertificateName: aws.String("oldest"),
Expiration: timePtr(time.Now()),
Expiration: aws.Time(time.Now()),
},
{
ServerCertificateName: aws.String("latest"),
Expiration: timePtr(time.Now().Add(3 * time.Hour)),
Expiration: aws.Time(time.Now().Add(3 * time.Hour)),
},
{
ServerCertificateName: aws.String("in between"),
Expiration: timePtr(time.Now().Add(2 * time.Hour)),
Expiration: aws.Time(time.Now().Add(2 * time.Hour)),
},
}
sort.Sort(certificateByExpiration(certs))
Expand Down

0 comments on commit ddc62cf

Please sign in to comment.