Skip to content

Commit

Permalink
Merge pull request #308 from cnabio/schristoff_fixgocilint
Browse files Browse the repository at this point in the history
chore: update golangci-lint and remove ioutil
  • Loading branch information
schristoff authored Nov 14, 2024
2 parents b10e925 + 8ce1c03 commit 2a65de0
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 18 deletions.
3 changes: 2 additions & 1 deletion action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func (a Action) saveLogs(logFile *os.File, opResult driver.OperationResult) erro
_, logOutputNameInUse := opResult.Outputs[claim.OutputInvocationImageLogs]
if logOutputNameInUse {
// The bundle is using our reserved log output name, so skip saving the logs
return nil
}

// Read from the beginning of the file
Expand All @@ -152,7 +153,7 @@ func (a Action) saveLogs(logFile *os.File, opResult driver.OperationResult) erro
return errors.Wrapf(err, "error seeking the log file")
}

logsB, err := ioutil.ReadAll(logFile)
logsB, err := io.ReadAll(logFile)
if err != nil {
return errors.Wrapf(err, "error reading log file %s", logFile.Name())
}
Expand Down
10 changes: 6 additions & 4 deletions action/operation_configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package action

import (
"errors"
"io/ioutil"
"io"
"os"
"testing"

Expand All @@ -24,23 +24,25 @@ func TestOperationConfigs_ApplyConfig(t *testing.T) {

t.Run("all config is persisted", func(t *testing.T) {
a := OperationConfigs{
//nolint:all
func(op *driver.Operation) error {
if op.Files == nil {
op.Files = make(map[string]string, 1)
}
op.Files["a"] = "b"
return nil
},
//nolint:all
func(op *driver.Operation) error {
op.Out = ioutil.Discard
op.Out = io.Discard
return nil
},
}
op := &driver.Operation{}
err := a.ApplyConfig(op)
require.NoError(t, err, "ApplyConfig should not have returned an error")
assert.Contains(t, op.Files, "a", "Changes from the first config function were not persisted")
assert.Equal(t, ioutil.Discard, op.Out, "Changes from the second config function were not persisted")
assert.Equal(t, io.Discard, op.Out, "Changes from the second config function were not persisted")
assert.Equal(t, os.Stderr, op.Err, "Changes from the second config function were not persisted")
})

Expand All @@ -50,7 +52,7 @@ func TestOperationConfigs_ApplyConfig(t *testing.T) {
return errors.New("oops")
},
func(op *driver.Operation) error {
op.Out = ioutil.Discard
op.Out = io.Discard
return nil
},
}
Expand Down
1 change: 1 addition & 0 deletions bundle/definition/validators.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:unused,revive
package definition

import (
Expand Down
1 change: 1 addition & 0 deletions claim/claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ func TestClaims_Sort(t *testing.T) {
assert.Equal(t, "3", c[2].ID, "Claims did not sort 3 to the third slot")
}

//nolint:all
func TestNewULID_ThreadSafe(t *testing.T) {
// Validate that the ULID function is thread-safe and generates
// monotonically increasing values
Expand Down
10 changes: 4 additions & 6 deletions claim/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ func TestOutput(t *testing.T) {
assert.Equal(t, []string{ActionInstall}, def.ApplyTo)
}

func TestOutputs_GetByName(t *testing.T) {
// func TestOutputs_GetByName(t *testing.T) {
// }

}

func TestOutputs_GetByIndex(t *testing.T) {

}
// func TestOutputs_GetByIndex(t *testing.T) {
// }

func TestOutputs_Sort(t *testing.T) {
o := NewOutputs([]Output{
Expand Down
2 changes: 1 addition & 1 deletion driver/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (d *Driver) Run(op *driver.Operation) (driver.OperationResult, error) {
}

// Handles always returns true, effectively claiming to work for any image type
func (d *Driver) Handles(dt string) bool {
func (d *Driver) Handles(_ string) bool {
return true
}

Expand Down
2 changes: 1 addition & 1 deletion driver/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ func (k *Driver) watchJobStatusAndLogs(ctx context.Context, podSelector metav1.L
complete := false
for _, cond := range job.Status.Conditions {
if cond.Type == batchv1.JobFailed {
err = fmt.Errorf(cond.Message)
err = fmt.Errorf("%s", cond.Message)
complete = true
break
}
Expand Down
6 changes: 6 additions & 0 deletions golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ linters:
linters-settings:
goimports:
local-prefixes: github.com/cnabio/cnab-go

issues:
exclude-rules:
- path: _test.go
linters:
- revive
2 changes: 1 addition & 1 deletion imagestore/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Create(options ...imagestore.Option) (imagestore.Store, error) {
}, nil
}

func (r *remote) Add(im string) (string, error) {
func (r *remote) Add(_ string) (string, error) {
return "", nil
}

Expand Down
7 changes: 3 additions & 4 deletions packager/export_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package packager

import (
"io/ioutil"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -149,7 +148,7 @@ func TestExportDigestMismatch(t *testing.T) {
}()

is := &imagestoremocks.MockStore{
AddStub: func(im string) (string, error) {
AddStub: func(_ string) (string, error) {
// return the same digest for all images, but only one of them has a digest in the bundle manifest so just
// that one will fail verification
return "sha256:222222228fb14266b7c0461ef1ef0b2f8c05f41cd544987a259a9d92cdad2540", nil
Expand All @@ -174,15 +173,15 @@ func TestExportDigestMismatch(t *testing.T) {
}

func setupTempDir() (string, error) {
tempDir, err := ioutil.TempDir("", "duffle-export-test")
tempDir, err := os.MkdirTemp("", "duffle-export-test")
if err != nil {
return "", err
}
return tempDir, nil
}

func setupPWD() (string, string, error) {
tempPWD, err := ioutil.TempDir("", "duffle-export-test")
tempPWD, err := os.MkdirTemp("", "duffle-export-test")
if err != nil {
return "", "", err
}
Expand Down

0 comments on commit 2a65de0

Please sign in to comment.