Skip to content
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

switch to use blackbox testing, move tests to separate module #35

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
- name: Test
run: go test -v ./...
run: cd test && go test -v .
lint:
runs-on: ubuntu-latest
steps:
Expand All @@ -30,3 +30,8 @@ jobs:
docker run --rm -v `pwd`:/go/src/github.com/moby/term -w /go/src/github.com/moby/term \
golangci/golangci-lint:v1.50.1 golangci-lint run --disable-all -v \
-E govet -E misspell -E gofmt -E ineffassign -E revive
- name: Lint tests
run: |
docker run --rm -v `pwd`:/go/src/github.com/moby/term -w /go/src/github.com/moby/term/test \
golangci/golangci-lint:v1.50.1 golangci-lint run --disable-all -v \
-E govet -E misspell -E gofmt -E ineffassign -E revive
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ go 1.18

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1
github.com/creack/pty v1.1.18
golang.org/x/sys v0.1.0
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
15 changes: 15 additions & 0 deletions test/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module github.com/moby/term/test

go 1.18

require (
github.com/creack/pty v1.1.18
github.com/moby/term v0.0.0-00010101000000-000000000000 // replaced
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
golang.org/x/sys v0.1.0 // indirect
)

replace github.com/moby/term => ../
7 changes: 7 additions & 0 deletions test/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4 changes: 3 additions & 1 deletion proxy_test.go → test/proxy_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package term
package test

import (
"bytes"
"testing"

. "github.com/moby/term"
)

func TestEscapeProxyRead(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions term_test.go → test/term_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//go:build !windows
// +build !windows

package term
package test

import (
"os"
"reflect"
"testing"

cpty "github.com/creack/pty"
. "github.com/moby/term"
)

func newTTYForTest(t *testing.T) *os.File {
Expand Down Expand Up @@ -47,7 +48,7 @@ func TestGetWinsize(t *testing.T) {
t.Fatal("winSize is nil")
}

newSize := Winsize{Width: 200, Height: 200, x: winSize.x, y: winSize.y}
newSize := Winsize{Width: 200, Height: 200}
Comment on lines -50 to +51
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think this was the bit I was still looking at. It's somewhat unclear why x and y aren't exported; effectively WinSize in this module is identical to golang.org/x/sys/unix.Winsize`;

Type in this module:

// Winsize represents the size of the terminal window.
type Winsize struct {
	Height uint16
	Width  uint16
	x      uint16
	y      uint16
}

And in golang.org/x/sys:

type Winsize struct {
	Row    uint16
	Col    uint16
	Xpixel uint16
	Ypixel uint16
}

In this module, we're converting the types between, so perhaps instead we should make it an alias (and deprecate the local type). Let me look at that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I recall now; for Windows, it's a different type, so we can make it an alias (but only on !windows)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. nevermind; field names are different 🤦

err = SetWinsize(tty.Fd(), &newSize)
if err != nil {
t.Fatal(err)
Expand All @@ -70,7 +71,7 @@ func TestSetWinsize(t *testing.T) {
if winSize == nil {
t.Fatal("winSize is nil")
}
newSize := Winsize{Width: 200, Height: 200, x: winSize.x, y: winSize.y}
newSize := Winsize{Width: 200, Height: 200}
err = SetWinsize(tty.Fd(), &newSize)
if err != nil {
t.Fatal(err)
Expand Down