From 4c35683c9958741b312462a0f13490422da6c3b8 Mon Sep 17 00:00:00 2001 From: Andrea Zucchini Date: Thu, 22 Aug 2024 10:57:41 +0100 Subject: [PATCH] chore: fix errors found when updating the static check library (#1075) * chore: manual update tools to fix errors after staticcheck is applied * chore: printf without parameters is not valid [#187876023](https://www.pivotaltracker.com/story/show/187876023) * chore: omit redundant nil check on slice when checking its length --------- Co-authored-by: Felisia Martini --- brokerapi/broker/bind_test.go | 9 +++++---- brokerapi/broker/unbind_test.go | 7 ++++--- go.mod | 6 +++--- go.sum | 6 ++++++ pkg/providers/tf/definition.go | 2 +- pkg/providers/tf/deprovision_test.go | 9 +++++---- pkg/providers/tf/unbind_test.go | 11 ++++++----- pkg/providers/tf/upgrade.go | 2 +- 8 files changed, 31 insertions(+), 21 deletions(-) diff --git a/brokerapi/broker/bind_test.go b/brokerapi/broker/bind_test.go index d02f4fd2e..48cf19cd8 100644 --- a/brokerapi/broker/bind_test.go +++ b/brokerapi/broker/bind_test.go @@ -3,6 +3,7 @@ package broker_test import ( "context" "encoding/json" + "errors" "fmt" "code.cloudfoundry.org/lager/v3" @@ -322,7 +323,7 @@ var _ = Describe("Bind", func() { const saveError = "credential-save-error" BeforeEach(func() { - fakeStorage.CreateServiceBindingCredentialsReturns(fmt.Errorf(saveError)) + fakeStorage.CreateServiceBindingCredentialsReturns(errors.New(saveError)) }) It("should error", func() { @@ -336,7 +337,7 @@ var _ = Describe("Bind", func() { const saveBindRequestError = "bind-request-save-error" BeforeEach(func() { - fakeStorage.StoreBindRequestDetailsReturns(fmt.Errorf(saveBindRequestError)) + fakeStorage.StoreBindRequestDetailsReturns(errors.New(saveBindRequestError)) }) It("should error", func() { @@ -350,7 +351,7 @@ var _ = Describe("Bind", func() { const credstoreError = "credstore-error" BeforeEach(func() { - fakeCredStore.PutReturns(nil, fmt.Errorf(credstoreError)) + fakeCredStore.PutReturns(nil, errors.New(credstoreError)) }) It("should error", func() { @@ -364,7 +365,7 @@ var _ = Describe("Bind", func() { const credstorePermissionError = "credstore-error-permissions" BeforeEach(func() { - fakeCredStore.AddPermissionReturns(nil, fmt.Errorf(credstorePermissionError)) + fakeCredStore.AddPermissionReturns(nil, errors.New(credstorePermissionError)) }) It("should error", func() { diff --git a/brokerapi/broker/unbind_test.go b/brokerapi/broker/unbind_test.go index 87c580660..c59b2b1bb 100644 --- a/brokerapi/broker/unbind_test.go +++ b/brokerapi/broker/unbind_test.go @@ -2,6 +2,7 @@ package broker_test import ( "context" + "errors" "fmt" "code.cloudfoundry.org/lager/v3" @@ -345,7 +346,7 @@ var _ = Describe("Unbind", func() { const deleteError = "credential-delete-error" BeforeEach(func() { - fakeStorage.DeleteServiceBindingCredentialsReturns(fmt.Errorf(deleteError)) + fakeStorage.DeleteServiceBindingCredentialsReturns(errors.New(deleteError)) }) It("should error", func() { @@ -359,7 +360,7 @@ var _ = Describe("Unbind", func() { const deleteError = "bind-details-delete-error" BeforeEach(func() { - fakeStorage.DeleteBindRequestDetailsReturns(fmt.Errorf(deleteError)) + fakeStorage.DeleteBindRequestDetailsReturns(errors.New(deleteError)) }) It("should error", func() { @@ -373,7 +374,7 @@ var _ = Describe("Unbind", func() { const deleteError = "bind-provider-details-delete-error" BeforeEach(func() { - fakeServiceProvider.DeleteBindingDataReturns(fmt.Errorf(deleteError)) + fakeServiceProvider.DeleteBindingDataReturns(errors.New(deleteError)) }) It("should error", func() { diff --git a/go.mod b/go.mod index 5136be622..8abf0aa20 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( gorm.io/driver/mysql v1.5.7 gorm.io/driver/sqlite v1.4.4 gorm.io/gorm v1.25.11 - honnef.co/go/tools v0.4.7 + honnef.co/go/tools v0.5.1 ) require ( @@ -43,7 +43,7 @@ require ( cloud.google.com/go/iam v1.1.6 // indirect cloud.google.com/go/storage v1.38.0 // indirect filippo.io/edwards25519 v1.1.0 // indirect - github.com/BurntSushi/toml v1.2.1 // indirect + github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c // indirect github.com/agext/levenshtein v1.2.2 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/aws/aws-sdk-go v1.44.122 // indirect @@ -115,7 +115,7 @@ require ( go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.9.0 // indirect golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect - golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect + golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678 // indirect golang.org/x/mod v0.20.0 // indirect golang.org/x/oauth2 v0.18.0 // indirect golang.org/x/sync v0.8.0 // indirect diff --git a/go.sum b/go.sum index 9e05c8b4c..c06086ef2 100644 --- a/go.sum +++ b/go.sum @@ -197,6 +197,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs= +github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= @@ -676,6 +678,8 @@ golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeId golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE= golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= +golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678 h1:1P7xPZEwZMoBoz0Yze5Nx2/4pxj6nw9ZqHWXqP0iRgQ= +golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -1244,6 +1248,8 @@ honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9 honnef.co/go/tools v0.4.0-0.dev/go.mod h1:vlRD9XErLMGT+mDuofSr0mMMquscM/1nQqtRSsh6m70= honnef.co/go/tools v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs= honnef.co/go/tools v0.4.7/go.mod h1:+rnGS1THNh8zMwnd2oVOTL9QF6vmfyG6ZXBULae2uc0= +honnef.co/go/tools v0.5.1 h1:4bH5o3b5ZULQ4UrBmP+63W9r7qIkqJClEA9ko5YKx+I= +honnef.co/go/tools v0.5.1/go.mod h1:e9irvo83WDG9/irijV44wr3tbhcFeRnfpVlRqVwpzMs= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/goversion v1.2.0 h1:SPn+NLTiAG7w30IRK/DKp1BjvpWabYgxlLp/+kx5J8w= rsc.io/goversion v1.2.0/go.mod h1:Eih9y/uIBS3ulggl7KNJ09xGSLcuNaLgmvvqa07sgfo= diff --git a/pkg/providers/tf/definition.go b/pkg/providers/tf/definition.go index 5d2140fc6..f1141ca31 100644 --- a/pkg/providers/tf/definition.go +++ b/pkg/providers/tf/definition.go @@ -205,7 +205,7 @@ func (tfb *TfServiceDefinitionV1) resolveEnvVars() (map[string]string, error) { for _, v := range tfb.RequiredEnvVars { _ = viper.BindEnv(v, v) if !viper.IsSet(v) { - return vars, fmt.Errorf(fmt.Sprintf("missing required env var %s", v)) + return vars, fmt.Errorf("missing required env var %s", v) } vars[v] = viper.GetString(v) } diff --git a/pkg/providers/tf/deprovision_test.go b/pkg/providers/tf/deprovision_test.go index feb2b9e69..e253e3b91 100644 --- a/pkg/providers/tf/deprovision_test.go +++ b/pkg/providers/tf/deprovision_test.go @@ -2,6 +2,7 @@ package tf_test import ( "context" + "errors" "fmt" "github.com/hashicorp/go-version" @@ -99,7 +100,7 @@ var _ = Describe("Deprovision", func() { }) It("fails, when unable to update the workspace HCL", func() { - fakeDeploymentManager.UpdateWorkspaceHCLReturns(fmt.Errorf(expectedError)) + fakeDeploymentManager.UpdateWorkspaceHCLReturns(errors.New(expectedError)) provider := tf.NewTerraformProvider( executor.TFBinariesContext{DefaultTfVersion: version.Must(version.NewVersion("1.6.0"))}, @@ -116,7 +117,7 @@ var _ = Describe("Deprovision", func() { }) It("fails, when unable to get the Terraform deployment", func() { - fakeDeploymentManager.GetTerraformDeploymentReturns(storage.TerraformDeployment{}, fmt.Errorf(expectedError)) + fakeDeploymentManager.GetTerraformDeploymentReturns(storage.TerraformDeployment{}, errors.New(expectedError)) provider := tf.NewTerraformProvider( executor.TFBinariesContext{}, @@ -134,7 +135,7 @@ var _ = Describe("Deprovision", func() { It("fails, when unable to mark operation as started", func() { fakeDeploymentManager.GetTerraformDeploymentReturns(deployment, nil) - fakeDeploymentManager.MarkOperationStartedReturns(fmt.Errorf(expectedError)) + fakeDeploymentManager.MarkOperationStartedReturns(errors.New(expectedError)) provider := tf.NewTerraformProvider( executor.TFBinariesContext{}, @@ -154,7 +155,7 @@ var _ = Describe("Deprovision", func() { fakeDeploymentManager.GetTerraformDeploymentReturns(deployment, nil) fakeDeploymentManager.MarkOperationStartedReturns(nil) fakeInvokerBuilder.VersionedTerraformInvokerReturns(fakeDefaultInvoker) - fakeDefaultInvoker.DestroyReturns(fmt.Errorf(expectedError)) + fakeDefaultInvoker.DestroyReturns(errors.New(expectedError)) provider := tf.NewTerraformProvider( executor.TFBinariesContext{DefaultTfVersion: version.Must(version.NewVersion("1.6.0"))}, diff --git a/pkg/providers/tf/unbind_test.go b/pkg/providers/tf/unbind_test.go index 0ac10fb09..ed24c5bec 100644 --- a/pkg/providers/tf/unbind_test.go +++ b/pkg/providers/tf/unbind_test.go @@ -2,6 +2,7 @@ package tf_test import ( "context" + "errors" "fmt" "github.com/hashicorp/go-version" @@ -108,7 +109,7 @@ var _ = Describe("Unbind", func() { }) It("fails, when unable to update the workspace HCL", func() { - fakeDeploymentManager.UpdateWorkspaceHCLReturns(fmt.Errorf(expectedError)) + fakeDeploymentManager.UpdateWorkspaceHCLReturns(errors.New(expectedError)) provider := tf.NewTerraformProvider(executor.TFBinariesContext{DefaultTfVersion: version.Must(version.NewVersion("1"))}, fakeInvokerBuilder, fakeLogger, fakeServiceDefinition, fakeDeploymentManager) @@ -117,7 +118,7 @@ var _ = Describe("Unbind", func() { }) It("fails, when unable to get the Terraform deployment", func() { - fakeDeploymentManager.GetTerraformDeploymentReturns(storage.TerraformDeployment{}, fmt.Errorf(expectedError)) + fakeDeploymentManager.GetTerraformDeploymentReturns(storage.TerraformDeployment{}, errors.New(expectedError)) provider := tf.NewTerraformProvider(executor.TFBinariesContext{}, fakeInvokerBuilder, fakeLogger, fakeServiceDefinition, fakeDeploymentManager) @@ -127,7 +128,7 @@ var _ = Describe("Unbind", func() { It("fails, when unable to mark operation as started", func() { fakeDeploymentManager.GetTerraformDeploymentReturns(deployment, nil) - fakeDeploymentManager.MarkOperationStartedReturns(fmt.Errorf(expectedError)) + fakeDeploymentManager.MarkOperationStartedReturns(errors.New(expectedError)) provider := tf.NewTerraformProvider(executor.TFBinariesContext{}, fakeInvokerBuilder, fakeLogger, fakeServiceDefinition, fakeDeploymentManager) @@ -139,8 +140,8 @@ var _ = Describe("Unbind", func() { fakeDeploymentManager.GetTerraformDeploymentReturns(deployment, nil) fakeDeploymentManager.MarkOperationStartedReturns(nil) fakeInvokerBuilder.VersionedTerraformInvokerReturns(fakeDefaultInvoker) - fakeDefaultInvoker.DestroyReturns(fmt.Errorf(expectedError)) - fakeDeploymentManager.OperationStatusReturns(true, "", fmt.Errorf(expectedError)) + fakeDefaultInvoker.DestroyReturns(errors.New(expectedError)) + fakeDeploymentManager.OperationStatusReturns(true, "", errors.New(expectedError)) provider := tf.NewTerraformProvider(executor.TFBinariesContext{DefaultTfVersion: version.Must(version.NewVersion("1"))}, fakeInvokerBuilder, fakeLogger, fakeServiceDefinition, fakeDeploymentManager) diff --git a/pkg/providers/tf/upgrade.go b/pkg/providers/tf/upgrade.go index 5c66947d6..c763185f2 100644 --- a/pkg/providers/tf/upgrade.go +++ b/pkg/providers/tf/upgrade.go @@ -107,7 +107,7 @@ func (provider *TerraformProvider) performTerraformUpgrade(ctx context.Context, if currentTfVersion.LessThan(version.Must(version.NewVersion("1.5.0"))) { return errors.New("upgrade only supported for Terraform versions >= 1.5.0") } else if currentTfVersion.LessThan(provider.tfBinContext.DefaultTfVersion) { - if provider.tfBinContext.TfUpgradePath == nil || len(provider.tfBinContext.TfUpgradePath) == 0 { + if len(provider.tfBinContext.TfUpgradePath) == 0 { return errors.New("tofu version mismatch and no upgrade path specified") } for _, targetTfVersion := range provider.tfBinContext.TfUpgradePath {