MCPcopy Index your code
hub / github.com/coder/coder / TestPasswordTerminalState

Function TestPasswordTerminalState

cli/cliui/prompt_test.go:249–283  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

247}
248
249func 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
286func passwordHelper() {

Callers

nothing calls this directly

Calls 13

NewFunction · 0.92
passwordHelperFunction · 0.85
SkipMethod · 0.80
CommandMethod · 0.80
EnvironMethod · 0.65
InputMethod · 0.65
OutputMethod · 0.65
StartMethod · 0.65
KillMethod · 0.65
WriteMethod · 0.65
SignalMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected