pkg/compose: fix TestRunHook_ConsoleSize on macOS

containerd/console is broken on macOS, and panics; use creack/pty
instead for this test.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2026-03-29 23:02:54 +02:00 committed by Guillaume Lours
parent e742d09711
commit 5bbdd239df
2 changed files with 9 additions and 10 deletions

1
go.mod
View file

@ -13,6 +13,7 @@ require (
github.com/containerd/containerd/v2 v2.2.2
github.com/containerd/errdefs v1.0.0
github.com/containerd/platforms v1.0.0-rc.3
github.com/creack/pty v1.1.24
github.com/distribution/reference v0.6.0
github.com/docker/buildx v0.31.1
github.com/docker/cli v29.2.1+incompatible

View file

@ -22,7 +22,7 @@ import (
"testing"
"github.com/compose-spec/compose-go/v2/types"
"github.com/containerd/console"
"github.com/creack/pty"
"github.com/docker/cli/cli/streams"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/client"
@ -67,16 +67,14 @@ func TestRunHook_ConsoleSize(t *testing.T) {
// Create a PTY so GetTtySize() returns real non-zero dimensions,
// simulating an interactive terminal session.
pty, slavePath, err := console.NewPty()
ptmx, tty, err := pty.Open()
assert.NilError(t, err)
defer pty.Close() //nolint:errcheck
assert.NilError(t, pty.Resize(console.WinSize{Height: 24, Width: 80}))
slaveFile, err := os.OpenFile(slavePath, os.O_RDWR, 0)
assert.NilError(t, err)
defer slaveFile.Close() //nolint:errcheck
mockCli.EXPECT().Out().Return(streams.NewOut(slaveFile)).AnyTimes()
t.Cleanup(func() {
_ = ptmx.Close()
_ = tty.Close()
})
assert.NilError(t, pty.Setsize(ptmx, &pty.Winsize{Rows: 24, Cols: 80}))
mockCli.EXPECT().Out().Return(streams.NewOut(tty)).AnyTimes()
service := types.ServiceConfig{
Name: "test",