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

Address golangci-lint issues #87

Merged
merged 2 commits into from
Mar 12, 2024
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
14 changes: 14 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: go
on:
push:
pull_request:
jobs:
lint:
strategy:
matrix:
os: [windows-2019, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: golangci/golangci-lint-action@v3
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://golangci-lint.run/usage/configuration/
run:
timeout: 5m # 1m default times out on github-action runners

output:
# Sort results by: filepath, line and column.
sort-results: true
2 changes: 1 addition & 1 deletion blobstore/digest_verifiable_blobstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var _ = Describe("checksumVerifiableBlobstore", func() {
Describe("Create", func() {
BeforeEach(func() {
fakeFile := fakesys.NewFakeFile(fixturePath, fs)
fakeFile.Write([]byte("blargityblargblarg"))
fakeFile.Write([]byte("blargityblargblarg")) //nolint:errcheck
fs.RegisterOpenFile(fixturePath, fakeFile)
})

Expand Down
5 changes: 2 additions & 3 deletions blobstore/external_blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package blobstore

import (
"encoding/json"
"errors"
"fmt"
"path/filepath"

"errors"

bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshsys "github.com/cloudfoundry/bosh-utils/system"
boshuuid "github.com/cloudfoundry/bosh-utils/uuid"
Expand Down Expand Up @@ -50,7 +49,7 @@ func (b externalBlobstore) Get(blobID string) (string, error) {

err = b.run("get", blobID, fileName)
if err != nil {
b.fs.RemoveAll(fileName)
b.fs.RemoveAll(fileName) //nolint:errcheck
return "", err
}

Expand Down
6 changes: 3 additions & 3 deletions blobstore/external_blobstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var _ = Describe("externalBlobstore", func() {
Expect(err).ToNot(HaveOccurred())

fs.ReturnTempFile = tempFile
defer fs.RemoveAll(tempFile.Name())
defer fs.RemoveAll(tempFile.Name()) //nolint:errcheck

fileName, err := blobstore.Get("fake-blob-id")
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -97,7 +97,7 @@ var _ = Describe("externalBlobstore", func() {
Expect(err).ToNot(HaveOccurred())

fs.ReturnTempFile = tempFile
defer fs.RemoveAll(tempFile.Name())
defer fs.RemoveAll(tempFile.Name()) //nolint:errcheck

expectedCmd := []string{
"bosh-blobstore-fake-provider", "-c", configPath, "get",
Expand All @@ -121,7 +121,7 @@ var _ = Describe("externalBlobstore", func() {
Expect(err).ToNot(HaveOccurred())
fileName := file.Name()

defer fs.RemoveAll(fileName)
defer fs.RemoveAll(fileName) //nolint:errcheck

err = blobstore.CleanUp(fileName)
Expect(err).ToNot(HaveOccurred())
Expand Down
8 changes: 4 additions & 4 deletions blobstore/local_blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ func (b localBlobstore) Get(blobID string) (fileName string, err error) {

err = b.fs.CopyFile(path.Join(b.path(), blobID), fileName)
if err != nil {
b.fs.RemoveAll(fileName)
b.fs.RemoveAll(fileName) //nolint:errcheck
return "", bosherr.WrapError(err, "Copying file")
}

return fileName, nil
}

func (b localBlobstore) CleanUp(fileName string) error {
b.fs.RemoveAll(fileName)
b.fs.RemoveAll(fileName) //nolint:errcheck
return nil
}

Expand Down Expand Up @@ -83,12 +83,12 @@ func (b localBlobstore) Create(fileName string) (blobID string, err error) {
}

func (b localBlobstore) Validate() error {
path, found := b.options["blobstore_path"]
p, found := b.options["blobstore_path"]
if !found {
return bosherr.Error("missing blobstore_path")
}

_, ok := path.(string)
_, ok := p.(string)
if !ok {
return bosherr.Error("blobstore_path must be a string")
}
Expand Down
16 changes: 8 additions & 8 deletions blobstore/local_blobstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ var _ = Describe("localBlobstore", func() {

Describe("Get", func() {
It("fetches the local blob contents", func() {
fs.WriteFileString(fakeBlobstorePath+"/fake-blob-id", "fake contents")
fs.WriteFileString(fakeBlobstorePath+"/fake-blob-id", "fake contents") //nolint:errcheck

tempFile, err := fs.TempFile("bosh-blobstore-local-TestLocalGet")
Expect(err).ToNot(HaveOccurred())

fs.ReturnTempFile = tempFile
defer fs.RemoveAll(tempFile.Name())
defer fs.RemoveAll(tempFile.Name()) //nolint:errcheck

_, err = blobstore.Get("fake-blob-id")
Expect(err).ToNot(HaveOccurred())
Expand All @@ -85,7 +85,7 @@ var _ = Describe("localBlobstore", func() {
Expect(err).ToNot(HaveOccurred())

fs.ReturnTempFile = tempFile
defer fs.RemoveAll(tempFile.Name())
defer fs.RemoveAll(tempFile.Name()) //nolint:errcheck

fs.CopyFileError = errors.New("fake-copy-file-error")

Expand All @@ -104,7 +104,7 @@ var _ = Describe("localBlobstore", func() {
Expect(err).ToNot(HaveOccurred())
fileName := file.Name()

defer fs.RemoveAll(fileName)
defer fs.RemoveAll(fileName) //nolint:errcheck

err = blobstore.CleanUp(fileName)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -114,7 +114,7 @@ var _ = Describe("localBlobstore", func() {

Describe("Create", func() {
It("creates the local blob", func() {
fs.WriteFileString("/fake-file.txt", "fake-file-contents")
fs.WriteFileString("/fake-file.txt", "fake-file-contents") //nolint:errcheck

uuidGen.GeneratedUUID = "some-uuid"

Expand Down Expand Up @@ -148,7 +148,7 @@ var _ = Describe("localBlobstore", func() {
})

It("errs when copy file errs", func() {
fs.WriteFileString("/fake-file.txt", "fake-file-contents")
fs.WriteFileString("/fake-file.txt", "fake-file-contents") //nolint:errcheck

uuidGen.GeneratedUUID = "some-uuid"
fs.CopyFileError = errors.New("fake-copy-file-error")
Expand All @@ -161,7 +161,7 @@ var _ = Describe("localBlobstore", func() {

Describe("Delete", func() {
It("removes the blob from the blobstore", func() {
fs.WriteFileString("/fake-file.txt", "fake-file-contents")
fs.WriteFileString("/fake-file.txt", "fake-file-contents") //nolint:errcheck
blobID, err := blobstore.Create("/fake-file.txt")
Expect(err).ToNot(HaveOccurred())

Expand All @@ -180,7 +180,7 @@ var _ = Describe("localBlobstore", func() {
fs.RemoveAllStub = func(_ string) error {
return errors.New("failed to remove")
}
fs.WriteFileString("/fake-file.txt", "fake-file-contents")
fs.WriteFileString("/fake-file.txt", "fake-file-contents") //nolint:errcheck
blobID, err := blobstore.Create("/fake-file.txt")
Expect(err).ToNot(HaveOccurred())

Expand Down
5 changes: 2 additions & 3 deletions crypto/digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"errors"
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -114,10 +113,10 @@ var _ = Describe("digestImpl", func() {

BeforeEach(func() {
var err error
file, err = ioutil.TempFile("", "multiple-digest")
file, err = os.CreateTemp("", "multiple-digest")
Expect(err).ToNot(HaveOccurred())
defer file.Close()
file.Write([]byte("fake-contents"))
file.Write([]byte("fake-contents")) //nolint:errcheck

digest = NewDigest(DigestAlgorithmSHA1, "978ad524a02039f261773fe93d94973ae7de6470")
})
Expand Down
6 changes: 3 additions & 3 deletions crypto/multiple_digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"errors"
"fmt"
"io"
"os"
"strings"
"unicode"

bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshsys "github.com/cloudfoundry/bosh-utils/system"
"os"
"unicode"
)

type MultipleDigest struct {
Expand Down Expand Up @@ -59,7 +59,7 @@ func NewMultipleDigest(stream io.ReadSeeker, algos []Algorithm) (MultipleDigest,

digests := []Digest{}
for _, algo := range algos {
stream.Seek(0, 0)
stream.Seek(0, 0) //nolint:errcheck
digest, err := algo.CreateDigest(stream)
if err != nil {
return MultipleDigest{}, err
Expand Down
24 changes: 11 additions & 13 deletions crypto/multiple_digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package crypto_test

import (
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"strings"

Expand All @@ -13,9 +14,6 @@ import (
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"errors"
"fmt"
)

var _ = Describe("MultipleDigest", func() {
Expand Down Expand Up @@ -77,10 +75,10 @@ var _ = Describe("MultipleDigest", func() {

BeforeEach(func() {
var err error
file, err = ioutil.TempFile("", "multiple-digest")
file, err = os.CreateTemp("", "multiple-digest")
Expect(err).ToNot(HaveOccurred())
defer file.Close()
file.Write([]byte("fake-contents"))
file.Write([]byte("fake-contents")) //nolint:errcheck
})

It("can read a file and verify its content aginst the digest", func() {
Expand Down Expand Up @@ -261,10 +259,10 @@ var _ = Describe("MultipleDigest", func() {

Describe("NewMultipleDigestFromPath", func() {
It("returns a multi digest with provided algorithms", func() {
file, err := ioutil.TempFile("", "multiple-digest")
file, err := os.CreateTemp("", "multiple-digest")
Expect(err).ToNot(HaveOccurred())
defer file.Close()
file.Write([]byte("fake-readSeeker-2-contents"))
file.Write([]byte("fake-readSeeker-2-contents")) //nolint:errcheck
algos := []Algorithm{
DigestAlgorithmSHA1,
DigestAlgorithmSHA256,
Expand All @@ -278,10 +276,10 @@ var _ = Describe("MultipleDigest", func() {
})

It("return an error when calculation the digest fails", func() {
file, err := ioutil.TempFile("", "multiple-digest")
file, err := os.CreateTemp("", "multiple-digest")
Expect(err).ToNot(HaveOccurred())
defer file.Close()
file.Write([]byte("fake-readSeeker-2-contents"))
file.Write([]byte("fake-readSeeker-2-contents")) //nolint:errcheck
algos := []Algorithm{
DigestAlgorithmSHA1,
DigestAlgorithmSHA256,
Expand Down Expand Up @@ -321,14 +319,14 @@ var _ = Describe("MultipleDigest", func() {
)

BeforeEach(func() {
file, err := ioutil.TempFile("", "multiple-digest")
file, err := os.CreateTemp("", "multiple-digest")
Expect(err).ToNot(HaveOccurred())
file.Write([]byte("fake-readSeeker-2-contents"))
file.Write([]byte("fake-readSeeker-2-contents")) //nolint:errcheck
readSeeker = file
})

AfterEach(func() {
file.Close()
file.Close() //nolint:errcheck
})

It("returns a multi digest with provided algorithms", func() {
Expand Down
8 changes: 4 additions & 4 deletions crypto/x509_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ QAOSxgrLBblGLWcDF9fjMeYaUnI34pHviCKeVxfgsxDR+Jg11F78sPdYLOF6ipBe

certPool, err := crypto.CertPoolFromPEM([]byte(caCert))
Expect(err).ToNot(HaveOccurred())
Expect(certPool.Subjects()[0]).To(ContainSubstring("Internet Widgits Pty Ltd"))
Expect(certPool.Subjects()[0]).To(ContainSubstring("Internet Widgits Pty Ltd")) //nolint:staticcheck
})

It("returns error if PEM formatted block is invalid", func() {
Expand Down Expand Up @@ -133,9 +133,9 @@ nH9ttalAwSLBsobVaK8mmiAdtAdx+CmHWrB4UNxCPYasrt5A6a9A9SiQ2dLd

certPool, err := crypto.CertPoolFromPEM([]byte(caCert))
Expect(err).ToNot(HaveOccurred())
Expect(len(certPool.Subjects())).To(Equal(2))
Expect(certPool.Subjects()[0]).To(ContainSubstring("Internet Widgits Pty Ltd"))
Expect(certPool.Subjects()[1]).To(ContainSubstring("Cloud Foundry"))
Expect(len(certPool.Subjects())).To(Equal(2)) //nolint:staticcheck
Expect(certPool.Subjects()[0]).To(ContainSubstring("Internet Widgits Pty Ltd")) //nolint:staticcheck
Expect(certPool.Subjects()[1]).To(ContainSubstring("Cloud Foundry")) //nolint:staticcheck
})
})
})
2 changes: 1 addition & 1 deletion errors/multi_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func NewMultiError(errors ...error) error {
}

func (e MultiError) Error() string {
errors := make([]string, len(e.Errors), len(e.Errors))
errors := make([]string, len(e.Errors), len(e.Errors)) //nolint:gosimple
for i, err := range e.Errors {
errors[i] = err.Error()
}
Expand Down
2 changes: 1 addition & 1 deletion fileutil/generic_cp_copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c genericCpCopier) FilteredMultiCopyToTemp(dirs []DirToCopy, filters []str
err = os.Chmod(tempDir, os.FileMode(0755))
if err != nil {
c.CleanUp(tempDir)
bosherr.WrapError(err, "Fixing permissions on temp dir")
bosherr.WrapError(err, "Fixing permissions on temp dir") //nolint:errcheck
}

for _, dirToCopy := range dirs {
Expand Down
2 changes: 1 addition & 1 deletion fileutil/generic_cp_copier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ var _ = Describe("genericCpCopier", func() {
Describe("CleanUp", func() {
It("cleans up", func() {
tempDir := filepath.Join(os.TempDir(), "test-copier-cleanup")
fs.MkdirAll(tempDir, os.ModePerm)
fs.MkdirAll(tempDir, os.ModePerm) //nolint:errcheck

cpCopier.CleanUp(tempDir)

Expand Down
2 changes: 1 addition & 1 deletion fileutil/mover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ = Describe("Mover", func() {
oldLocation = "/path/to/old_file"
newLocation = "/path/to/new_file"

fs.WriteFileString(oldLocation, "some content")
fs.WriteFileString(oldLocation, "some content") //nolint:errcheck
})

It("renames the file", func() {
Expand Down
2 changes: 1 addition & 1 deletion fileutil/mover_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var _ = Describe("Mover", func() {
oldLocation = "/path/to/old_file"
newLocation = "/path/to/new_file"

fs.WriteFileString(oldLocation, "some content")
fs.WriteFileString(oldLocation, "some content") //nolint:errcheck
})

Context("when Rename fails due to Win32 Error Code ERROR_NOT_SAME_DEVICE", func() {
Expand Down
2 changes: 1 addition & 1 deletion fileutil/tarball_compressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c tarballCompressor) CompressSpecificFilesInDir(dir string, files []string
args = append([]string{"--no-mac-metadata"}, args...)
}

for _, file := range files {
for _, file := range files { //nolint:gosimple
args = append(args, file)
}

Expand Down
Loading
Loading