mirror of
https://github.com/coder/coder.git
synced 2026-11-09 10:14:23 +08:00
* Add ssh tests for longoutput, orphan Signed-off-by: Spike Curtis <spike@coder.com> * PTY/SSH tests & improvements Signed-off-by: Spike Curtis <spike@coder.com> * Fix some tests Signed-off-by: Spike Curtis <spike@coder.com> * Fix linting Signed-off-by: Spike Curtis <spike@coder.com> * fmt Signed-off-by: Spike Curtis <spike@coder.com> * Fix windows test Signed-off-by: Spike Curtis <spike@coder.com> * Windows copy test Signed-off-by: Spike Curtis <spike@coder.com> * WIP Windows pty handling Signed-off-by: Spike Curtis <spike@coder.com> * Fix truncation tests Signed-off-by: Spike Curtis <spike@coder.com> * Appease linter/fmt Signed-off-by: Spike Curtis <spike@coder.com> * Fix typo Signed-off-by: Spike Curtis <spike@coder.com> * Rework truncation test to not assume OS buffers Signed-off-by: Spike Curtis <spike@coder.com> * Disable orphan test on Windows --- uses sh Signed-off-by: Spike Curtis <spike@coder.com> * agent_test running SSH in pty use ptytest.Start Signed-off-by: Spike Curtis <spike@coder.com> * More detail about closing pseudoconsole on windows Signed-off-by: Spike Curtis <spike@coder.com> * Code review fixes Signed-off-by: Spike Curtis <spike@coder.com> * Rearrange ptytest method order Signed-off-by: Spike Curtis <spike@coder.com> * Protect pty.Resize on windows from races Signed-off-by: Spike Curtis <spike@coder.com> * Fix windows bugs Signed-off-by: Spike Curtis <spike@coder.com> * PTY doesn't extend PTYCmd Signed-off-by: Spike Curtis <spike@coder.com> * Fix windows types Signed-off-by: Spike Curtis <spike@coder.com> --------- Signed-off-by: Spike Curtis <spike@coder.com>
69 lines
1.5 KiB
Go
69 lines
1.5 KiB
Go
//go:build windows
|
|
// +build windows
|
|
|
|
package pty_test
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"testing"
|
|
|
|
"github.com/coder/coder/pty/ptytest"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"go.uber.org/goleak"
|
|
"golang.org/x/xerrors"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
goleak.VerifyTestMain(m)
|
|
}
|
|
|
|
func TestStart(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("Echo", func(t *testing.T) {
|
|
t.Parallel()
|
|
ptty, ps := ptytest.Start(t, exec.Command("cmd.exe", "/c", "echo", "test"))
|
|
ptty.ExpectMatch("test")
|
|
err := ps.Wait()
|
|
require.NoError(t, err)
|
|
err = ptty.Close()
|
|
require.NoError(t, err)
|
|
})
|
|
t.Run("Resize", func(t *testing.T) {
|
|
t.Parallel()
|
|
ptty, _ := ptytest.Start(t, exec.Command("cmd.exe"))
|
|
err := ptty.Resize(100, 50)
|
|
require.NoError(t, err)
|
|
err = ptty.Close()
|
|
require.NoError(t, err)
|
|
})
|
|
t.Run("Kill", func(t *testing.T) {
|
|
t.Parallel()
|
|
ptty, ps := ptytest.Start(t, exec.Command("cmd.exe"))
|
|
err := ps.Kill()
|
|
assert.NoError(t, err)
|
|
err = ps.Wait()
|
|
var exitErr *exec.ExitError
|
|
require.True(t, xerrors.As(err, &exitErr))
|
|
assert.NotEqual(t, 0, exitErr.ExitCode())
|
|
err = ptty.Close()
|
|
require.NoError(t, err)
|
|
})
|
|
}
|
|
|
|
// these constants/vars are used by Test_Start_copy
|
|
|
|
const cmdEcho = "cmd.exe"
|
|
|
|
var argEcho = []string{"/c", "echo", "test"}
|
|
|
|
// these constants/vars are used by Test_Start_truncate
|
|
|
|
const (
|
|
countEnd = 1000
|
|
cmdCount = "cmd.exe"
|
|
)
|
|
|
|
var argCount = []string{"/c", fmt.Sprintf("for /L %%n in (1,1,%d) do @echo %%n", countEnd)}
|