Skip to content

Commit

Permalink
[CLEANUP] Patching all of the new linter complaints
Browse files Browse the repository at this point in the history
Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com>
  • Loading branch information
AnomalRoil committed Nov 2, 2023
1 parent 321f1bc commit 8229185
Show file tree
Hide file tree
Showing 150 changed files with 1,020 additions and 1,006 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ linters:
- govet
- interfacer
- ifshort
- inamedparam
- interfacebloat
- ireturn
- lll
Expand Down
8 changes: 4 additions & 4 deletions internal/action/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestAction(t *testing.T) {
assert.Equal(t, actName, act.Name)

assert.Contains(t, act.String(), u.StoreDir(""))
assert.Equal(t, 0, len(act.Store.Mounts()))
assert.Empty(t, act.Store.Mounts())
}

func TestNew(t *testing.T) {
Expand All @@ -83,9 +83,9 @@ func TestNew(t *testing.T) {

t.Run("init an existing plain store", func(t *testing.T) {
require.NoError(t, cfg.SetPath(filepath.Join(td, "store")))
assert.NoError(t, os.MkdirAll(cfg.Path(), 0o700))
assert.NoError(t, os.WriteFile(filepath.Join(cfg.Path(), plain.IDFile), []byte("foobar"), 0o600))
require.NoError(t, os.MkdirAll(cfg.Path(), 0o700))
require.NoError(t, os.WriteFile(filepath.Join(cfg.Path(), plain.IDFile), []byte("foobar"), 0o600))
_, err := New(cfg, sv)
assert.NoError(t, err)
require.NoError(t, err)
})
}
3 changes: 1 addition & 2 deletions internal/action/aliases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/gopasspw/gopass/internal/out"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/tests/gptest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand All @@ -32,5 +31,5 @@ func TestAliases(t *testing.T) {
stdout = os.Stdout
}()

assert.NoError(t, act.AliasesPrint(gptest.CliCtx(ctx, t)))
require.NoError(t, act.AliasesPrint(gptest.CliCtx(ctx, t)))
}
12 changes: 6 additions & 6 deletions internal/action/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ func TestAudit(t *testing.T) {
t.Run("expect audit complaints on very weak passwords", func(t *testing.T) {
sec := secrets.NewAKV()
sec.SetPassword("123")
assert.NoError(t, act.Store.Set(ctx, "bar", sec))
assert.NoError(t, act.Store.Set(ctx, "baz", sec))
require.NoError(t, act.Store.Set(ctx, "bar", sec))
require.NoError(t, act.Store.Set(ctx, "baz", sec))

assert.Error(t, act.Audit(gptest.CliCtx(ctx, t)))
require.Error(t, act.Audit(gptest.CliCtx(ctx, t)))
buf.Reset()
})

t.Run("test with filter and very passwords", func(t *testing.T) {
c := gptest.CliCtx(ctx, t, "foo")
assert.Error(t, act.Audit(c))
require.Error(t, act.Audit(c))
buf.Reset()
})

t.Run("test empty store", func(t *testing.T) {
for _, v := range []string{"foo", "bar", "baz"} {
assert.NoError(t, act.Store.Delete(ctx, v))
require.NoError(t, act.Store.Delete(ctx, v))
}
assert.NoError(t, act.Audit(gptest.CliCtx(ctx, t)))
require.NoError(t, act.Audit(gptest.CliCtx(ctx, t)))
assert.Contains(t, "No secrets found", buf.String())
buf.Reset()
})
Expand Down
5 changes: 3 additions & 2 deletions internal/action/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -242,7 +243,7 @@ func (s *Action) binaryCopyFromStoreToFile(ctx context.Context, from, to string,
func (s *Action) binaryValidate(ctx context.Context, buf []byte, name string) error {
h := sha256.New()
_, _ = h.Write(buf)
fileSum := fmt.Sprintf("%x", h.Sum(nil))
fileSum := hex.EncodeToString(h.Sum(nil))
h.Reset()

debug.Log("in: %s - %q", fileSum, string(buf))
Expand All @@ -253,7 +254,7 @@ func (s *Action) binaryValidate(ctx context.Context, buf []byte, name string) er
return fmt.Errorf("failed to read %q from the store: %w", name, err)
}
_, _ = h.Write(buf)
storeSum := fmt.Sprintf("%x", h.Sum(nil))
storeSum := hex.EncodeToString(h.Sum(nil))

debug.Log("store: %s - %q", storeSum, string(buf))

Expand Down
48 changes: 24 additions & 24 deletions internal/action/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func TestBinary(t *testing.T) {
require.NotNil(t, act)
ctx = act.cfg.WithConfig(ctx)

assert.Error(t, act.Cat(gptest.CliCtx(ctx, t)))
assert.Error(t, act.BinaryCopy(gptest.CliCtx(ctx, t)))
assert.Error(t, act.BinaryMove(gptest.CliCtx(ctx, t)))
assert.Error(t, act.Sum(gptest.CliCtx(ctx, t)))
require.Error(t, act.Cat(gptest.CliCtx(ctx, t)))
require.Error(t, act.BinaryCopy(gptest.CliCtx(ctx, t)))
require.Error(t, act.BinaryMove(gptest.CliCtx(ctx, t)))
require.Error(t, act.Sum(gptest.CliCtx(ctx, t)))
}

func TestBinaryCat(t *testing.T) {
Expand Down Expand Up @@ -66,26 +66,26 @@ func TestBinaryCat(t *testing.T) {
writeBinfile(t, infile, tSize)

t.Run("populate store", func(t *testing.T) {
assert.NoError(t, act.binaryCopy(ctx, gptest.CliCtx(ctx, t), infile, "bar", true))
require.NoError(t, act.binaryCopy(ctx, gptest.CliCtx(ctx, t), infile, "bar", true))
})

t.Run("binary cat bar", func(t *testing.T) {
assert.NoError(t, act.Cat(gptest.CliCtx(ctx, t, "bar")))
require.NoError(t, act.Cat(gptest.CliCtx(ctx, t, "bar")))
})

stdinfile := filepath.Join(u.Dir, "stdin")
t.Run("binary cat baz from stdin", func(t *testing.T) {
writeBinfile(t, stdinfile, tSize)

fd, err := os.Open(stdinfile)
assert.NoError(t, err)
require.NoError(t, err)
binstdin = fd
defer func() {
binstdin = os.Stdin
_ = fd.Close()
}()

assert.NoError(t, act.Cat(gptest.CliCtx(ctx, t, "baz")))
require.NoError(t, act.Cat(gptest.CliCtx(ctx, t, "baz")))
})

t.Run("compare output", func(t *testing.T) {
Expand Down Expand Up @@ -123,7 +123,7 @@ func TestBinaryCatSizes(t *testing.T) {
writeBinfile(t, stdinfile, tSize)

fd, err := os.Open(stdinfile)
assert.NoError(t, err)
require.NoError(t, err)

catFn := func() {
binstdin = fd
Expand All @@ -132,7 +132,7 @@ func TestBinaryCatSizes(t *testing.T) {
_ = fd.Close()
}()

assert.NoError(t, act.Cat(gptest.CliCtx(ctx, t, "baz")))
require.NoError(t, act.Cat(gptest.CliCtx(ctx, t, "baz")))
}
catFn()

Expand Down Expand Up @@ -173,8 +173,8 @@ func TestBinaryCopy(t *testing.T) {
defer buf.Reset()

infile := filepath.Join(u.Dir, "input.txt")
assert.NoError(t, os.WriteFile(infile, []byte("0xDEADBEEF\n"), 0o644))
assert.NoError(t, act.binaryCopy(ctx, gptest.CliCtx(ctx, t), infile, "txt", true))
require.NoError(t, os.WriteFile(infile, []byte("0xDEADBEEF\n"), 0o644))
require.NoError(t, act.binaryCopy(ctx, gptest.CliCtx(ctx, t), infile, "txt", true))
})

infile := filepath.Join(u.Dir, "input.raw")
Expand All @@ -183,33 +183,33 @@ func TestBinaryCopy(t *testing.T) {
defer buf.Reset()

writeBinfile(t, infile, 1024)
assert.NoError(t, act.binaryCopy(ctx, gptest.CliCtx(ctx, t), infile, "bar", true))
require.NoError(t, act.binaryCopy(ctx, gptest.CliCtx(ctx, t), infile, "bar", true))
})

t.Run("binary copy bar tempdir/bar", func(t *testing.T) {
defer buf.Reset()
assert.NoError(t, act.BinaryCopy(gptest.CliCtx(ctx, t, "bar", outfile)))
require.NoError(t, act.BinaryCopy(gptest.CliCtx(ctx, t, "bar", outfile)))
})

t.Run("binary copy tempdir/bar tempdir/bar", func(t *testing.T) {
defer buf.Reset()

assert.Error(t, act.BinaryCopy(gptest.CliCtx(ctx, t, outfile, outfile)))
require.Error(t, act.BinaryCopy(gptest.CliCtx(ctx, t, outfile, outfile)))
})

t.Run("binary copy bar bar", func(t *testing.T) {
defer buf.Reset()
assert.Error(t, act.BinaryCopy(gptest.CliCtx(ctx, t, "bar", "bar")))
require.Error(t, act.BinaryCopy(gptest.CliCtx(ctx, t, "bar", "bar")))
})

t.Run("binary move tempdir/bar bar2", func(t *testing.T) {
defer buf.Reset()
assert.NoError(t, act.BinaryMove(gptest.CliCtx(ctx, t, outfile, "bar2")))
require.NoError(t, act.BinaryMove(gptest.CliCtx(ctx, t, outfile, "bar2")))
})

t.Run("binary move bar2 tempdir/bar", func(t *testing.T) {
defer buf.Reset()
assert.NoError(t, act.BinaryMove(gptest.CliCtx(ctx, t, "bar2", outfile)))
require.NoError(t, act.BinaryMove(gptest.CliCtx(ctx, t, "bar2", outfile)))
})
}

Expand All @@ -235,11 +235,11 @@ func TestBinarySum(t *testing.T) {

t.Run("populate store", func(t *testing.T) {
writeBinfile(t, infile, 1024)
assert.NoError(t, act.binaryCopy(ctx, gptest.CliCtx(ctx, t), infile, "bar", true))
require.NoError(t, act.binaryCopy(ctx, gptest.CliCtx(ctx, t), infile, "bar", true))
})

t.Run("binary sum bar", func(t *testing.T) {
assert.NoError(t, act.Sum(gptest.CliCtx(ctx, t, "bar")))
require.NoError(t, act.Sum(gptest.CliCtx(ctx, t, "bar")))
buf.Reset()
})
}
Expand All @@ -257,10 +257,10 @@ func TestBinaryGet(t *testing.T) {
ctx = act.cfg.WithConfig(ctx)

data := []byte("1\n2\n3\n")
assert.NoError(t, act.insertStdin(ctx, "x", data, false))
require.NoError(t, act.insertStdin(ctx, "x", data, false))

out, err := act.binaryGet(ctx, "x")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, data, out)
}

Expand All @@ -272,7 +272,7 @@ func writeBinfile(t *testing.T, fn string, size int) {

buf := make([]byte, size)
n, err := lr.Read(buf)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, size, n)
assert.NoError(t, os.WriteFile(fn, buf, 0o644))
require.NoError(t, os.WriteFile(fn, buf, 0o644))
}
3 changes: 2 additions & 1 deletion internal/action/clihelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -77,7 +78,7 @@ func TestParseArgs(t *testing.T) {

app := cli.NewApp()
fs := flag.NewFlagSet("default", flag.ContinueOnError)
assert.NoError(t, fs.Parse(tc.argIn), tc.name)
require.NoError(t, fs.Parse(tc.argIn), tc.name)
args, kvps := parseArgs(cli.NewContext(app, fs, nil))
assert.Equal(t, tc.argOut, args, tc.name)
assert.Equal(t, tc.kvOut, kvps, tc.name)
Expand Down
20 changes: 10 additions & 10 deletions internal/action/clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ func aGitRepo(ctx context.Context, t *testing.T, u *gptest.Unit, name string) st
t.Helper()

gd := filepath.Join(u.Dir, name)
assert.NoError(t, os.MkdirAll(gd, 0o700))
require.NoError(t, os.MkdirAll(gd, 0o700))

_, err := git.New(gd)
assert.Error(t, err)
require.Error(t, err)

idf := filepath.Join(gd, ".gpg-id")
assert.NoError(t, os.WriteFile(idf, []byte("0xDEADBEEF"), 0o600))
require.NoError(t, os.WriteFile(idf, []byte("0xDEADBEEF"), 0o600))

gr, err := git.Init(ctx, gd, "Nobody", "foo.bar@example.org")
assert.NoError(t, err)
require.NoError(t, err)
assert.NotNil(t, gr)

return gd
Expand Down Expand Up @@ -66,18 +66,18 @@ func TestClone(t *testing.T) {
t.Run("no args", func(t *testing.T) {
defer buf.Reset()
c := gptest.CliCtx(ctx, t)
assert.Error(t, act.Clone(c))
require.Error(t, act.Clone(c))
})

t.Run("clone to initialized store", func(t *testing.T) {
defer buf.Reset()
assert.Error(t, act.clone(ctx, "/tmp/non-existing-repo.git", "", filepath.Join(u.Dir, "store")))
require.Error(t, act.clone(ctx, "/tmp/non-existing-repo.git", "", filepath.Join(u.Dir, "store")))
})

t.Run("clone to mount", func(t *testing.T) {
defer buf.Reset()
gd := aGitRepo(ctx, t, u, "other-repo")
assert.NoError(t, act.clone(ctx, gd, "gd", filepath.Join(u.Dir, "mount")))
require.NoError(t, act.clone(ctx, gd, "gd", filepath.Join(u.Dir, "mount")))
})
}

Expand Down Expand Up @@ -112,7 +112,7 @@ func TestCloneBackendIsStoredForMount(t *testing.T) {
repo := aGitRepo(ctx, t, u, "my-project")

c = gptest.CliCtxWithFlags(ctx, t, map[string]string{"check-keys": "false"}, repo, "the-project")
assert.NoError(t, act.Clone(c))
require.NoError(t, act.Clone(c))

require.Contains(t, act.cfg.Mounts(), "the-project")
}
Expand All @@ -135,7 +135,7 @@ func TestCloneGetGitConfig(t *testing.T) {
ctx = act.cfg.WithConfig(ctx)

name, email, err := act.cloneGetGitConfig(ctx, "foobar")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, "0xDEADBEEF", name)
assert.Equal(t, "0xDEADBEEF", email)
}
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestCloneCheckDecryptionKeys(t *testing.T) {
}

c = gptest.CliCtxWithFlags(ctx, t, map[string]string{"check-keys": "true"}, repo, "the-project")
assert.NoError(t, act.Clone(c))
require.NoError(t, act.Clone(c))

require.Contains(t, act.cfg.Mounts(), "the-project")
}
14 changes: 7 additions & 7 deletions internal/action/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,31 @@ func TestComplete(t *testing.T) {
t.Run("bash completion", func(t *testing.T) {
defer buf.Reset()

assert.NoError(t, act.CompletionBash(nil))
require.NoError(t, act.CompletionBash(nil))
assert.Contains(t, buf.String(), "action.test")
})

t.Run("fish completion", func(t *testing.T) {
defer buf.Reset()

assert.NoError(t, act.CompletionFish(app))
require.NoError(t, act.CompletionFish(app))
assert.Contains(t, buf.String(), "action.test")
assert.Error(t, act.CompletionFish(nil))
require.Error(t, act.CompletionFish(nil))
})

t.Run("zsh completion", func(t *testing.T) {
defer buf.Reset()

assert.NoError(t, act.CompletionZSH(app))
require.NoError(t, act.CompletionZSH(app))
assert.Contains(t, buf.String(), "action.test")
assert.Error(t, act.CompletionZSH(nil))
require.Error(t, act.CompletionZSH(nil))
})

t.Run("openbsdksh completion", func(t *testing.T) {
defer buf.Reset()

assert.NoError(t, act.CompletionOpenBSDKsh(app))
require.NoError(t, act.CompletionOpenBSDKsh(app))
assert.Contains(t, buf.String(), "complete_gopass")
assert.Error(t, act.CompletionOpenBSDKsh(nil))
require.Error(t, act.CompletionOpenBSDKsh(nil))
})
}
Loading

0 comments on commit 8229185

Please sign in to comment.