Files
act_runner/act/container/docker_ssh_test.go
silverwind 4158e05dae refactor: drop logrus and other direct dependencies (#1319)
After https://gitea.com/gitea/runner/pulls/1304, logrus stayed only to forward logs from docker/cli and moby/go-archive. The runner used a small part of those: volume parsing, the build context tar, the `ssh://` connection and registry credentials. Own code that matches them replaces them, so logrus leaves the module graph. docker/cli stays for its logrus-free `opts` and `connhelper/ssh` packages.

Other dependencies that the standard library or existing ones cover go too: mergo, httprouter (replaced by `http.ServeMux`), retry-go, go-isatty, go-selinux, container-device-interface, gotest.tools and go-cmp (replaced by testify). The binary shrinks by 5%.

Behaviour differences:

1. An unreadable file in a build context is skipped with a warning, where go-archive left a truncated tar.
2. Build contexts no longer carry `security.capability` xattrs.
3. The cache and artifact servers answer HEAD on GET routes, and no longer redirect trailing slashes or answer OPTIONS.

*Written by Claude.*

---------

Co-authored-by: bircni <bircni@icloud.com>
Reviewed-on: https://gitea.com/gitea/runner/pulls/1319
Reviewed-by: bircni <bircni@icloud.com>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: silverwind <2021+silverwind@noreply.gitea.com>
2026-10-18 18:57:08 +00:00

52 lines
1.6 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd))
package container
import (
"io"
"os/exec"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSSHArgs(t *testing.T) {
args, err := sshArgs("ssh://me@host:2222/run/user/1000/my docker.sock")
require.NoError(t, err)
assert.Equal(t, []string{"-l", "me", "-p", "2222", "-o", "ConnectTimeout=30", "-T", "--", "host", "docker '--host=unix:///run/user/1000/my docker.sock' system dial-stdio"}, args)
args, err = sshArgs("ssh://[::1]")
require.NoError(t, err)
assert.Equal(t, []string{"-o", "ConnectTimeout=30", "-T", "--", "::1", "docker system dial-stdio"}, args)
for _, invalid := range []string{"ssh://me:secret@host", "ssh://host?x=1", "ssh://host#x", "ssh://"} {
_, err := sshArgs(invalid)
assert.Error(t, err, invalid)
}
}
func TestDialCommandStreamsStdioAndReportsExit(t *testing.T) {
if _, err := exec.LookPath("sh"); err != nil {
t.Skip("needs a POSIX shell")
}
conn, err := dialCommand("sh", "-c", "cat")
require.NoError(t, err)
_, err = conn.Write([]byte("ping"))
require.NoError(t, err)
require.NoError(t, conn.(interface{ CloseWrite() error }).CloseWrite())
echoed, err := io.ReadAll(conn)
require.NoError(t, err)
assert.Equal(t, "ping", string(echoed))
require.NoError(t, conn.Close())
conn, err = dialCommand("sh", "-c", "exec 3<&0; cat <&3 >/dev/null & echo 'no route to host' >&2; exit 255")
require.NoError(t, err)
_, err = io.ReadAll(conn)
require.ErrorContains(t, err, "no route to host")
require.NoError(t, conn.Close())
}