aboutsummaryrefslogtreecommitdiff
path: root/internal/readpassword/stdin_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2022-01-03 15:18:59 +0100
committerJakob Unterwurzacher2022-01-03 15:18:59 +0100
commit4b251f3ce1f0a0472ed10a00aeef70c69ba03a5d (patch)
treea93b7b37d5b3118decd8a52f2db2e76d09d82b70 /internal/readpassword/stdin_test.go
parent1eaf1211a259a38cdf3e7dad2e00e140409bef9a (diff)
readpassword: bubble up errors instead of exiting the process
This allows cleanups to happen in the caller, like removing the control socket. Fixes https://github.com/rfjakob/gocryptfs/issues/634
Diffstat (limited to 'internal/readpassword/stdin_test.go')
-rw-r--r--internal/readpassword/stdin_test.go33
1 files changed, 26 insertions, 7 deletions
diff --git a/internal/readpassword/stdin_test.go b/internal/readpassword/stdin_test.go
index 01dd701..5d5d846 100644
--- a/internal/readpassword/stdin_test.go
+++ b/internal/readpassword/stdin_test.go
@@ -8,12 +8,20 @@ import (
)
// Provide password via stdin, terminated by "\n".
+//
+// The TEST_SLAVE magic is explained at
+// https://talks.golang.org/2014/testing.slide#23 , mirror:
+// http://web.archive.org/web/20200426174352/https://talks.golang.org/2014/testing.slide#23
func TestStdin(t *testing.T) {
p1 := "g55434t55wef"
if os.Getenv("TEST_SLAVE") == "1" {
- p2 := string(readPasswordStdin("foo"))
- if p1 != p2 {
- fmt.Fprintf(os.Stderr, "%q != %q", p1, p2)
+ p2, err := readPasswordStdin("foo")
+ if err != nil {
+ fmt.Fprint(os.Stderr, err)
+ os.Exit(1)
+ }
+ if p1 != string(p2) {
+ fmt.Fprintf(os.Stderr, "%q != %q", p1, string(p2))
os.Exit(1)
}
return
@@ -41,12 +49,20 @@ func TestStdin(t *testing.T) {
// Provide password via stdin, terminated by EOF (pipe close). This should not
// hang.
+//
+// The TEST_SLAVE magic is explained at
+// https://talks.golang.org/2014/testing.slide#23 , mirror:
+// http://web.archive.org/web/20200426174352/https://talks.golang.org/2014/testing.slide#23
func TestStdinEof(t *testing.T) {
p1 := "asd45as5f4a36"
if os.Getenv("TEST_SLAVE") == "1" {
- p2 := string(readPasswordStdin("foo"))
- if p1 != p2 {
- fmt.Fprintf(os.Stderr, "%q != %q", p1, p2)
+ p2, err := readPasswordStdin("foo")
+ if err != nil {
+ fmt.Fprint(os.Stderr, err)
+ os.Exit(1)
+ }
+ if p1 != string(p2) {
+ fmt.Fprintf(os.Stderr, "%q != %q", p1, string(p2))
os.Exit(1)
}
return
@@ -76,7 +92,10 @@ func TestStdinEof(t *testing.T) {
// Provide empty password via stdin
func TestStdinEmpty(t *testing.T) {
if os.Getenv("TEST_SLAVE") == "1" {
- readPasswordStdin("foo")
+ _, err := readPasswordStdin("foo")
+ if err != nil {
+ os.Exit(1)
+ }
}
cmd := exec.Command(os.Args[0], "-test.run=TestStdinEmpty$")
cmd.Env = append(os.Environ(), "TEST_SLAVE=1")