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
9 changes: 8 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Test
run: go test -v ./...
run: cd test && go test -v .
lint:
runs-on: ubuntu-latest
steps:
Expand All @@ -47,3 +47,10 @@ jobs:
-E gofmt \
-E misspell \
-E revive
- name: Lint tests
run: |
docker run --rm -v ./:/go/src/github.com/moby/term -w /go/src/github.com/moby/term/test \
golangci/golangci-lint:v1.62.2 golangci-lint run -v \
-E gofmt \
-E misspell \
-E revive
12 changes: 7 additions & 5 deletions ascii_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package term
package term_test

import (
"bytes"
"testing"

"github.com/moby/term"
)

func TestToBytes(t *testing.T) {
codes, err := ToBytes("ctrl-a,a")
codes, err := term.ToBytes("ctrl-a,a")
if err != nil {
t.Error(err)
}
Expand All @@ -15,12 +17,12 @@ func TestToBytes(t *testing.T) {
t.Errorf("expected: %+v, got: %+v", expected, codes)
}

_, err = ToBytes("shift-z")
_, err = term.ToBytes("shift-z")
if err == nil {
t.Error("expected and error")
}

codes, err = ToBytes("ctrl-@,ctrl-[,~,ctrl-o")
codes, err = term.ToBytes("ctrl-@,ctrl-[,~,ctrl-o")
if err != nil {
t.Error(err)
}
Expand All @@ -29,7 +31,7 @@ func TestToBytes(t *testing.T) {
t.Errorf("expected: %+v, got: %+v", expected, codes)
}

codes, err = ToBytes("DEL,+")
codes, err = term.ToBytes("DEL,+")
if err != nil {
t.Error(err)
}
Expand Down
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-20250102033503-faa5f7b0171c
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-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg=
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/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-20250102033503-faa5f7b0171c // 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-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg=
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/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=
82 changes: 42 additions & 40 deletions proxy_test.go → test/proxy_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package term
package test

import (
"bytes"
"testing"

"github.com/moby/term"
)

func TestEscapeProxyRead(t *testing.T) {
t.Run("no escape keys, keys [a]", func(t *testing.T) {
escapeKeys, _ := ToBytes("")
keys, _ := ToBytes("a")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
escapeKeys, _ := term.ToBytes("")
keys, _ := term.ToBytes("a")
reader := term.NewEscapeProxy(bytes.NewReader(keys), escapeKeys)

buf := make([]byte, len(keys))
nr, err := reader.Read(buf)
Expand All @@ -25,9 +27,9 @@ func TestEscapeProxyRead(t *testing.T) {
})

t.Run("no escape keys, keys [a,b,c]", func(t *testing.T) {
escapeKeys, _ := ToBytes("")
keys, _ := ToBytes("a,b,c")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
escapeKeys, _ := term.ToBytes("")
keys, _ := term.ToBytes("a,b,c")
reader := term.NewEscapeProxy(bytes.NewReader(keys), escapeKeys)

buf := make([]byte, len(keys))
nr, err := reader.Read(buf)
Expand All @@ -43,9 +45,9 @@ func TestEscapeProxyRead(t *testing.T) {
})

t.Run("no escape keys, no keys", func(t *testing.T) {
escapeKeys, _ := ToBytes("")
keys, _ := ToBytes("")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
escapeKeys, _ := term.ToBytes("")
keys, _ := term.ToBytes("")
reader := term.NewEscapeProxy(bytes.NewReader(keys), escapeKeys)

buf := make([]byte, len(keys))
nr, err := reader.Read(buf)
Expand All @@ -64,9 +66,9 @@ func TestEscapeProxyRead(t *testing.T) {
})

t.Run("DEL escape key, keys [a,b,c,+]", func(t *testing.T) {
escapeKeys, _ := ToBytes("DEL")
keys, _ := ToBytes("a,b,c,+")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
escapeKeys, _ := term.ToBytes("DEL")
keys, _ := term.ToBytes("a,b,c,+")
reader := term.NewEscapeProxy(bytes.NewReader(keys), escapeKeys)

buf := make([]byte, len(keys))
nr, err := reader.Read(buf)
Expand All @@ -82,9 +84,9 @@ func TestEscapeProxyRead(t *testing.T) {
})

t.Run("DEL escape key, no keys", func(t *testing.T) {
escapeKeys, _ := ToBytes("DEL")
keys, _ := ToBytes("")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
escapeKeys, _ := term.ToBytes("DEL")
keys, _ := term.ToBytes("")
reader := term.NewEscapeProxy(bytes.NewReader(keys), escapeKeys)

buf := make([]byte, len(keys))
nr, err := reader.Read(buf)
Expand All @@ -103,9 +105,9 @@ func TestEscapeProxyRead(t *testing.T) {
})

t.Run("ctrl-x,ctrl-@ escape key, keys [DEL]", func(t *testing.T) {
escapeKeys, _ := ToBytes("ctrl-x,ctrl-@")
keys, _ := ToBytes("DEL")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
escapeKeys, _ := term.ToBytes("ctrl-x,ctrl-@")
keys, _ := term.ToBytes("DEL")
reader := term.NewEscapeProxy(bytes.NewReader(keys), escapeKeys)

buf := make([]byte, len(keys))
nr, err := reader.Read(buf)
Expand All @@ -121,9 +123,9 @@ func TestEscapeProxyRead(t *testing.T) {
})

t.Run("ctrl-c escape key, keys [ctrl-c]", func(t *testing.T) {
escapeKeys, _ := ToBytes("ctrl-c")
keys, _ := ToBytes("ctrl-c")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
escapeKeys, _ := term.ToBytes("ctrl-c")
keys, _ := term.ToBytes("ctrl-c")
reader := term.NewEscapeProxy(bytes.NewReader(keys), escapeKeys)

buf := make([]byte, len(keys))
nr, err := reader.Read(buf)
Expand All @@ -139,9 +141,9 @@ func TestEscapeProxyRead(t *testing.T) {
})

t.Run("ctrl-c,ctrl-z escape key, keys [ctrl-c],[ctrl-z]", func(t *testing.T) {
escapeKeys, _ := ToBytes("ctrl-c,ctrl-z")
keys, _ := ToBytes("ctrl-c,ctrl-z")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
escapeKeys, _ := term.ToBytes("ctrl-c,ctrl-z")
keys, _ := term.ToBytes("ctrl-c,ctrl-z")
reader := term.NewEscapeProxy(bytes.NewReader(keys), escapeKeys)

buf := make([]byte, 1)
nr, err := reader.Read(buf)
Expand All @@ -168,9 +170,9 @@ func TestEscapeProxyRead(t *testing.T) {
})

t.Run("ctrl-c,ctrl-z escape key, keys [ctrl-c,ctrl-z]", func(t *testing.T) {
escapeKeys, _ := ToBytes("ctrl-c,ctrl-z")
keys, _ := ToBytes("ctrl-c,ctrl-z")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
escapeKeys, _ := term.ToBytes("ctrl-c,ctrl-z")
keys, _ := term.ToBytes("ctrl-c,ctrl-z")
reader := term.NewEscapeProxy(bytes.NewReader(keys), escapeKeys)

buf := make([]byte, 2)
nr, err := reader.Read(buf)
Expand All @@ -186,9 +188,9 @@ func TestEscapeProxyRead(t *testing.T) {
})

t.Run("ctrl-c,ctrl-z escape key, keys [ctrl-c],[DEL,+]", func(t *testing.T) {
escapeKeys, _ := ToBytes("ctrl-c,ctrl-z")
keys, _ := ToBytes("ctrl-c,DEL,+")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
escapeKeys, _ := term.ToBytes("ctrl-c,ctrl-z")
keys, _ := term.ToBytes("ctrl-c,DEL,+")
reader := term.NewEscapeProxy(bytes.NewReader(keys), escapeKeys)

buf := make([]byte, 1)
nr, err := reader.Read(buf)
Expand Down Expand Up @@ -216,9 +218,9 @@ func TestEscapeProxyRead(t *testing.T) {
})

t.Run("ctrl-c,ctrl-z escape key, keys [ctrl-c],[DEL]", func(t *testing.T) {
escapeKeys, _ := ToBytes("ctrl-c,ctrl-z")
keys, _ := ToBytes("ctrl-c,DEL")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
escapeKeys, _ := term.ToBytes("ctrl-c,ctrl-z")
keys, _ := term.ToBytes("ctrl-c,DEL")
reader := term.NewEscapeProxy(bytes.NewReader(keys), escapeKeys)

buf := make([]byte, 1)
nr, err := reader.Read(buf)
Expand Down Expand Up @@ -246,9 +248,9 @@ func TestEscapeProxyRead(t *testing.T) {
})

t.Run("a,b,c,d escape key, keys [a,b],[c,d]", func(t *testing.T) {
escapeKeys, _ := ToBytes("a,b,c,d")
keys, _ := ToBytes("a,b,c,d")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
escapeKeys, _ := term.ToBytes("a,b,c,d")
keys, _ := term.ToBytes("a,b,c,d")
reader := term.NewEscapeProxy(bytes.NewReader(keys), escapeKeys)

buf := make([]byte, 2)
nr, err := reader.Read(buf)
Expand Down Expand Up @@ -276,9 +278,9 @@ func TestEscapeProxyRead(t *testing.T) {
})

t.Run("ctrl-p,ctrl-q escape key, keys [ctrl-p],[a],[ctrl-p,ctrl-q]", func(t *testing.T) {
escapeKeys, _ := ToBytes("ctrl-p,ctrl-q")
keys, _ := ToBytes("ctrl-p,a,ctrl-p,ctrl-q")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
escapeKeys, _ := term.ToBytes("ctrl-p,ctrl-q")
keys, _ := term.ToBytes("ctrl-p,a,ctrl-p,ctrl-q")
reader := term.NewEscapeProxy(bytes.NewReader(keys), escapeKeys)

buf := make([]byte, 1)
nr, err := reader.Read(buf)
Expand Down
Loading
Loading