2022-02-17 16:44:49 +00:00
|
|
|
//go:build windows
|
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package pty_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/coder/coder/pty/ptytest"
|
2022-07-27 19:23:28 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-02-17 16:44:49 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.uber.org/goleak"
|
2022-07-27 19:23:28 +00:00
|
|
|
"golang.org/x/xerrors"
|
2022-02-17 16:44:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
goleak.VerifyTestMain(m)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStart(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
t.Run("Echo", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
2022-07-27 19:23:28 +00:00
|
|
|
pty, ps := ptytest.Start(t, exec.Command("cmd.exe", "/c", "echo", "test"))
|
2022-02-17 16:44:49 +00:00
|
|
|
pty.ExpectMatch("test")
|
2022-07-27 19:23:28 +00:00
|
|
|
err := ps.Wait()
|
|
|
|
require.NoError(t, err)
|
2022-02-17 16:44:49 +00:00
|
|
|
})
|
|
|
|
t.Run("Resize", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
2022-02-19 05:13:32 +00:00
|
|
|
pty, _ := ptytest.Start(t, exec.Command("cmd.exe"))
|
2022-02-17 16:44:49 +00:00
|
|
|
err := pty.Resize(100, 50)
|
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
2022-07-27 19:23:28 +00:00
|
|
|
t.Run("Kill", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
_, 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())
|
|
|
|
})
|
2022-02-17 16:44:49 +00:00
|
|
|
}
|