From 3e712164604d515160ec2eff74e82198b2732c25 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 5 Nov 2022 16:50:59 +0100 Subject: [PATCH] switch to use blackbox testing, move tests to separate module This allows us to remove the test-dependencies from the module itself Signed-off-by: Sebastiaan van Stijn --- .github/workflows/test.yml | 7 ++++++- go.mod | 1 - go.sum | 2 -- test/go.mod | 15 +++++++++++++++ test/go.sum | 7 +++++++ proxy_test.go => test/proxy_test.go | 4 +++- term_test.go => test/term_test.go | 7 ++++--- 7 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 test/go.mod create mode 100644 test/go.sum rename proxy_test.go => test/proxy_test.go (99%) rename term_test.go => test/term_test.go (94%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 01bf9c3..4b70379 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: @@ -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 diff --git a/go.mod b/go.mod index 7850eda..2cdf0d9 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 505e5b0..1e41a03 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/test/go.mod b/test/go.mod new file mode 100644 index 0000000..91bf9fd --- /dev/null +++ b/test/go.mod @@ -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 => ../ diff --git a/test/go.sum b/test/go.sum new file mode 100644 index 0000000..505e5b0 --- /dev/null +++ b/test/go.sum @@ -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= diff --git a/proxy_test.go b/test/proxy_test.go similarity index 99% rename from proxy_test.go rename to test/proxy_test.go index 9adb91a..72f7cd6 100644 --- a/proxy_test.go +++ b/test/proxy_test.go @@ -1,8 +1,10 @@ -package term +package test import ( "bytes" "testing" + + . "github.com/moby/term" ) func TestEscapeProxyRead(t *testing.T) { diff --git a/term_test.go b/test/term_test.go similarity index 94% rename from term_test.go rename to test/term_test.go index 954f5f9..6295a6c 100644 --- a/term_test.go +++ b/test/term_test.go @@ -1,7 +1,7 @@ //go:build !windows // +build !windows -package term +package test import ( "os" @@ -9,6 +9,7 @@ import ( "testing" cpty "github.com/creack/pty" + . "github.com/moby/term" ) func newTTYForTest(t *testing.T) *os.File { @@ -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} err = SetWinsize(tty.Fd(), &newSize) if err != nil { t.Fatal(err) @@ -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)