Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to golangci-lint meta-lint tool #272

Merged
merged 3 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# https://github.com/golangci/golangci-lint#config-file
run:
timeout: 5m
skip-dirs:
- tmp
- integration
skip-files:
# explicitly skip files containing '// Code generated by counterfeiter. DO NOT EDIT.'
- agent/action/fakes/fake_clock.go
- agent/action/fakes/fake_clock.go
- agent/agentfakes/fake_start_manager.go
- agent/applier/bundlecollection/fakes/fake_clock.go
- agent/applier/jobs/jobsfakes/fake_applier.go
- agent/blobstore/blobstorefakes/fake_blob_manager_interface.go
- agent/httpblobprovider/blobstore_delegator/blobstore_delegatorfakes/fake_blobstore_delegator.go
- agent/httpblobprovider/httpblobproviderfakes/fake_httpblob_provider.go
- agent/script/drain/drainfakes/fake_script_params.go
- agent/script/scriptfakes/fake_cancellable_script.go
- agent/script/scriptfakes/fake_job_script_provider.go
- agent/script/scriptfakes/fake_script.go
- agent/tarpath/tarpathfakes/fake_detector.go
- agent/utils/utilsfakes/fake_killer.go
- agentclient/fakes/fake_agent_client.go
- jobsupervisor/monit/monitfakes/fake_httpclient.go
- jobsupervisor/monit/monitfakes/fake_request_retryable.go
- mbus/mbusfakes/fake_nats_connection.go
- platform/cert/certfakes/fake_manager.go
- platform/disk/diskfakes/fake_manager.go
- platform/disk/diskfakes/fake_mounter.go
- platform/fakes/fake_windows_disk_manager.go
- platform/net/netfakes/fake_macaddress_detector.go
- platform/openiscsi/openiscsifakes/fake_open_iscsi.go
- platform/platformfakes/fake_audit_logger.go
- platform/platformfakes/fake_platform.go
- platform/vitals/vitalsfakes/fake_service.go
- platform/windows/disk/fakes/fake_windows_disk_formatter.go
- platform/windows/disk/fakes/fake_windows_disk_linker.go
- platform/windows/disk/fakes/fake_windows_disk_partitioner.go
- platform/windows/disk/fakes/fake_windows_disk_protector.go
- settings/settingsfakes/fake_platform_settings_getter.go
- vendor/github.com/cloudfoundry/bosh-utils/logger/loggerfakes/fake_logger.go
- vendor/github.com/maxbrunsfeld/counterfeiter/v6/generator/function_template.go
- vendor/github.com/maxbrunsfeld/counterfeiter/v6/generator/interface_template.go
- vendor/github.com/maxbrunsfeld/counterfeiter/v6/generator/package_template.go

linters-settings:
dogsled:
max-blank-identifiers: 5
funlen:
lines: 200
statements: 90

output:
# Sort results by: filepath, line and column.
sort-results: true
1 change: 1 addition & 0 deletions agent/action/add_persistent_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package action

import (
"errors"

boshsettings "github.com/cloudfoundry/bosh-agent/settings"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
Expand Down
52 changes: 26 additions & 26 deletions agent/action/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

. "github.com/cloudfoundry/bosh-agent/agent/action"
"github.com/cloudfoundry/bosh-agent/agent/action"
boshas "github.com/cloudfoundry/bosh-agent/agent/applier/applyspec"
fakeas "github.com/cloudfoundry/bosh-agent/agent/applier/applyspec/fakes"
fakeappl "github.com/cloudfoundry/bosh-agent/agent/applier/fakes"
Expand All @@ -24,7 +24,7 @@ var _ = Describe("ApplyAction", func() {
specService *fakeas.FakeV1Service
settingsService *fakesettings.FakeSettingsService
dirProvider boshdir.Provider
action ApplyAction
applyAction action.ApplyAction
fs boshsys.FileSystem
)

Expand All @@ -34,14 +34,14 @@ var _ = Describe("ApplyAction", func() {
settingsService = &fakesettings.FakeSettingsService{}
dirProvider = boshdir.NewProvider("/var/vcap")
fs = fakesys.NewFakeFileSystem()
action = NewApply(applier, specService, settingsService, dirProvider, fs)
applyAction = action.NewApply(applier, specService, settingsService, dirProvider, fs)
})

AssertActionIsAsynchronous(action)
AssertActionIsNotPersistent(action)
AssertActionIsLoggable(action)
AssertActionIsNotCancelable(action)
AssertActionIsNotResumable(action)
AssertActionIsAsynchronous(applyAction)
AssertActionIsNotPersistent(applyAction)
AssertActionIsLoggable(applyAction)
AssertActionIsNotCancelable(applyAction)
AssertActionIsNotResumable(applyAction)

Describe("Run", func() {
settings := boshsettings.Settings{AgentID: "fake-agent-id"}
Expand All @@ -63,7 +63,7 @@ var _ = Describe("ApplyAction", func() {
})

It("populates dynamic networks in desired spec", func() {
_, err := action.Run(desiredApplySpec)
_, err := applyAction.Run(desiredApplySpec)
Expect(err).ToNot(HaveOccurred())
Expect(specService.PopulateDHCPNetworksSpec).To(Equal(desiredApplySpec))
Expect(specService.PopulateDHCPNetworksSettings).To(Equal(settings))
Expand All @@ -75,7 +75,7 @@ var _ = Describe("ApplyAction", func() {
})

It("runs applier with populated desired spec", func() {
_, err := action.Run(desiredApplySpec)
_, err := applyAction.Run(desiredApplySpec)
Expect(err).ToNot(HaveOccurred())
Expect(applier.Applied).To(BeTrue())
Expect(applier.ApplyDesiredApplySpec).To(Equal(populatedDesiredApplySpec))
Expand All @@ -84,7 +84,7 @@ var _ = Describe("ApplyAction", func() {
Context("when applier succeeds applying desired spec", func() {
Context("when saving desires spec as current spec succeeds", func() {
It("returns 'applied' after setting populated desired spec as current spec", func() {
value, err := action.Run(desiredApplySpec)
value, err := applyAction.Run(desiredApplySpec)
Expect(err).ToNot(HaveOccurred())
Expect(value).To(Equal("applied"))

Expand All @@ -99,7 +99,7 @@ var _ = Describe("ApplyAction", func() {
})

It("returns 'applied' and writes the id, instance name, deployment name, and az to files in the instance directory", func() {
value, err := action.Run(desiredApplySpec)
value, err := applyAction.Run(desiredApplySpec)
Expect(err).ToNot(HaveOccurred())
Expect(value).To(Equal("applied"))

Expand Down Expand Up @@ -128,7 +128,7 @@ var _ = Describe("ApplyAction", func() {
It("returns error because agent was not able to remember that is converged to desired spec", func() {
specService.SetErr = errors.New("fake-set-error")

_, err := action.Run(desiredApplySpec)
_, err := applyAction.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-set-error"))
})
Expand All @@ -141,13 +141,13 @@ var _ = Describe("ApplyAction", func() {
})

It("returns error", func() {
_, err := action.Run(desiredApplySpec)
_, err := applyAction.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-apply-error"))
})

It("does not save desired spec as current spec", func() {
_, err := action.Run(desiredApplySpec)
_, err := applyAction.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(specService.Spec).To(Equal(currentApplySpec))
})
Expand All @@ -160,19 +160,19 @@ var _ = Describe("ApplyAction", func() {
})

It("returns error", func() {
_, err := action.Run(desiredApplySpec)
_, err := applyAction.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-populate-dynamic-networks-err"))
})

It("does not apply desired spec as current spec", func() {
_, err := action.Run(desiredApplySpec)
_, err := applyAction.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(applier.Applied).To(BeFalse())
})

It("does not save desired spec as current spec", func() {
_, err := action.Run(desiredApplySpec)
_, err := applyAction.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(specService.Spec).To(Equal(currentApplySpec))
})
Expand All @@ -194,7 +194,7 @@ var _ = Describe("ApplyAction", func() {
}

It("populates dynamic networks in desired spec", func() {
_, err := action.Run(desiredApplySpec)
_, err := applyAction.Run(desiredApplySpec)
Expect(err).ToNot(HaveOccurred())
Expect(specService.PopulateDHCPNetworksSpec).To(Equal(desiredApplySpec))
Expect(specService.PopulateDHCPNetworksSettings).To(Equal(settings))
Expand All @@ -207,15 +207,15 @@ var _ = Describe("ApplyAction", func() {

Context("when saving desires spec as current spec succeeds", func() {
It("returns 'applied' after setting desired spec as current spec", func() {
value, err := action.Run(desiredApplySpec)
value, err := applyAction.Run(desiredApplySpec)
Expect(err).ToNot(HaveOccurred())
Expect(value).To(Equal("applied"))

Expect(specService.Spec).To(Equal(populatedDesiredApplySpec))
})

It("does not try to apply desired spec since it does not have jobs and packages", func() {
_, err := action.Run(desiredApplySpec)
_, err := applyAction.Run(desiredApplySpec)
Expect(err).ToNot(HaveOccurred())
Expect(applier.Applied).To(BeFalse())
})
Expand All @@ -227,13 +227,13 @@ var _ = Describe("ApplyAction", func() {
})

It("returns error because agent was not able to remember that is converged to desired spec", func() {
_, err := action.Run(desiredApplySpec)
_, err := applyAction.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-set-error"))
})

It("does not try to apply desired spec since it does not have jobs and packages", func() {
_, err := action.Run(desiredApplySpec)
_, err := applyAction.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(applier.Applied).To(BeFalse())
})
Expand All @@ -246,19 +246,19 @@ var _ = Describe("ApplyAction", func() {
})

It("returns error", func() {
_, err := action.Run(desiredApplySpec)
_, err := applyAction.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-populate-dynamic-networks-err"))
})

It("does not apply desired spec as current spec", func() {
_, err := action.Run(desiredApplySpec)
_, err := applyAction.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(applier.Applied).To(BeFalse())
})

It("does not save desired spec as current spec", func() {
_, err := action.Run(desiredApplySpec)
_, err := applyAction.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(specService.Spec).ToNot(Equal(desiredApplySpec))
})
Expand Down
6 changes: 3 additions & 3 deletions agent/action/cancel_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

. "github.com/cloudfoundry/bosh-agent/agent/action"
boshaction "github.com/cloudfoundry/bosh-agent/agent/action"
boshtask "github.com/cloudfoundry/bosh-agent/agent/task"
faketask "github.com/cloudfoundry/bosh-agent/agent/task/fakes"
)

var _ = Describe("CancelTaskAction", func() {
var (
taskService *faketask.FakeService
action CancelTaskAction
action boshaction.CancelTaskAction
)

BeforeEach(func() {
taskService = faketask.NewFakeService()
action = NewCancelTask(taskService)
action = boshaction.NewCancelTask(taskService)
})

AssertActionIsNotAsynchronous(action)
Expand Down
9 changes: 5 additions & 4 deletions agent/action/compile_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func (a CompilePackageAction) IsLoggable() bool {
return true
}

func (a CompilePackageAction) Run(blobID string, multiDigest boshcrypto.MultipleDigest, name, version string, deps boshcomp.Dependencies) (val map[string]interface{}, err error) {
func (a CompilePackageAction) Run(blobID string, multiDigest boshcrypto.MultipleDigest, name, version string, deps boshcomp.Dependencies) (map[string]interface{}, error) {
val := map[string]interface{}{}

pkg := boshcomp.Package{
BlobstoreID: blobID,
Name: name,
Expand All @@ -53,8 +55,7 @@ func (a CompilePackageAction) Run(blobID string, multiDigest boshcrypto.Multiple

uploadedBlobID, uploadedDigest, err := a.compiler.Compile(pkg, modelsDeps)
if err != nil {
err = bosherr.WrapErrorf(err, "Compiling package %s", pkg.Name)
return
return val, bosherr.WrapErrorf(err, "Compiling package %s", pkg.Name)
}

result := map[string]string{
Expand All @@ -65,7 +66,7 @@ func (a CompilePackageAction) Run(blobID string, multiDigest boshcrypto.Multiple
val = map[string]interface{}{
"result": result,
}
return
return val, nil
}

func (a CompilePackageAction) Resume() (interface{}, error) {
Expand Down
6 changes: 3 additions & 3 deletions agent/action/compile_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

. "github.com/cloudfoundry/bosh-agent/agent/action"
boshaction "github.com/cloudfoundry/bosh-agent/agent/action"
boshmodels "github.com/cloudfoundry/bosh-agent/agent/applier/models"
boshcomp "github.com/cloudfoundry/bosh-agent/agent/compiler"
fakecomp "github.com/cloudfoundry/bosh-agent/agent/compiler/fakes"
Expand Down Expand Up @@ -39,12 +39,12 @@ func getCompileActionArguments() (blobID string, multiDigest boshcrypto.Multiple
var _ = Describe("CompilePackageAction", func() {
var (
compiler *fakecomp.FakeCompiler
action CompilePackageAction
action boshaction.CompilePackageAction
)

BeforeEach(func() {
compiler = fakecomp.NewFakeCompiler()
action = NewCompilePackage(compiler)
action = boshaction.NewCompilePackage(compiler)
})

AssertActionIsAsynchronous(action)
Expand Down
10 changes: 5 additions & 5 deletions agent/action/compile_package_with_signed_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

. "github.com/cloudfoundry/bosh-agent/agent/action"
boshaction "github.com/cloudfoundry/bosh-agent/agent/action"
boshmodels "github.com/cloudfoundry/bosh-agent/agent/applier/models"
boshcomp "github.com/cloudfoundry/bosh-agent/agent/compiler"
fakecomp "github.com/cloudfoundry/bosh-agent/agent/compiler/fakes"
boshcrypto "github.com/cloudfoundry/bosh-utils/crypto"
)

func getCompileWithSignedURLActionArguments() CompilePackageWithSignedURLRequest {
return CompilePackageWithSignedURLRequest{
func getCompileWithSignedURLActionArguments() boshaction.CompilePackageWithSignedURLRequest {
return boshaction.CompilePackageWithSignedURLRequest{
PackageGetSignedURL: "fake/get/url",
UploadSignedURL: "fake/upload/url",
Name: "fake-package-name",
Expand Down Expand Up @@ -46,12 +46,12 @@ func getCompileWithSignedURLActionArguments() CompilePackageWithSignedURLRequest
var _ = Describe("CompilePackageWithSignedURL", func() {
var (
compiler *fakecomp.FakeCompiler
action CompilePackageWithSignedURL
action boshaction.CompilePackageWithSignedURL
)

BeforeEach(func() {
compiler = fakecomp.NewFakeCompiler()
action = NewCompilePackageWithSignedURL(compiler)
action = boshaction.NewCompilePackageWithSignedURL(compiler)
})

AssertActionIsAsynchronous(action)
Expand Down
5 changes: 2 additions & 3 deletions agent/action/concrete_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ func NewFactory(
specService boshas.V1Service,
jobScriptProvider boshscript.JobScriptProvider,
logger boshlog.Logger,
blobstoreDelegator blobdelegator.BlobstoreDelegator) (factory Factory) {
blobstoreDelegator blobdelegator.BlobstoreDelegator) Factory {
compressor := platform.GetCompressor()
copier := platform.GetCopier()
dirProvider := platform.GetDirProvider()
vitalsService := platform.GetVitalsService()
certManager := platform.GetCertManager()

factory = concreteFactory{
return concreteFactory{
availableActions: map[string]Action{
// API
"ping": NewPing(),
Expand Down Expand Up @@ -92,7 +92,6 @@ func NewFactory(
"sync_dns_with_signed_url": NewSyncDNSWithSignedURL(settingsService, platform, logger, blobstoreDelegator),
},
}
return
}

func (f concreteFactory) Create(method string) (Action, error) {
Expand Down
Loading