(t *testing.T)
| 247 | } |
| 248 | |
| 249 | func TestPasswordTerminalState(t *testing.T) { |
| 250 | if os.Getenv("TEST_SUBPROCESS") == "1" { |
| 251 | passwordHelper() |
| 252 | return |
| 253 | } |
| 254 | if runtime.GOOS == "windows" { |
| 255 | t.Skip("Skipping on windows. PTY doesn't read ptty.Write correctly.") |
| 256 | } |
| 257 | t.Parallel() |
| 258 | |
| 259 | ptty := ptytest.New(t) |
| 260 | |
| 261 | cmd := exec.Command(os.Args[0], "-test.run=TestPasswordTerminalState") //nolint:gosec |
| 262 | cmd.Env = append(os.Environ(), "TEST_SUBPROCESS=1") |
| 263 | // connect the child process's stdio to the PTY directly, not via a pipe |
| 264 | cmd.Stdin = ptty.Input().Reader |
| 265 | cmd.Stdout = ptty.Output().Writer |
| 266 | cmd.Stderr = ptty.Output().Writer |
| 267 | err := cmd.Start() |
| 268 | require.NoError(t, err) |
| 269 | process := cmd.Process |
| 270 | defer process.Kill() |
| 271 | |
| 272 | ptty.ExpectMatch("Password: ") |
| 273 | ptty.Write('t') |
| 274 | ptty.Write('e') |
| 275 | ptty.Write('s') |
| 276 | ptty.Write('t') |
| 277 | ptty.ExpectMatch("****") |
| 278 | |
| 279 | err = process.Signal(os.Interrupt) |
| 280 | require.NoError(t, err) |
| 281 | _, err = process.Wait() |
| 282 | require.NoError(t, err) |
| 283 | } |
| 284 | |
| 285 | // nolint:unused |
| 286 | func passwordHelper() { |
nothing calls this directly
no test coverage detected