termstatus: fully wrap reading password from terminal

This commit is contained in:
Michael Eischer
2025-09-14 19:21:51 +02:00
parent 013c565c29
commit ff5a0cc851
7 changed files with 56 additions and 44 deletions

View File

@@ -3,6 +3,7 @@ package termstatus
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"testing"
@@ -76,3 +77,13 @@ func TestSanitizeLines(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)
}