Skip to content

Commit

Permalink
Fix golangci-lint errors (#441)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and paddycarver committed Feb 15, 2019
1 parent 1e5511c commit ac5820a
Show file tree
Hide file tree
Showing 45 changed files with 199 additions and 93 deletions.
21 changes: 0 additions & 21 deletions .gometalinter.json

This file was deleted.

4 changes: 3 additions & 1 deletion google-beta/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ func TestSetOmittedFields(t *testing.T) {
},
}
output := &OutputOuter{}
Convert(input, output)
if err := Convert(input, output); err != nil {
t.Errorf("Error converting: %v", err)
}
if input.NotOmitted != output.NotOmitted ||
!reflect.DeepEqual(input.Omitted, output.Omitted) ||
!reflect.DeepEqual(input.Struct, output.Struct) ||
Expand Down
3 changes: 3 additions & 0 deletions google-beta/data_source_google_compute_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ func testAccCheckDataSourceComputeAddressDestroy(resource_name string) resource.
}

addressId, err := parseComputeAddressId(rs.Primary.ID, nil)
if err != nil {
return err
}

_, err = config.clientCompute.Addresses.Get(
config.Project, addressId.Region, addressId.Name).Do()
Expand Down
4 changes: 3 additions & 1 deletion google-beta/data_source_storage_object_signed_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ func SignString(toSign []byte, cfg *jwt.Config) ([]byte, error) {

// Hash string
hasher := sha256.New()
hasher.Write(toSign)
if _, err := hasher.Write(toSign); err != nil {
return nil, errwrap.Wrapf("failed to calculate sha256: {{err}}", err)
}

// Sign string
signed, err := rsa.SignPKCS1v15(rand.Reader, pk, crypto.SHA256, hasher.Sum(nil))
Expand Down
7 changes: 6 additions & 1 deletion google-beta/resource_access_context_manager_access_level.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ func resourceAccessContextManagerAccessLevelUpdate(d *schema.ResourceData, meta
}

obj, err = resourceAccessContextManagerAccessLevelEncoder(d, meta, obj)
if err != nil {
return err
}

url, err := replaceVars(d, config, "https://accesscontextmanager.googleapis.com/v1beta/{{name}}")
if err != nil {
Expand Down Expand Up @@ -377,7 +380,9 @@ func resourceAccessContextManagerAccessLevelImport(d *schema.ResourceData, meta
config := meta.(*Config)

// current import_formats can't import ids with forward slashes in them.
parseImportId([]string{"(?P<name>.+)"}, d, config)
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
return nil, err
}
stringParts := strings.Split(d.Get("name").(string), "/")
d.Set("parent", fmt.Sprintf("%s/%s", stringParts[0], stringParts[1]))
return []*schema.ResourceData{d}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ func resourceAccessContextManagerServicePerimeterUpdate(d *schema.ResourceData,
}

obj, err = resourceAccessContextManagerServicePerimeterEncoder(d, meta, obj)
if err != nil {
return err
}

url, err := replaceVars(d, config, "https://accesscontextmanager.googleapis.com/v1beta/{{name}}")
if err != nil {
Expand Down Expand Up @@ -351,7 +354,9 @@ func resourceAccessContextManagerServicePerimeterImport(d *schema.ResourceData,
config := meta.(*Config)

// current import_formats can't import ids with forward slashes in them.
parseImportId([]string{"(?P<name>.+)"}, d, config)
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
return nil, err
}
stringParts := strings.Split(d.Get("name").(string), "/")
d.Set("parent", fmt.Sprintf("%s/%s", stringParts[0], stringParts[1]))
return []*schema.ResourceData{d}, nil
Expand Down
4 changes: 3 additions & 1 deletion google-beta/resource_composer_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,9 @@ func resourceComposerEnvironmentDelete(d *schema.ResourceData, meta interface{})

func resourceComposerEnvironmentImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
parseImportId([]string{"projects/(?P<project>[^/]+)/locations/(?P<region>[^/]+)/environments/(?P<name>[^/]+)", "(?P<project>[^/]+)/(?P<region>[^/]+)/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config)
if err := parseImportId([]string{"projects/(?P<project>[^/]+)/locations/(?P<region>[^/]+)/environments/(?P<name>[^/]+)", "(?P<project>[^/]+)/(?P<region>[^/]+)/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config); err != nil {
return nil, err
}

// Replace import id for the resource id
id, err := replaceVars(d, config, "{{project}}/{{region}}/{{name}}")
Expand Down
3 changes: 3 additions & 0 deletions google-beta/resource_compute_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ func resourceComputeAddressCreate(d *schema.ResourceData, meta interface{}) erro
obj := make(map[string]interface{})
// d.Get("labels") will have been overridden by the Read call.
labelsProp, err := expandComputeAddressLabels(v, d, config)
if err != nil {
return err
}
obj["labels"] = labelsProp
labelFingerprintProp := d.Get("label_fingerprint")
obj["labelFingerprint"] = labelFingerprintProp
Expand Down
3 changes: 3 additions & 0 deletions google-beta/resource_compute_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ func resourceComputeBackendServiceCreate(d *schema.ResourceData, meta interface{

if v, ok := d.GetOk("security_policy"); ok {
pol, err := ParseSecurityPolicyFieldValue(v.(string), d, config)
if err != nil {
return errwrap.Wrapf("Error parsing Backend Service security policy: {{err}}", err)
}
op, err := config.clientComputeBeta.BackendServices.SetSecurityPolicy(
project, service.Name, &computeBeta.SecurityPolicyReference{
SecurityPolicy: pol.RelativeLink(),
Expand Down
2 changes: 1 addition & 1 deletion google-beta/resource_compute_firewall_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestComputeFirewallMigrateState_empty(t *testing.T) {

// should handle non-nil but empty
is = &terraform.InstanceState{}
is, err = resourceComputeFirewallMigrateState(0, is, meta)
_, err = resourceComputeFirewallMigrateState(0, is, meta)

if err != nil {
t.Fatalf("err: %#v", err)
Expand Down
3 changes: 3 additions & 0 deletions google-beta/resource_compute_forwarding_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ func resourceComputeForwardingRuleCreate(d *schema.ResourceData, meta interface{
obj := make(map[string]interface{})
// d.Get("labels") will have been overridden by the Read call.
labelsProp, err := expandComputeForwardingRuleLabels(v, d, config)
if err != nil {
return err
}
obj["labels"] = labelsProp
labelFingerprintProp := d.Get("label_fingerprint")
obj["labelFingerprint"] = labelFingerprintProp
Expand Down
3 changes: 3 additions & 0 deletions google-beta/resource_compute_global_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ func resourceComputeGlobalAddressCreate(d *schema.ResourceData, meta interface{}
obj := make(map[string]interface{})
// d.Get("labels") will have been overridden by the Read call.
labelsProp, err := expandComputeGlobalAddressLabels(v, d, config)
if err != nil {
return err
}
obj["labels"] = labelsProp
labelFingerprintProp := d.Get("label_fingerprint")
obj["labelFingerprint"] = labelFingerprintProp
Expand Down
3 changes: 3 additions & 0 deletions google-beta/resource_compute_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ func resourceComputeHealthCheckUpdate(d *schema.ResourceData, meta interface{})
}

obj, err = resourceComputeHealthCheckEncoder(d, meta, obj)
if err != nil {
return err
}

url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/global/healthChecks/{{name}}")
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions google-beta/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,8 +1024,6 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
instNetworkInterface := instance.NetworkInterfaces[i]
networkName := d.Get(prefix + ".name").(string)

// TODO: This sanity check is broken by #929, disabled for now (by forcing the equality)
networkName = instNetworkInterface.Name
// Sanity check
if networkName != instNetworkInterface.Name {
return fmt.Errorf("Instance networkInterface had unexpected name: %s", instNetworkInterface.Name)
Expand Down
4 changes: 2 additions & 2 deletions google-beta/resource_compute_instance_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,9 @@ func resourceComputeInstanceGroupManagerDelete(d *schema.ResourceData, meta inte
return err
}

instanceGroup, err := config.clientComputeBeta.InstanceGroups.Get(
instanceGroup, igErr := config.clientComputeBeta.InstanceGroups.Get(
project, zone, name).Do()
if err != nil {
if igErr != nil {
return fmt.Errorf("Error getting instance group size: %s", err)
}

Expand Down
4 changes: 2 additions & 2 deletions google-beta/resource_compute_instance_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestComputeInstanceMigrateState_empty(t *testing.T) {

// should handle non-nil but empty
is = &terraform.InstanceState{}
is, err = resourceComputeInstanceMigrateState(0, is, meta)
_, err = resourceComputeInstanceMigrateState(0, is, meta)

if err != nil {
t.Fatalf("err: %#v", err)
Expand Down Expand Up @@ -841,7 +841,7 @@ func runInstanceMigrateTest(t *testing.T, id, testName string, version int, attr
ID: id,
Attributes: attributes,
}
is, err := resourceComputeInstanceMigrateState(version, is, meta)
_, err := resourceComputeInstanceMigrateState(version, is, meta)
if err != nil {
t.Fatal(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func TestComputeInstanceTemplateMigrateState_empty(t *testing.T) {

// should handle non-nil but empty
is = &terraform.InstanceState{}
is, err = resourceComputeInstanceTemplateMigrateState(0, is, meta)
_, err = resourceComputeInstanceTemplateMigrateState(0, is, meta)

if err != nil {
t.Fatalf("err: %#v", err)
Expand Down
3 changes: 3 additions & 0 deletions google-beta/resource_compute_region_instance_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@ func resourceComputeRegionInstanceGroupManagerDelete(d *schema.ResourceData, met

// Wait for the operation to complete
err = computeSharedOperationWaitTime(config.clientCompute, op, regionalID.Project, int(d.Timeout(schema.TimeoutDelete).Minutes()), "Deleting RegionInstanceGroupManager")
if err != nil {
return fmt.Errorf("Error waiting for delete to complete: %s", err)
}

d.SetId("")
return nil
Expand Down
3 changes: 3 additions & 0 deletions google-beta/resource_compute_ssl_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ func resourceComputeSslPolicyUpdate(d *schema.ResourceData, meta interface{}) er
}

obj, err = resourceComputeSslPolicyUpdateEncoder(d, meta, obj)
if err != nil {
return err
}

url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/global/sslPolicies/{{name}}")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion google-beta/resource_container_cluster_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestContainerClusterMigrateState_empty(t *testing.T) {

// should handle non-nil but empty
is = &terraform.InstanceState{}
is, err = resourceContainerClusterMigrateState(0, is, meta)
_, err = resourceContainerClusterMigrateState(0, is, meta)

if err != nil {
t.Fatalf("err: %#v", err)
Expand Down
5 changes: 3 additions & 2 deletions google-beta/resource_container_node_pool_migrate_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package google

import (
"github.com/hashicorp/terraform/terraform"
"testing"

"github.com/hashicorp/terraform/terraform"
)

func TestContainerNodePoolMigrateState(t *testing.T) {
Expand Down Expand Up @@ -57,7 +58,7 @@ func TestContainerNodePoolMigrateState_empty(t *testing.T) {

// should handle non-nil but empty
is = &terraform.InstanceState{}
is, err = resourceContainerNodePoolMigrateState(0, is, meta)
_, err = resourceContainerNodePoolMigrateState(0, is, meta)

if err != nil {
t.Fatalf("err: %#v", err)
Expand Down
6 changes: 4 additions & 2 deletions google-beta/resource_dataproc_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,10 @@ func resourceDataprocJobDelete(d *schema.ResourceData, meta interface{}) error {
if forceDelete {
log.Printf("[DEBUG] Attempting to first cancel Dataproc job %s if it's still running ...", d.Id())

config.clientDataproc.Projects.Regions.Jobs.Cancel(
project, region, d.Id(), &dataproc.CancelJobRequest{}).Do()
if _, err := config.clientDataproc.Projects.Regions.Jobs.Cancel(
project, region, d.Id(), &dataproc.CancelJobRequest{}).Do(); err != nil {
return fmt.Errorf("Error canceling job: %v", err)
}
// ignore error if we get one - job may be finished already and not need to
// be cancelled. We do however wait for the state to be one that is
// at least not active
Expand Down
5 changes: 4 additions & 1 deletion google-beta/resource_endpoints_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/base64"
"encoding/json"
"errors"

"github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/servicemanagement/v1"
)
Expand Down Expand Up @@ -228,7 +229,9 @@ func resourceEndpointsServiceUpdate(d *schema.ResourceData, meta interface{}) er
return err
}
var serviceConfig servicemanagement.SubmitConfigSourceResponse
json.Unmarshal(s, &serviceConfig)
if err := json.Unmarshal(s, &serviceConfig); err != nil {
return err
}

// Next, we create a new rollout with the new config value, and wait for it to complete.
rolloutService := servicemanagement.NewServicesRolloutsService(config.clientServiceMan)
Expand Down
2 changes: 1 addition & 1 deletion google-beta/resource_google_project_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestGoogleProjectMigrateState_empty(t *testing.T) {

// should handle non-nil but empty
is = &terraform.InstanceState{}
is, err = resourceGoogleProjectMigrateState(0, is, meta)
_, err = resourceGoogleProjectMigrateState(0, is, meta)

if err != nil {
t.Fatalf("err: %#v", err)
Expand Down
4 changes: 3 additions & 1 deletion google-beta/resource_google_project_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func resourceGoogleProjectServicesDelete(d *schema.ResourceData, meta interface{
config := meta.(*Config)
services := resourceServices(d)
for _, s := range services {
disableService(s, d.Id(), config, true)
if err := disableService(s, d.Id(), config, true); err != nil {
return err
}
}
d.SetId("")
return nil
Expand Down
12 changes: 9 additions & 3 deletions google-beta/resource_google_project_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ func TestAccProjectServices_basic(t *testing.T) {
{
PreConfig: func() {
config := testAccProvider.Meta().(*Config)
enableService(oobService, pid, config)
if err := enableService(oobService, pid, config); err != nil {
t.Fatalf("Error enabling %q: %v", oobService, err)
}
},
Config: testAccProjectAssociateServicesBasic(services2, pid, pname, org),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -87,7 +89,9 @@ func TestAccProjectServices_authoritative(t *testing.T) {
{
PreConfig: func() {
config := testAccProvider.Meta().(*Config)
enableService(oobService, pid, config)
if err := enableService(oobService, pid, config); err != nil {
t.Fatalf("Error enabling %q: %v", oobService, err)
}
},
Config: testAccProjectAssociateServicesBasic(services, pid, pname, org),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -126,7 +130,9 @@ func TestAccProjectServices_authoritative2(t *testing.T) {
PreConfig: func() {
config := testAccProvider.Meta().(*Config)
for _, s := range oobServices {
enableService(s, pid, config)
if err := enableService(s, pid, config); err != nil {
t.Fatalf("Error enabling %q: %v", s, err)
}
}
},
Config: testAccProjectAssociateServicesBasic(services, pid, pname, org),
Expand Down
6 changes: 4 additions & 2 deletions google-beta/resource_google_service_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,12 @@ func resourceGoogleServiceAccountUpdate(d *schema.ResourceData, meta interface{}

func resourceGoogleServiceAccountImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
parseImportId([]string{
if err := parseImportId([]string{
"projects/(?P<project>[^/]+)/serviceAccounts/(?P<email>[^/]+)",
"(?P<project>[^/]+)/(?P<email>[^/]+)",
"(?P<email>[^/]+)"}, d, config)
"(?P<email>[^/]+)"}, d, config); err != nil {
return nil, err
}

// Replace import id for the resource id
id, err := replaceVars(d, config, "projects/{{project}}/serviceAccounts/{{email}}")
Expand Down
4 changes: 3 additions & 1 deletion google-beta/resource_monitoring_alert_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,9 @@ func resourceMonitoringAlertPolicyImport(d *schema.ResourceData, meta interface{
config := meta.(*Config)

// current import_formats can't import id's with forward slashes in them.
parseImportId([]string{"(?P<name>.+)"}, d, config)
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
return nil, err
}

return []*schema.ResourceData{d}, nil
}
Expand Down
4 changes: 3 additions & 1 deletion google-beta/resource_monitoring_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ func resourceMonitoringGroupImport(d *schema.ResourceData, meta interface{}) ([]
config := meta.(*Config)

// current import_formats can't import id's with forward slashes in them.
parseImportId([]string{"(?P<name>.+)"}, d, config)
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
return nil, err
}

return []*schema.ResourceData{d}, nil
}
Expand Down
4 changes: 3 additions & 1 deletion google-beta/resource_monitoring_notification_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ func resourceMonitoringNotificationChannelImport(d *schema.ResourceData, meta in
config := meta.(*Config)

// current import_formats can't import id's with forward slashes in them.
parseImportId([]string{"(?P<name>.+)"}, d, config)
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
return nil, err
}

return []*schema.ResourceData{d}, nil
}
Expand Down
Loading

0 comments on commit ac5820a

Please sign in to comment.