Skip to content

Commit

Permalink
provider: Fix updated govet composites and nilness checks
Browse files Browse the repository at this point in the history
Reference: #7992
  • Loading branch information
bflad committed Mar 18, 2019
1 parent ffbd247 commit cc2f4d4
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 64 deletions.
13 changes: 10 additions & 3 deletions aws/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ import (
func TestGetSupportedEC2Platforms(t *testing.T) {
ec2Endpoints := []*awsbase.MockEndpoint{
{
Request: &awsbase.MockRequest{"POST", "/", "Action=DescribeAccountAttributes&" +
"AttributeName.1=supported-platforms&Version=2016-11-15"},
Response: &awsbase.MockResponse{200, test_ec2_describeAccountAttributes_response, "text/xml"},
Request: &awsbase.MockRequest{
Method: "POST",
Uri: "/",
Body: "Action=DescribeAccountAttributes&AttributeName.1=supported-platforms&Version=2016-11-15",
},
Response: &awsbase.MockResponse{
StatusCode: 200,
Body: test_ec2_describeAccountAttributes_response,
ContentType: "text/xml",
},
},
}
closeFunc, sess, err := awsbase.GetMockedAwsApiSession("EC2", ec2Endpoints)
Expand Down
7 changes: 2 additions & 5 deletions aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1544,11 +1544,8 @@ func resourceAwsDbInstanceRetrieve(id string, conn *rds.RDS) (*rds.DBInstance, e
return nil, fmt.Errorf("Error retrieving DB Instances: %s", err)
}

if len(resp.DBInstances) != 1 ||
*resp.DBInstances[0].DBInstanceIdentifier != id {
if err != nil {
return nil, nil
}
if len(resp.DBInstances) != 1 || resp.DBInstances[0] == nil || aws.StringValue(resp.DBInstances[0].DBInstanceIdentifier) != id {
return nil, nil
}

return resp.DBInstances[0], nil
Expand Down
7 changes: 2 additions & 5 deletions aws/resource_aws_docdb_cluster_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,8 @@ func resourceAwsDocDBInstanceRetrieve(id string, conn *docdb.DocDB) (*docdb.DBIn
return nil, fmt.Errorf("Error retrieving DB Instances: %s", err)
}

if len(resp.DBInstances) != 1 ||
*resp.DBInstances[0].DBInstanceIdentifier != id {
if err != nil {
return nil, nil
}
if len(resp.DBInstances) != 1 || resp.DBInstances[0] == nil || aws.StringValue(resp.DBInstances[0].DBInstanceIdentifier) != id {
return nil, nil
}

return resp.DBInstances[0], nil
Expand Down
4 changes: 0 additions & 4 deletions aws/resource_aws_egress_only_internet_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ func resourceAwsEgressOnlyInternetGatewayCreate(d *schema.ResourceData, meta int

d.SetId(*resp.EgressOnlyInternetGateway.EgressOnlyInternetGatewayId)

if err != nil {
return fmt.Errorf("%s", err)
}

return resourceAwsEgressOnlyInternetGatewayRead(d, meta)
}

Expand Down
17 changes: 8 additions & 9 deletions aws/resource_aws_emr_security_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,20 @@ func testAccCheckEmrSecurityConfigurationDestroy(s *terraform.State) error {
resp, err := conn.DescribeSecurityConfiguration(&emr.DescribeSecurityConfigurationInput{
Name: aws.String(rs.Primary.ID),
})
if err == nil {
if resp.Name != nil && *resp.Name == rs.Primary.ID {
// assume this means the resource still exists
return fmt.Errorf("Error: EMR Security Configuration still exists: %s", *resp.Name)
}

if isAWSErr(err, "InvalidRequestException", "does not exist") {
return nil
}

// Verify the error is what we want
if err != nil {
if isAWSErr(err, "InvalidRequestException", "does not exist") {
return nil
}
return err
}

if resp != nil && aws.StringValue(resp.Name) == rs.Primary.ID {
return fmt.Errorf("Error: EMR Security Configuration still exists: %s", aws.StringValue(resp.Name))
}

return nil
}

return nil
Expand Down
17 changes: 5 additions & 12 deletions aws/resource_aws_gamelift_game_session_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ func testSweepGameliftGameSessionQueue(region string) error {

out, err := conn.DescribeGameSessionQueues(&gamelift.DescribeGameSessionQueuesInput{})

if testSweepSkipSweepError(err) {
log.Printf("[WARN] Skipping Gamelife Queue sweep for %s: %s", region, err)
return nil
}

if err != nil {
if testSweepSkipSweepError(err) {
log.Printf("[WARN] Skipping Gamelife Queue sweep for %s: %s", region, err)
return nil
}
return fmt.Errorf("error listing Gamelift Session Queue: %s", err)
}

Expand All @@ -57,14 +58,6 @@ func testSweepGameliftGameSessionQueue(region string) error {
}
}

if err != nil {
if testSweepSkipSweepError(err) {
log.Printf("[WARN] Skipping Gamelift Session Queue sweep for %s: %s", region, err)
return nil
}
return fmt.Errorf("error listing Gamelift Session Queue: %s", err)
}

return nil
}

Expand Down
9 changes: 5 additions & 4 deletions aws/resource_aws_organizations_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ func testAccCheckAwsOrganizationsAccountDestroy(s *terraform.State) error {

resp, err := conn.DescribeAccount(params)

if isAWSErr(err, organizations.ErrCodeAccountNotFoundException, "") {
return nil
}

if err != nil {
if isAWSErr(err, organizations.ErrCodeAccountNotFoundException, "") {
return nil
}
return err
}

if resp == nil && resp.Account != nil {
if resp != nil && resp.Account != nil {
return fmt.Errorf("Bad: Account still exists: %q", rs.Primary.ID)
}
}
Expand Down
9 changes: 5 additions & 4 deletions aws/resource_aws_organizations_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ func testAccCheckAwsOrganizationsPolicyDestroy(s *terraform.State) error {

resp, err := conn.DescribePolicy(input)

if isAWSErr(err, organizations.ErrCodePolicyNotFoundException, "") {
return nil
}

if err != nil {
if isAWSErr(err, organizations.ErrCodePolicyNotFoundException, "") {
return nil
}
return err
}

if resp == nil && resp.Policy != nil {
if resp != nil && resp.Policy != nil {
return fmt.Errorf("Policy %q still exists", rs.Primary.ID)
}
}
Expand Down
8 changes: 2 additions & 6 deletions aws/resource_aws_vpn_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,9 @@ func testAccAWSVpnConnectionDisappears(connection *ec2.VpnConnection) resource.T
_, err := conn.DeleteVpnConnection(&ec2.DeleteVpnConnectionInput{
VpnConnectionId: connection.VpnConnectionId,
})

if err != nil {
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpnConnectionID.NotFound" {
return nil
}
if err != nil {
return err
}
return err
}

return resource.Retry(40*time.Minute, func() *resource.RetryError {
Expand Down
13 changes: 1 addition & 12 deletions aws/resource_aws_vpn_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,7 @@ func testAccAWSVpnGatewayDisappears(gateway *ec2.VpnGateway) resource.TestCheckF
VpcId: gateway.VpcAttachments[0].VpcId,
})
if err != nil {
ec2err, ok := err.(awserr.Error)
if ok {
if ec2err.Code() == "InvalidVpnGatewayID.NotFound" {
return nil
} else if ec2err.Code() == "InvalidVpnGatewayAttachment.NotFound" {
return nil
}
}

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

opts := &ec2.DeleteVpnGatewayInput{
Expand Down

0 comments on commit cc2f4d4

Please sign in to comment.