From 9c4184de6f8c208a11e4329b90fa9844efd728e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Dost=C3=A1l?= Date: Tue, 28 Apr 2026 19:57:35 +0200 Subject: [PATCH] Address review feedback on echo mode polling - Rename echo_test_{linux,darwin}.go to echo_{linux,darwin}_test.go so they are only compiled during tests - Narrow build tag from !windows to linux || darwin to avoid compile failures on other Unix platforms - Return error from waitForEchoDisabled instead of calling t.Fatal, since the function is called from goroutines where FailNow would only terminate the calling goroutine --- internal/prompter/accessible_prompter_test.go | 19 ++++++++++--------- ...cho_test_darwin.go => echo_darwin_test.go} | 0 ...{echo_test_linux.go => echo_linux_test.go} | 0 3 files changed, 10 insertions(+), 9 deletions(-) rename internal/prompter/{echo_test_darwin.go => echo_darwin_test.go} (100%) rename internal/prompter/{echo_test_linux.go => echo_linux_test.go} (100%) diff --git a/internal/prompter/accessible_prompter_test.go b/internal/prompter/accessible_prompter_test.go index 8c4d8ce92..ee6eba3a9 100644 --- a/internal/prompter/accessible_prompter_test.go +++ b/internal/prompter/accessible_prompter_test.go @@ -1,4 +1,4 @@ -//go:build !windows +//go:build linux || darwin package prompter_test @@ -506,7 +506,7 @@ func TestAccessiblePrompter(t *testing.T) { require.NoError(t, err) // Wait until huh has disabled echo mode on the TTY - waitForEchoDisabled(t, console.Tty(), 5*time.Second) + require.NoError(t, waitForEchoDisabled(console.Tty(), 5*time.Second)) // Enter a number _, err = console.SendLine(dummyPassword) @@ -597,7 +597,7 @@ func TestAccessiblePrompter(t *testing.T) { require.NoError(t, err) // Wait until huh has disabled echo mode on the TTY - waitForEchoDisabled(t, console.Tty(), 5*time.Second) + require.NoError(t, waitForEchoDisabled(console.Tty(), 5*time.Second)) // Enter some dummy auth token _, err = console.SendLine(dummyAuthToken) @@ -642,7 +642,7 @@ func TestAccessiblePrompter(t *testing.T) { require.NoError(t, err) // Wait until huh has disabled echo mode on the TTY - waitForEchoDisabled(t, console.Tty(), 5*time.Second) + require.NoError(t, waitForEchoDisabled(console.Tty(), 5*time.Second)) // Now enter some dummy auth token to return control back to the test _, err = console.SendLine(dummyAuthTokenForAfterFailure) @@ -960,16 +960,17 @@ func testCloser(t *testing.T, closer io.Closer) { // waitForEchoDisabled polls the TTY until echo mode is disabled or the // timeout is reached. This is used in password and auth token tests to // ensure that huh has configured the terminal before we send input. -func waitForEchoDisabled(t *testing.T, tty *os.File, timeout time.Duration) { - t.Helper() +func waitForEchoDisabled(tty *os.File, timeout time.Duration) error { deadline := time.Now().Add(timeout) for time.Now().Before(deadline) { termios, err := unix.IoctlGetTermios(int(tty.Fd()), ioctlGetTermios) - require.NoError(t, err) + if err != nil { + return fmt.Errorf("getting terminal attributes: %w", err) + } if termios.Lflag&unix.ECHO == 0 { - return + return nil } time.Sleep(time.Millisecond) } - t.Fatal("timed out waiting for echo mode to be disabled") + return fmt.Errorf("timed out waiting for echo mode to be disabled") } diff --git a/internal/prompter/echo_test_darwin.go b/internal/prompter/echo_darwin_test.go similarity index 100% rename from internal/prompter/echo_test_darwin.go rename to internal/prompter/echo_darwin_test.go diff --git a/internal/prompter/echo_test_linux.go b/internal/prompter/echo_linux_test.go similarity index 100% rename from internal/prompter/echo_test_linux.go rename to internal/prompter/echo_linux_test.go