Skip to content

Commit

Permalink
chore: fix errors found when updating the static check library (#1075)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
zucchinidev and FelisiaM authored Aug 22, 2024
1 parent b52a023 commit 4c35683
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 21 deletions.
9 changes: 5 additions & 4 deletions brokerapi/broker/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package broker_test
import (
"context"
"encoding/json"
"errors"
"fmt"

"code.cloudfoundry.org/lager/v3"
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
7 changes: 4 additions & 3 deletions brokerapi/broker/unbind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package broker_test

import (
"context"
"errors"
"fmt"

"code.cloudfoundry.org/lager/v3"
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/tf/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/providers/tf/deprovision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tf_test

import (
"context"
"errors"
"fmt"

"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -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"))},
Expand All @@ -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{},
Expand All @@ -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{},
Expand All @@ -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"))},
Expand Down
11 changes: 6 additions & 5 deletions pkg/providers/tf/unbind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tf_test

import (
"context"
"errors"
"fmt"

"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/tf/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4c35683

Please sign in to comment.