mirror of
https://github.com/gopasspw/gopass.git
synced 2026-05-30 11:18:48 +02:00
9b72a1c76c
* [chore] Add more tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix most tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix remaining tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix lint issues. Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix more lint issues. Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix more lint issues. Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix the final lint issue. Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> --------- Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
146 lines
3.0 KiB
Go
146 lines
3.0 KiB
Go
package action
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/ergochat/readline"
|
|
"github.com/fatih/color"
|
|
"github.com/gopasspw/gopass/internal/config"
|
|
"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"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
func TestREPL(t *testing.T) {
|
|
u := gptest.NewUnitTester(t)
|
|
|
|
ctx := config.NewContextInMemory()
|
|
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
|
ctx = ctxutil.WithInteractive(ctx, false)
|
|
|
|
act, err := newMock(ctx, u.StoreDir(""))
|
|
require.NoError(t, err)
|
|
require.NotNil(t, act)
|
|
ctx = act.cfg.WithConfig(ctx)
|
|
|
|
buf := &bytes.Buffer{}
|
|
out.Stdout = buf
|
|
out.Stderr = buf
|
|
stdout = buf
|
|
color.NoColor = true
|
|
defer func() {
|
|
out.Stdout = os.Stdout
|
|
out.Stderr = os.Stderr
|
|
stdout = os.Stdout
|
|
}()
|
|
|
|
rl, err := readline.NewEx(&readline.Config{
|
|
Prompt: "gopass> ",
|
|
Stdin: bytes.NewBufferString("help\nquit\n"),
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
defer func() {
|
|
_ = rl.Close()
|
|
}()
|
|
|
|
err = act.REPL(gptest.CliCtx(ctx, t))
|
|
require.NoError(t, err)
|
|
assert.Contains(t, buf.String(), "help")
|
|
}
|
|
|
|
func TestEntriesForCompleter(t *testing.T) {
|
|
u := gptest.NewUnitTester(t)
|
|
|
|
ctx := config.NewContextInMemory()
|
|
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
|
ctx = ctxutil.WithInteractive(ctx, false)
|
|
|
|
act, err := newMock(ctx, u.StoreDir(""))
|
|
require.NoError(t, err)
|
|
require.NotNil(t, act)
|
|
ctx = act.cfg.WithConfig(ctx)
|
|
|
|
buf := &bytes.Buffer{}
|
|
out.Stdout = buf
|
|
out.Stderr = buf
|
|
stdout = buf
|
|
color.NoColor = true
|
|
defer func() {
|
|
out.Stdout = os.Stdout
|
|
out.Stderr = os.Stderr
|
|
stdout = os.Stdout
|
|
}()
|
|
|
|
completers, err := act.entriesForCompleter(ctx)
|
|
require.NoError(t, err)
|
|
assert.Len(t, completers, 1)
|
|
}
|
|
|
|
func TestReplCompleteRecipients(t *testing.T) {
|
|
u := gptest.NewUnitTester(t)
|
|
|
|
ctx := config.NewContextInMemory()
|
|
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
|
ctx = ctxutil.WithInteractive(ctx, false)
|
|
|
|
act, err := newMock(ctx, u.StoreDir(""))
|
|
require.NoError(t, err)
|
|
require.NotNil(t, act)
|
|
ctx = act.cfg.WithConfig(ctx)
|
|
|
|
buf := &bytes.Buffer{}
|
|
out.Stdout = buf
|
|
out.Stderr = buf
|
|
stdout = buf
|
|
color.NoColor = true
|
|
defer func() {
|
|
out.Stdout = os.Stdout
|
|
out.Stderr = os.Stderr
|
|
stdout = os.Stdout
|
|
}()
|
|
|
|
cmd := &cli.Command{
|
|
Name: "remove",
|
|
}
|
|
|
|
completers := act.replCompleteRecipients(ctx, cmd)
|
|
assert.Len(t, completers, 1)
|
|
}
|
|
|
|
func TestReplCompleteTemplates(t *testing.T) {
|
|
u := gptest.NewUnitTester(t)
|
|
|
|
ctx := config.NewContextInMemory()
|
|
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
|
ctx = ctxutil.WithInteractive(ctx, false)
|
|
|
|
act, err := newMock(ctx, u.StoreDir(""))
|
|
require.NoError(t, err)
|
|
require.NotNil(t, act)
|
|
ctx = act.cfg.WithConfig(ctx)
|
|
|
|
buf := &bytes.Buffer{}
|
|
out.Stdout = buf
|
|
out.Stderr = buf
|
|
stdout = buf
|
|
color.NoColor = true
|
|
defer func() {
|
|
out.Stdout = os.Stdout
|
|
out.Stderr = os.Stderr
|
|
stdout = os.Stdout
|
|
}()
|
|
|
|
cmd := &cli.Command{
|
|
Name: "templates",
|
|
}
|
|
|
|
completers := act.replCompleteTemplates(ctx, cmd)
|
|
assert.Len(t, completers, 1)
|
|
}
|