Skip to content

refactor: PTY & SSH #7100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Appease linter/fmt
Signed-off-by: Spike Curtis <spike@coder.com>
  • Loading branch information
spikecurtis committed Apr 18, 2023
commit d6e131ccbb03b40285eef62bcc74cfec03fd6eeb
6 changes: 4 additions & 2 deletions pty/start_other_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ var argEcho = []string{"test"}

// these constants/vars are used by Test_Start_truncate

const countEnd = 1000
const cmdCount = "sh"
const (
countEnd = 1000
cmdCount = "sh"
)

var argCount = []string{"-c", `
i=0
Expand Down
24 changes: 15 additions & 9 deletions pty/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ import (
"os/exec"
"strings"
"testing"
"time"

"github.com/coder/coder/pty"
"github.com/hinshun/vt10x"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/coder/coder/pty"
"github.com/coder/coder/testutil"
)

// Test_Start_copy tests that we can use io.Copy() on command output
// without deadlocking.
func Test_Start_copy(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
defer cancel()

pc, cmd, err := pty.Start(exec.CommandContext(ctx, cmdEcho, argEcho...))
Expand Down Expand Up @@ -54,12 +55,12 @@ func Test_Start_copy(t *testing.T) {
}
}

// Test_Start_truncation tests that we can read command ouput without truncation
// Test_Start_truncation tests that we can read command output without truncation
// even after the command has exited.
func Test_Start_trucation(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithTimeout(context.Background(), time.Second*1000)
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

pc, cmd, err := pty.Start(exec.CommandContext(ctx, cmdCount, argCount...))
Expand All @@ -73,7 +74,10 @@ func Test_Start_trucation(t *testing.T) {
for n < countEnd-25 {
want := fmt.Sprintf("%d", n)
err := readUntil(ctx, t, want, pc.OutputReader())
require.NoError(t, err, "want: %s", want)
assert.NoError(t, err, "want: %s", want)
if err != nil {
return
}
n++
}
}()
Expand Down Expand Up @@ -106,14 +110,16 @@ func Test_Start_trucation(t *testing.T) {
for n <= countEnd {
want := fmt.Sprintf("%d", n)
err := readUntil(ctx, t, want, pc.OutputReader())
require.NoError(t, err, "want: %s", want)
assert.NoError(t, err, "want: %s", want)
if err != nil {
return
}
n++
}
// ensure we still get to EOF
endB := &bytes.Buffer{}
_, err := io.Copy(endB, pc.OutputReader())
require.NoError(t, err)

assert.NoError(t, err)
}()

select {
Expand Down
6 changes: 4 additions & 2 deletions pty/start_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ var argEcho = []string{"/c", "echo", "test"}

// these constants/vars are used by Test_Start_truncate

const countEnd = 1000
const cmdCount = "cmd.exe"
const (
countEnd = 1000
cmdCount = "cmd.exe"
)

var argCount = []string{"/c", fmt.Sprintf("for /L %%n in (1,1,%d) do @echo %%n", countEnd)}