mirror of
https://github.com/gopasspw/gopass.git
synced 2025-12-08 19:24:54 +00:00
* [chore] Migrate to golangci-lint v2 Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issue Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Add more package comments. Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix golangci-lint config and the remaining checks Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Use Go 1.24 Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix container builds Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix more failing tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix test failure Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix another len assertion Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Move location tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix most remaining lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Only run XDG specific tests on linux Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Attempt to address on source of flaky failures Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> --------- Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
78 lines
1.8 KiB
Go
78 lines
1.8 KiB
Go
package cui
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/gopasspw/gopass/internal/backend/crypto/plain"
|
|
"github.com/gopasspw/gopass/internal/config"
|
|
"github.com/gopasspw/gopass/pkg/ctxutil"
|
|
"github.com/gopasspw/gopass/tests/gptest"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAskForPrivateKey(t *testing.T) {
|
|
buf := &bytes.Buffer{}
|
|
Stdout = buf
|
|
defer func() {
|
|
Stdout = os.Stdout
|
|
}()
|
|
|
|
ctx := config.NewContextInMemory()
|
|
|
|
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
|
key, err := AskForPrivateKey(ctx, plain.New(), "test")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "0xDEADBEEF", key)
|
|
buf.Reset()
|
|
}
|
|
|
|
func TestAskForGitConfigUser(t *testing.T) {
|
|
// necessary for setting up the env
|
|
u := gptest.NewGUnitTester(t)
|
|
assert.NotNil(t, u)
|
|
|
|
ctx := config.NewContextInMemory()
|
|
ctx = ctxutil.WithTerminal(ctx, true)
|
|
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
|
|
|
_, _, err := AskForGitConfigUser(ctx, plain.New())
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
type fakeMountPointer []string
|
|
|
|
func (f fakeMountPointer) MountPoints() []string {
|
|
return f
|
|
}
|
|
|
|
func TestAskForStore(t *testing.T) {
|
|
ctx := config.NewContextInMemory()
|
|
|
|
// test non-interactive
|
|
ctx = ctxutil.WithInteractive(ctx, false)
|
|
assert.Empty(t, AskForStore(ctx, fakeMountPointer{"foo", "bar"}))
|
|
|
|
// test interactive
|
|
ctx = ctxutil.WithInteractive(ctx, true)
|
|
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
|
assert.Empty(t, AskForStore(ctx, fakeMountPointer{"foo", "bar"}))
|
|
|
|
// test zero mps
|
|
assert.Empty(t, AskForStore(ctx, fakeMountPointer{}))
|
|
|
|
// test one mp
|
|
assert.Empty(t, AskForStore(ctx, fakeMountPointer{"foo"}))
|
|
|
|
// test two mps
|
|
assert.Empty(t, AskForStore(ctx, fakeMountPointer{"foo", "bar"}))
|
|
}
|
|
|
|
func TestSorted(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
assert.Equal(t, []string{"a", "b", "c"}, sorted([]string{"c", "a", "b"}))
|
|
}
|