Skip to content

Commit

Permalink
tests/provider: Enable S1039 check for unnecessary fmt.Sprint()/fmt.S…
Browse files Browse the repository at this point in the history
…printf() usage (hashicorp#16741)
  • Loading branch information
mattburgess authored Jan 5, 2021
1 parent eb5174a commit 0ed3e50
Show file tree
Hide file tree
Showing 40 changed files with 256 additions and 259 deletions.
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
issues:
exclude-rules:
- linters:
- gosimple
text: "S1039:"

# Exclude issues bypassing staticcheck.conf
- linters:
- staticcheck
Expand Down
4 changes: 2 additions & 2 deletions aws/data_source_aws_autoscaling_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func testAccAutoScalingGroupDataResourceConfig_launchTemplate() string {
testAccLatestAmazonLinuxHvmEbsAmiConfig(),
testAccAvailableAZsNoOptInConfig(),
testAccAvailableEc2InstanceTypeForAvailabilityZone("data.aws_availability_zones.available.names[0]", "t3.micro", "t2.micro"),
fmt.Sprintf(`
`
data "aws_autoscaling_group" "test" {
name = aws_autoscaling_group.test.name
}
Expand All @@ -145,5 +145,5 @@ resource "aws_launch_template" "test" {
image_id = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
instance_type = data.aws_ec2_instance_type_offering.available.instance_type
}
`))
`)
}
15 changes: 9 additions & 6 deletions aws/data_source_aws_codeartifact_authorization_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,19 @@ resource "aws_codeartifact_domain" "test" {
}

func testAccCheckAWSCodeArtifactAuthorizationTokenBasicConfig(rName string) string {
return testAccCheckAWSCodeArtifactAuthorizationTokenBaseConfig(rName) +
fmt.Sprintf(`
return composeConfig(
testAccCheckAWSCodeArtifactAuthorizationTokenBaseConfig(rName),
`
data "aws_codeartifact_authorization_token" "test" {
domain = aws_codeartifact_domain.test.domain
}
`)
}

func testAccCheckAWSCodeArtifactAuthorizationTokenOwnerConfig(rName string) string {
return testAccCheckAWSCodeArtifactAuthorizationTokenBaseConfig(rName) +
fmt.Sprintf(`
return composeConfig(
testAccCheckAWSCodeArtifactAuthorizationTokenBaseConfig(rName),
`
data "aws_codeartifact_authorization_token" "test" {
domain = aws_codeartifact_domain.test.domain
domain_owner = aws_codeartifact_domain.test.owner
Expand All @@ -104,8 +106,9 @@ data "aws_codeartifact_authorization_token" "test" {
}

func testAccCheckAWSCodeArtifactAuthorizationTokenDurationConfig(rName string) string {
return testAccCheckAWSCodeArtifactAuthorizationTokenBaseConfig(rName) +
fmt.Sprintf(`
return composeConfig(
testAccCheckAWSCodeArtifactAuthorizationTokenBaseConfig(rName),
`
data "aws_codeartifact_authorization_token" "test" {
domain = aws_codeartifact_domain.test.domain
duration_seconds = 900
Expand Down
4 changes: 2 additions & 2 deletions aws/data_source_aws_codeartifact_repository_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ data "aws_codeartifact_repository_endpoint" "test" {
func testAccCheckAWSCodeArtifactRepositoryEndpointOwnerConfig(rName string) string {
return composeConfig(
testAccCheckAWSCodeArtifactRepositoryEndpointBaseConfig(rName),
fmt.Sprintf(`
`
data "aws_codeartifact_repository_endpoint" "test" {
domain = aws_codeartifact_domain.test.domain
repository = aws_codeartifact_repository.test.repository
domain_owner = aws_codeartifact_domain.test.owner
format = "npm"
}
`))
`)
}
5 changes: 3 additions & 2 deletions aws/data_source_aws_directory_service_directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ data "aws_directory_service_directory" "test-microsoft-ad" {
}

func testAccDataSourceDirectoryServiceDirectoryConfig_connector() string {
return composeConfig(testAccAvailableAZsNoOptInConfig(), fmt.Sprintf(`
return composeConfig(testAccAvailableAZsNoOptInConfig(),
`
resource "aws_directory_service_directory" "test" {
name = "corp.notexample.com"
password = "SuperSecretPassw0rd"
Expand Down Expand Up @@ -254,5 +255,5 @@ resource "aws_subnet" "test" {
data "aws_directory_service_directory" "test-ad-connector" {
directory_id = aws_directory_service_directory.connector.id
}
`))
`)
}
8 changes: 4 additions & 4 deletions aws/data_source_aws_docdb_engine_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ data "aws_docdb_engine_version" "test" {
}

func testAccAWSDocDBEngineVersionDataSourcePreferredConfig() string {
return fmt.Sprintf(`
return `
data "aws_docdb_engine_version" "test" {
preferred_versions = ["34.6.1", "3.6.0", "2.6.0"]
}
`)
`
}

func testAccAWSDocDBEngineVersionDataSourceDefaultOnlyConfig() string {
return fmt.Sprintf(`
return `
data "aws_docdb_engine_version" "test" {}
`)
`
}
4 changes: 2 additions & 2 deletions aws/data_source_aws_ebs_snapshot_ids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestAccDataSourceAwsEbsSnapshotIds_empty(t *testing.T) {
}

func testAccDataSourceAwsEbsSnapshotIdsConfig_basic() string {
return composeConfig(testAccAvailableAZsNoOptInConfig(), fmt.Sprintf(`
return composeConfig(testAccAvailableAZsNoOptInConfig(), `
resource "aws_ebs_volume" "test" {
availability_zone = data.aws_availability_zones.available.names[0]
size = 1
Expand All @@ -84,7 +84,7 @@ resource "aws_ebs_snapshot" "test" {
data "aws_ebs_snapshot_ids" "test" {
owners = ["self"]
}
`))
`)
}

func testAccDataSourceAwsEbsSnapshotIdsConfig_sorted1(rName string) string {
Expand Down
5 changes: 2 additions & 3 deletions aws/data_source_aws_ec2_spot_price_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package aws

import (
"fmt"
"regexp"
"testing"

Expand Down Expand Up @@ -67,7 +66,7 @@ func testAccPreCheckAwsEc2SpotPrice(t *testing.T) {
}

func testAccAwsEc2SpotPriceDataSourceConfig() string {
return testAccAvailableAZsNoOptInConfig() + fmt.Sprintf(`
return composeConfig(testAccAvailableAZsNoOptInConfig(), `
data "aws_region" "current" {}
data "aws_ec2_instance_type_offering" "test" {
Expand All @@ -91,7 +90,7 @@ data "aws_ec2_spot_price" "test" {
}

func testAccAwsEc2SpotPriceDataSourceFilterConfig() string {
return testAccAvailableAZsNoOptInConfig() + fmt.Sprintf(`
return composeConfig(testAccAvailableAZsNoOptInConfig(), `
data "aws_region" "current" {}
data "aws_ec2_instance_type_offering" "test" {
Expand Down
21 changes: 11 additions & 10 deletions aws/data_source_aws_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ data "aws_instance" "test" {
}

// filter on tag, populate more attributes
var testAccInstanceDataSourceConfig_AzUserData = testAccAvailableAZsNoOptInDefaultExcludeConfig() +
testAccLatestAmazonLinuxHvmEbsAmiConfig() + fmt.Sprintf(`
var testAccInstanceDataSourceConfig_AzUserData = composeConfig(testAccAvailableAZsNoOptInDefaultExcludeConfig(),
testAccLatestAmazonLinuxHvmEbsAmiConfig(), `
resource "aws_instance" "test" {
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
availability_zone = data.aws_availability_zones.available.names[0]
Expand Down Expand Up @@ -738,7 +738,7 @@ data "aws_instance" "test" {
`

func testAccInstanceDataSourceConfig_privateIP(rName string) string {
return testAccLatestAmazonLinuxHvmEbsAmiConfig() + testAccAwsInstanceVpcConfigBasic(rName) + fmt.Sprintf(`
return composeConfig(testAccLatestAmazonLinuxHvmEbsAmiConfig(), testAccAwsInstanceVpcConfigBasic(rName), `
resource "aws_instance" "test" {
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
instance_type = "t2.micro"
Expand All @@ -753,7 +753,7 @@ data "aws_instance" "test" {
}

func testAccInstanceDataSourceConfig_secondaryPrivateIPs(rName string) string {
return testAccLatestAmazonLinuxHvmEbsAmiConfig() + testAccAwsInstanceVpcConfigBasic(rName) + fmt.Sprintf(`
return composeConfig(testAccLatestAmazonLinuxHvmEbsAmiConfig(), testAccAwsInstanceVpcConfigBasic(rName), `
resource "aws_instance" "test" {
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
instance_type = "t2.micro"
Expand Down Expand Up @@ -799,7 +799,7 @@ data "aws_instance" "test" {
}

func testAccInstanceDataSourceConfig_VPC(rName string) string {
return testAccLatestAmazonLinuxHvmEbsAmiConfig() + testAccAwsInstanceVpcConfigBasic(rName) + fmt.Sprintf(`
return composeConfig(testAccLatestAmazonLinuxHvmEbsAmiConfig(), testAccAwsInstanceVpcConfigBasic(rName), `
resource "aws_instance" "test" {
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
instance_type = "t2.small"
Expand Down Expand Up @@ -869,10 +869,10 @@ data "aws_instance" "test" {
}

func testAccInstanceDataSourceConfig_VPCSecurityGroups(rName string) string {
return testAccLatestAmazonLinuxHvmEbsAmiConfig() +
testAccAwsInstanceVpcConfigBasic(rName) +
testAccAwsInstanceVpcSecurityGroupConfig(rName) +
fmt.Sprintf(`
return composeConfig(testAccLatestAmazonLinuxHvmEbsAmiConfig(),
testAccAwsInstanceVpcConfigBasic(rName),
testAccAwsInstanceVpcSecurityGroupConfig(rName),
`
resource "aws_instance" "test" {
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
instance_type = "t2.micro"
Expand Down Expand Up @@ -945,7 +945,8 @@ data "aws_instance" "test" {
}

func testAccInstanceDataSourceConfig_creditSpecification(rName string) string {
return testAccLatestAmazonLinuxHvmEbsAmiConfig() + testAccAwsInstanceVpcConfigBasic(rName) + fmt.Sprintf(`
return composeConfig(testAccLatestAmazonLinuxHvmEbsAmiConfig(),
testAccAwsInstanceVpcConfigBasic(rName), `
resource "aws_instance" "test" {
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
instance_type = "t2.micro"
Expand Down
8 changes: 4 additions & 4 deletions aws/data_source_aws_neptune_engine_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ data "aws_neptune_engine_version" "test" {
}

func testAccAWSNeptuneEngineVersionDataSourcePreferredConfig() string {
return fmt.Sprintf(`
return `
data "aws_neptune_engine_version" "test" {
preferred_versions = ["85.9.12", "1.0.3.0", "1.0.2.2"]
}
`)
`
}

func testAccAWSNeptuneEngineVersionDataSourceDefaultOnlyConfig() string {
return fmt.Sprintf(`
return `
data "aws_neptune_engine_version" "test" {}
`)
`
}
12 changes: 6 additions & 6 deletions aws/data_source_aws_rds_engine_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,27 @@ data "aws_rds_engine_version" "test" {
}

func testAccAWSRDSEngineVersionDataSourceUpgradeTargetsConfig() string {
return fmt.Sprintf(`
return `
data "aws_rds_engine_version" "test" {
engine = "mysql"
version = "5.7.17"
}
`)
`
}

func testAccAWSRDSEngineVersionDataSourcePreferredConfig() string {
return fmt.Sprintf(`
return `
data "aws_rds_engine_version" "test" {
engine = "mysql"
preferred_versions = ["85.9.12", "5.7.19", "5.7.17"]
}
`)
`
}

func testAccAWSRDSEngineVersionDataSourceDefaultOnlyConfig() string {
return fmt.Sprintf(`
return `
data "aws_rds_engine_version" "test" {
engine = "mysql"
}
`)
`
}
28 changes: 14 additions & 14 deletions aws/data_source_aws_rds_orderable_db_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ data "aws_rds_orderable_db_instance" "test" {
}

func testAccAWSRdsOrderableDbInstanceDataSourceConfig_supportsEnhancedMonitoring() string {
return fmt.Sprintf(`
return `
data "aws_rds_orderable_db_instance" "test" {
engine = "mysql"
license_model = "general-public-license"
Expand All @@ -320,11 +320,11 @@ data "aws_rds_orderable_db_instance" "test" {
preferred_engine_versions = ["5.6.35", "5.6.41", "5.6.44"]
preferred_instance_classes = ["db.t2.small", "db.t3.medium", "db.t3.large"]
}
`)
`
}

func testAccAWSRdsOrderableDbInstanceDataSourceConfig_supportsIAMDatabaseAuthentication() string {
return fmt.Sprintf(`
return `
data "aws_rds_orderable_db_instance" "test" {
engine = "mysql"
license_model = "general-public-license"
Expand All @@ -334,11 +334,11 @@ data "aws_rds_orderable_db_instance" "test" {
preferred_engine_versions = ["5.6.35", "5.6.41", "5.6.44"]
preferred_instance_classes = ["db.t2.small", "db.t3.medium", "db.t3.large"]
}
`)
`
}

func testAccAWSRdsOrderableDbInstanceDataSourceConfig_supportsIops() string {
return fmt.Sprintf(`
return `
data "aws_rds_orderable_db_instance" "test" {
engine = "mysql"
license_model = "general-public-license"
Expand All @@ -347,11 +347,11 @@ data "aws_rds_orderable_db_instance" "test" {
preferred_engine_versions = ["8.0.20", "8.0.19", "8.0.17"]
preferred_instance_classes = ["db.t3.small", "db.t2.xlarge", "db.t2.small"]
}
`)
`
}

func testAccAWSRdsOrderableDbInstanceDataSourceConfig_supportsKerberosAuthentication() string {
return fmt.Sprintf(`
return `
data "aws_rds_orderable_db_instance" "test" {
engine = "postgres"
license_model = "postgresql-license"
Expand All @@ -361,11 +361,11 @@ data "aws_rds_orderable_db_instance" "test" {
preferred_engine_versions = ["12.3", "11.1", "10.13"]
preferred_instance_classes = ["db.m5.xlarge", "db.r5.large", "db.t3.large"]
}
`)
`
}

func testAccAWSRdsOrderableDbInstanceDataSourceConfig_supportsPerformanceInsights() string {
return fmt.Sprintf(`
return `
data "aws_rds_orderable_db_instance" "test" {
engine = "mysql"
license_model = "general-public-license"
Expand All @@ -374,11 +374,11 @@ data "aws_rds_orderable_db_instance" "test" {
preferred_engine_versions = ["5.6.35", "5.6.41", "5.6.44"]
preferred_instance_classes = ["db.t2.small", "db.t3.medium", "db.t3.large"]
}
`)
`
}

func testAccAWSRdsOrderableDbInstanceDataSourceConfig_supportsStorageAutoscaling() string {
return fmt.Sprintf(`
return `
data "aws_rds_orderable_db_instance" "test" {
engine = "mysql"
license_model = "general-public-license"
Expand All @@ -387,11 +387,11 @@ data "aws_rds_orderable_db_instance" "test" {
preferred_engine_versions = ["8.0.20", "8.0.19", "5.7.30"]
preferred_instance_classes = ["db.t3.medium", "db.t2.large", "db.t3.xlarge"]
}
`)
`
}

func testAccAWSRdsOrderableDbInstanceDataSourceConfig_supportsStorageEncryption() string {
return fmt.Sprintf(`
return `
data "aws_rds_orderable_db_instance" "test" {
engine = "mysql"
license_model = "general-public-license"
Expand All @@ -401,5 +401,5 @@ data "aws_rds_orderable_db_instance" "test" {
preferred_engine_versions = ["5.6.35", "5.6.41", "5.6.44"]
preferred_instance_classes = ["db.t2.small", "db.t3.medium", "db.t3.large"]
}
`)
`
}
4 changes: 2 additions & 2 deletions aws/data_source_aws_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ data "aws_route" "test" {
}

func testAccAWSRouteDataSourceConfigLocalGatewayID() string {
return fmt.Sprintf(`
return `
data "aws_ec2_local_gateways" "all" {}
data "aws_ec2_local_gateway" "first" {
id = tolist(data.aws_ec2_local_gateways.all.ids)[0]
Expand Down Expand Up @@ -286,5 +286,5 @@ data "aws_route" "by_local_gateway_id" {
local_gateway_id = data.aws_ec2_local_gateway.first.id
depends_on = [aws_route.test]
}
`)
`
}
Loading

0 comments on commit 0ed3e50

Please sign in to comment.