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

Function testSessionOutput

agent/agent_test.go:3956–3992  ·  view source on GitHub ↗
(t *testing.T, session *ssh.Session, expected, unexpected []string, expectedRe *regexp.Regexp)

Source from the content-addressed store, hash-verified

3954}
3955
3956func testSessionOutput(t *testing.T, session *ssh.Session, expected, unexpected []string, expectedRe *regexp.Regexp) {
3957 t.Helper()
3958
3959 err := session.RequestPty("xterm", 128, 128, ssh.TerminalModes{})
3960 require.NoError(t, err)
3961
3962 ptty := ptytest.New(t)
3963 var stdout bytes.Buffer
3964 session.Stdout = &stdout
3965 session.Stderr = ptty.Output()
3966 session.Stdin = ptty.Input()
3967 err = session.Shell()
3968 require.NoError(t, err)
3969
3970 ptty.WriteLine("exit 0")
3971
3972 waitErr := make(chan error, 1)
3973 go func() {
3974 waitErr <- session.Wait()
3975 }()
3976 select {
3977 case err = <-waitErr:
3978 require.NoError(t, err)
3979 case <-time.After(testutil.WaitLong):
3980 require.Fail(t, "timed out waiting for session to exit")
3981 }
3982
3983 for _, unexpected := range unexpected {
3984 require.NotContains(t, stdout.String(), unexpected, "should not show output")
3985 }
3986 for _, expect := range expected {
3987 require.Contains(t, stdout.String(), expect, "should show output")
3988 }
3989 if expectedRe != nil {
3990 require.Regexp(t, expectedRe, stdout.String())
3991 }
3992}
3993
3994func TestAgent_Metrics_SSH(t *testing.T) {
3995 t.Parallel()

Callers 2

Calls 10

NewFunction · 0.92
WriteLineMethod · 0.80
HelperMethod · 0.65
OutputMethod · 0.65
InputMethod · 0.65
ShellMethod · 0.65
WaitMethod · 0.65
FailMethod · 0.45
StringMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected