cmd: Return error in readPassword
The returned error was always nil. Replaced Wrap by WithStack because the function name was stale.
This commit is contained in:
parent
4a874000b7
commit
10fdb914df
2 changed files with 12 additions and 1 deletions
|
@ -280,7 +280,7 @@ func readPassword(in io.Reader) (password string, err error) {
|
|||
sc := bufio.NewScanner(in)
|
||||
sc.Scan()
|
||||
|
||||
return sc.Text(), errors.Wrap(err, "Scan")
|
||||
return sc.Text(), errors.WithStack(sc.Err())
|
||||
}
|
||||
|
||||
// readPasswordTerminal reads the password from the given reader which must be a
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/errors"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
|
@ -22,6 +23,16 @@ func Test_PrintFunctionsRespectsGlobalStdout(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
type errorReader struct{ err error }
|
||||
|
||||
func (r *errorReader) Read([]byte) (int, error) { return 0, r.err }
|
||||
|
||||
func TestReadPassword(t *testing.T) {
|
||||
want := errors.New("foo")
|
||||
_, err := readPassword(&errorReader{want})
|
||||
rtest.Assert(t, errors.Is(err, want), "wrong error %v", err)
|
||||
}
|
||||
|
||||
func TestReadRepo(t *testing.T) {
|
||||
tempDir := rtest.TempDir(t)
|
||||
|
||||
|
|
Loading…
Reference in a new issue