Files
moby/integration/container/exec_linux_test.go
Sebastiaan van Stijn 4970333621 integration: remove // import comments
These comments were added to enforce using the correct import path for
our packages ("github.com/docker/docker", not "github.com/moby/moby").
However, when working in go module mode (not GOPATH / vendor), they have
no effect, so their impact is limited.

Remove these imports in preparation of migrating our code to become an
actual go module.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-30 15:59:14 +02:00

66 lines
1.6 KiB
Go

package container
import (
"strings"
"testing"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/integration/internal/container"
"gotest.tools/v3/assert"
"gotest.tools/v3/skip"
)
func TestExecConsoleSize(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.42"), "skip test from new feature")
ctx := setupTest(t)
apiClient := testEnv.APIClient()
cID := container.Run(ctx, t, apiClient, container.WithImage("busybox"))
result, err := container.Exec(ctx, apiClient, cID, []string{"stty", "size"},
func(ec *containertypes.ExecOptions) {
ec.Tty = true
ec.ConsoleSize = &[2]uint{57, 123}
},
)
assert.NilError(t, err)
assert.Equal(t, strings.TrimSpace(result.Stdout()), "57 123")
}
func TestFailedExecExitCode(t *testing.T) {
testCases := []struct {
doc string
command []string
expectedExitCode int
}{
{
doc: "executable not found",
command: []string{"nonexistent"},
expectedExitCode: 127,
},
{
doc: "executable cannot be invoked",
command: []string{"/etc"},
expectedExitCode: 126,
},
}
for _, tc := range testCases {
t.Run(tc.doc, func(t *testing.T) {
ctx := setupTest(t)
apiClient := testEnv.APIClient()
cID := container.Run(ctx, t, apiClient)
result, err := container.Exec(ctx, apiClient, cID, tc.command)
assert.NilError(t, err)
assert.Equal(t, result.ExitCode, tc.expectedExitCode)
})
}
}