Skip to content

Commit

Permalink
Merge pull request #21330 from hashicorp/svcpkg-linting-deadcode
Browse files Browse the repository at this point in the history
linting: Restores unused code linting for Service Packages
  • Loading branch information
gdavison authored Oct 18, 2021
2 parents a3d788b + 8e8d173 commit ab85b1c
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 91 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ issues:
linters:
disable-all: true
enable:
# - deadcode
- deadcode
- errcheck
- gofmt
# - gomnd
Expand All @@ -30,7 +30,7 @@ linters:
- structcheck
- unconvert
# - unparam
# - varcheck
- varcheck
- vet

linters-settings:
Expand Down
20 changes: 0 additions & 20 deletions internal/service/apigateway/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/apigateway"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -118,25 +117,6 @@ func testAccCheckAccountDestroy(s *terraform.State) error {
return nil
}

// testAccPreCheckAccountCloudWatchRoleARN checks whether a CloudWatch role ARN has been configured in the current AWS region.
func testAccPreCheckAccountCloudWatchRoleARN(t *testing.T) {
conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn

output, err := conn.GetAccount(&apigateway.GetAccountInput{})

if acctest.PreCheckSkipError(err) {
t.Skipf("skipping tests: %s", err)
}

if err != nil {
t.Fatalf("error reading API Gateway Account: %s", err)
}

if output == nil || aws.StringValue(output.CloudwatchRoleArn) == "" {
t.Skip("skipping tests; no API Gateway CloudWatch role ARN has been configured in this region")
}
}

const testAccAccountConfig_empty = `
resource "aws_api_gateway_account" "test" {
}
Expand Down
10 changes: 0 additions & 10 deletions internal/service/cloudformation/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,16 +497,6 @@ func testAccCheckDestroy(s *terraform.State) error {
return nil
}

func testAccCheckCloudFormationStackNotRecreated(i, j *cloudformation.Stack) resource.TestCheckFunc {
return func(s *terraform.State) error {
if aws.StringValue(i.StackId) != aws.StringValue(j.StackId) {
return fmt.Errorf("CloudFormation stack recreated")
}

return nil
}
}

func testAccCheckCloudFormationStackDisappears(stack *cloudformation.Stack) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).CloudFormationConn
Expand Down
5 changes: 2 additions & 3 deletions internal/service/guardduty/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ const (
adminAccountNotFoundTimeout = 5 * time.Minute

// Maximum amount of time to wait for a PublishingDestination to return Publishing
publishingDestinationCreatedTimeout = 5 * time.Minute
publishingDestinationCreatedMinTimeout = 3 * time.Second
publishingDestinationCreatedTimeout = 5 * time.Minute

// Maximum amount of time to wait for membership to propagate
// When removing Organization Admin Accounts, there is eventual
Expand All @@ -32,7 +31,7 @@ func waitAdminAccountEnabled(conn *guardduty.GuardDuty, adminAccountID string) (
Pending: []string{adminStatusNotFound},
Target: []string{guardduty.AdminStatusEnabled},
Refresh: statusAdminAccountAdmin(conn, adminAccountID),
Timeout: adminAccountNotFoundTimeout,
Timeout: adminAccountEnabledTimeout,
}

outputRaw, err := stateConf.WaitForState()
Expand Down
7 changes: 3 additions & 4 deletions internal/service/kafka/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/kafka"
Expand All @@ -30,9 +29,9 @@ func ResourceCluster() *schema.Resource {
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(120 * time.Minute),
Update: schema.DefaultTimeout(120 * time.Minute),
Delete: schema.DefaultTimeout(120 * time.Minute),
Create: schema.DefaultTimeout(clusterCreateDefaultTimeout),
Update: schema.DefaultTimeout(clusterUpdateDefaultTimeout),
Delete: schema.DefaultTimeout(clusterDeleteDefaultTimeout),
},

CustomizeDiff: customdiff.Sequence(
Expand Down
6 changes: 3 additions & 3 deletions internal/service/kafka/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
)

const (
clusterCreateTimeout = 120 * time.Minute
clusterUpdateTimeout = 120 * time.Minute
clusterDeleteTimeout = 120 * time.Minute
clusterCreateDefaultTimeout = 120 * time.Minute
clusterUpdateDefaultTimeout = 120 * time.Minute
clusterDeleteDefaultTimeout = 120 * time.Minute
)

const (
Expand Down
7 changes: 0 additions & 7 deletions internal/service/lexmodelbuilding/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ import (
)

const (
//Lex Bot Statuses
lexModeBuildingServicesStatusBuilding = "BUILDING"
lexModeBuildingServicesStatusFailed = "FAILED"
lexModeBuildingServicesStatusNotBuilt = "NOT_BUILT"
lexModeBuildingServicesStatusReady = "READY"
lexModeBuildingServicesStatusReadyBasicTesting = "READY_BASIC_TESTING"

lexModelBuildingServiceStatusCreated = "CREATED"
lexModelBuildingServiceStatusNotFound = "NOTFOUND"
lexModelBuildingServiceStatusUnknown = "UNKNOWN"
Expand Down
2 changes: 2 additions & 0 deletions internal/service/redshift/enum.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package redshift

// https://docs.aws.amazon.com/redshift/latest/mgmt/working-with-clusters.html#rs-mgmt-cluster-status.
//nolint:deadcode,varcheck // These constants are missing from the AWS SDK
const (
clusterStatusAvailable = "available"
clusterStatusAvailablePrepForResize = "available, prep-for-resize"
Expand Down Expand Up @@ -29,6 +30,7 @@ const (
clusterTypeSingleNode = "single-node"
)

//nolint:deadcode // These constants are missing from the AWS SDK
func clusterType_Values() []string {
return []string{
clusterTypeMultiNode,
Expand Down
9 changes: 0 additions & 9 deletions internal/service/s3/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@ package s3

import (
"time"

"github.com/aws/aws-sdk-go/service/s3"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

const (
bucketCreatedTimeout = 2 * time.Minute
propagationTimeout = 1 * time.Minute
)

// waitRetryWhenBucketNotFound retries the specified function if the returned error indicates that a bucket is not found.
// If the retries time out the specified function is called one last time.
func waitRetryWhenBucketNotFound(f func() (interface{}, error)) (interface{}, error) {
return tfresource.RetryWhenAWSErrCodeEquals(propagationTimeout, f, s3.ErrCodeNoSuchBucket)
}
2 changes: 1 addition & 1 deletion internal/service/s3control/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package s3control

// Error code constants missing from AWS Go SDK:
// https://docs.aws.amazon.com/sdk-for-go/api/service/s3control/#pkg-constants

//nolint:deadcode,varcheck // These constants are missing from the AWS SDK
const (
errCodeNoSuchAccessPoint = "NoSuchAccessPoint"
errCodeNoSuchAccessPointPolicy = "NoSuchAccessPointPolicy"
Expand Down
25 changes: 0 additions & 25 deletions internal/service/servicecatalog/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,6 @@ import (

// Custom Service Catalog tag service update functions using the same format as generated code.

func portfolioUpdateTags(conn *servicecatalog.ServiceCatalog, identifier string, oldTagsMap interface{}, newTagsMap interface{}) error {
oldTags := tftags.New(oldTagsMap)
newTags := tftags.New(newTagsMap)

input := &servicecatalog.UpdatePortfolioInput{
Id: aws.String(identifier),
}

if removedTags := oldTags.Removed(newTags); len(removedTags) > 0 {
input.RemoveTags = aws.StringSlice(removedTags.IgnoreAWS().Keys())
}

if updatedTags := oldTags.Updated(newTags); len(updatedTags) > 0 {
input.AddTags = Tags(updatedTags.IgnoreAWS())
}

_, err := conn.UpdatePortfolio(input)

if err != nil {
return fmt.Errorf("error updating tags for Service Catalog Product (%s): %w", identifier, err)
}

return nil
}

func productUpdateTags(conn *servicecatalog.ServiceCatalog, identifier string, oldTagsMap interface{}, newTagsMap interface{}) error {
oldTags := tftags.New(oldTagsMap)
newTags := tftags.New(newTagsMap)
Expand Down
1 change: 1 addition & 0 deletions internal/service/storagegateway/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
fileSystemAssociationDeleteTimeout = 3 * time.Minute
)

//nolint:deadcode,varcheck // These constants are missing from the AWS SDK
const (
fileSystemAssociationStatusAvailable = "AVAILABLE"
fileSystemAssociationStatusCreating = "CREATING"
Expand Down
9 changes: 2 additions & 7 deletions internal/service/storagegateway/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ import (
const (
storageGatewayGatewayStatusConnected = "GatewayConnected"
storediSCSIVolumeStatusNotFound = "NotFound"
storediSCSIVolumeStatusUnknown = "Unknown"
nfsFileShareStatusNotFound = "NotFound"
nfsFileShareStatusUnknown = "Unknown"
smbFileShareStatusNotFound = "NotFound"
smbFileShareStatusUnknown = "Unknown"
fileSystemAssociationStatusNotFound = "NotFound"
fileSystemAssociationStatusUnknown = "Unknown"
)

func statusStorageGatewayGateway(conn *storagegateway.StorageGateway, gatewayARN string) resource.StateRefreshFunc {
Expand Down Expand Up @@ -78,7 +73,7 @@ func statusStorediSCSIVolume(conn *storagegateway.StorageGateway, volumeARN stri
}

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

if output == nil || len(output.StorediSCSIVolumes) == 0 {
Expand All @@ -101,7 +96,7 @@ func statusNFSFileShare(conn *storagegateway.StorageGateway, fileShareArn string
if tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified file share was not found.") {
return nil, nfsFileShareStatusNotFound, nil
}
return nil, nfsFileShareStatusUnknown, fmt.Errorf("error reading Storage Gateway NFS File Share: %w", err)
return nil, "", fmt.Errorf("error reading Storage Gateway NFS File Share: %w", err)
}

if output == nil || len(output.NFSFileShareInfoList) == 0 || output.NFSFileShareInfoList[0] == nil {
Expand Down

0 comments on commit ab85b1c

Please sign in to comment.