fix: (Re-)enable TestPasswordTerminalState test (#3169)

This commit is contained in:
Mathias Fredriksson
2022-07-25 18:42:20 +03:00
committed by GitHub
parent 5312296283
commit 4d53934eb0
+8 -10
View File
@@ -165,9 +165,6 @@ func newPrompt(ptty *ptytest.PTY, opts cliui.PromptOptions, cmdOpt func(cmd *cob
}
func TestPasswordTerminalState(t *testing.T) {
// TODO: fix this test so that it runs reliably
t.Skip()
if os.Getenv("TEST_SUBPROCESS") == "1" {
passwordHelper()
return
@@ -192,20 +189,21 @@ func TestPasswordTerminalState(t *testing.T) {
defer process.Kill()
ptty.ExpectMatch("Password: ")
time.Sleep(100 * time.Millisecond) // wait for child process to turn off echo and start reading input
echo, err := ptyWithFlags.EchoEnabled()
require.NoError(t, err)
require.False(t, echo, "echo is on while reading password")
require.Eventually(t, func() bool {
echo, err := ptyWithFlags.EchoEnabled()
return err == nil && !echo
}, 5*time.Second, 50*time.Millisecond, "echo is on while reading password")
err = process.Signal(os.Interrupt)
require.NoError(t, err)
_, err = process.Wait()
require.NoError(t, err)
echo, err = ptyWithFlags.EchoEnabled()
require.NoError(t, err)
require.True(t, echo, "echo is off after reading password")
require.Eventually(t, func() bool {
echo, err := ptyWithFlags.EchoEnabled()
return err == nil && echo
}, 5*time.Second, 50*time.Millisecond, "echo is off after reading password")
}
// nolint:unused