mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-18 05:43:42 +00:00
The runner did not build on illumos, Solaris, NetBSD and OpenBSD: `internal/pkg/disk` called `unix.Statfs`, which `golang.org/x/sys/unix` lacks on illumos, Solaris and NetBSD (they have `statvfs(2)`) and exposes with `F_`-prefixed fields on OpenBSD. Each now has an implementation matching its syscall. FreeBSD and DragonFly report a negative available-block count once root writes into the reserved blocks. It wrapped to ~16 EiB free, so the disk health check and cache eviction saw plenty of space exactly when the disk was full. A shared helper clamps it to zero and absorbs the per-platform integer types. CI only built for the host, which let this and https://gitea.com/gitea/runner/pulls/1098 through. `make cross-check` vets code and tests on one target per distinct set of platform files, plus linux/arm for its 32-bit syscall fields, and runs as its own job in parallel to the others. It also surfaced docker-only tests lacking the docker build tag, which are fixed too. Assisted-by: Claude Code:claude-opus-5-5 Co-authored-by: rosekanari <[email protected]>
113 lines
4.7 KiB
Go
113 lines
4.7 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// Copyright 2020 The nektos/act Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
|
|
|
|
package container
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"testing/iotest"
|
|
|
|
"gitea.com/gitea/runner/act/common/logging"
|
|
"gitea.com/gitea/runner/act/common/logging/logtest"
|
|
|
|
"github.com/moby/moby/api/pkg/authconfig"
|
|
"github.com/moby/moby/api/types/registry"
|
|
assert "github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func init() {
|
|
logging.SetLevel(logging.LevelDebug)
|
|
}
|
|
|
|
func TestCleanImage(t *testing.T) {
|
|
tables := []struct {
|
|
imageIn string
|
|
imageOut string
|
|
}{
|
|
{"myhost.com/foo/bar", "myhost.com/foo/bar"},
|
|
{"localhost:8000/canonical/ubuntu", "localhost:8000/canonical/ubuntu"},
|
|
{"localhost/canonical/ubuntu:latest", "localhost/canonical/ubuntu:latest"},
|
|
{"localhost:8000/canonical/ubuntu:latest", "localhost:8000/canonical/ubuntu:latest"},
|
|
{"ubuntu", "docker.io/library/ubuntu"},
|
|
{"ubuntu:18.04", "docker.io/library/ubuntu:18.04"},
|
|
{"cibuilds/hugo:0.53", "docker.io/cibuilds/hugo:0.53"},
|
|
}
|
|
|
|
for _, table := range tables {
|
|
imageOut := cleanImage(t.Context(), table.imageIn)
|
|
assert.Equal(t, table.imageOut, imageOut)
|
|
}
|
|
}
|
|
|
|
func TestGetImagePullOptions(t *testing.T) {
|
|
ctx := t.Context()
|
|
|
|
t.Setenv("DOCKER_CONFIG", "/non-existent/docker")
|
|
|
|
options, err := getImagePullOptions(ctx, NewDockerPullExecutorInput{})
|
|
assert.NoError(t, err, "Failed to create ImagePullOptions") //nolint:testifylint // pre-existing issue from nektos/act
|
|
assert.Equal(t, "", options.RegistryAuth, "RegistryAuth should be empty if no username or password is set") //nolint:testifylint // pre-existing issue from nektos/act
|
|
|
|
options, err = getImagePullOptions(ctx, NewDockerPullExecutorInput{
|
|
Image: "",
|
|
Username: "username",
|
|
Password: "password",
|
|
})
|
|
assert.NoError(t, err, "Failed to create ImagePullOptions") //nolint:testifylint // pre-existing issue from nektos/act
|
|
assert.Equal(t, "eyJ1c2VybmFtZSI6InVzZXJuYW1lIiwicGFzc3dvcmQiOiJwYXNzd29yZCJ9", options.RegistryAuth, "Username and Password should be provided")
|
|
|
|
t.Setenv("DOCKER_CONFIG", "testdata/docker-pull-options")
|
|
|
|
options, err = getImagePullOptions(ctx, NewDockerPullExecutorInput{
|
|
Image: "nektos/act",
|
|
})
|
|
assert.NoError(t, err, "Failed to create ImagePullOptions") //nolint:testifylint // pre-existing issue from nektos/act
|
|
assert.Equal(t, "eyJ1c2VybmFtZSI6InVzZXJuYW1lIiwicGFzc3dvcmQiOiJwYXNzd29yZFxuIiwic2VydmVyYWRkcmVzcyI6Imh0dHBzOi8vaW5kZXguZG9ja2VyLmlvL3YxLyJ9", options.RegistryAuth, "RegistryAuth should be taken from local docker config")
|
|
|
|
dir := t.TempDir()
|
|
require.NoError(t, os.WriteFile(filepath.Join(dir, "config.json"), []byte(`{"auths":{"identity.example.com":{"identitytoken":"identity-token"},"registry.example.com":{"registrytoken":"registry-token"}}}`), 0o600))
|
|
t.Setenv("DOCKER_CONFIG", dir)
|
|
for host, want := range map[string]registry.AuthConfig{
|
|
"identity.example.com": {IdentityToken: "identity-token", ServerAddress: "identity.example.com"},
|
|
"registry.example.com": {RegistryToken: "registry-token", ServerAddress: "registry.example.com"},
|
|
} {
|
|
options, err := getImagePullOptions(ctx, NewDockerPullExecutorInput{Image: host + "/app"})
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, options.RegistryAuth, host)
|
|
got, err := authconfig.Decode(options.RegistryAuth)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, want, *got)
|
|
}
|
|
}
|
|
|
|
// A digest-pinned image is immutable, so its local copy is always current.
|
|
func TestIsPinnedImage(t *testing.T) {
|
|
assert.True(t, isPinnedImage("alpine@sha256:28bd5fe8b56d1bd048e5babf5b10710ebe0bae67db86916198a6eec434943f8b"))
|
|
assert.False(t, isPinnedImage("alpine:latest"))
|
|
}
|
|
|
|
// The pull path reports a failure the daemon sent mid-stream, so it must carry the reason
|
|
// whichever of the two shapes the daemon used.
|
|
func TestLogDockerResponseError(t *testing.T) {
|
|
logger, hook := logtest.NewLogger()
|
|
streamErr := func(line string) error {
|
|
return logDockerResponse(logger, io.NopCloser(strings.NewReader(line)), logger.Infof)
|
|
}
|
|
require.EqualError(t, streamErr(`{"error":"toomanyrequests: rate limit exceeded"}`), "toomanyrequests: rate limit exceeded")
|
|
require.EqualError(t, streamErr(`{"errorDetail":{"message":"unexpected EOF"}}`), "unexpected EOF")
|
|
require.NoError(t, streamErr(`{"status":"Downloading"}`))
|
|
require.NoError(t, streamErr(`{"stream":"`+strings.Repeat("x", 70000)+`"}`))
|
|
assert.Equal(t, logging.LevelInfo, hook.LastRecord().Level)
|
|
require.ErrorIs(t, logDockerResponse(logger, io.NopCloser(io.MultiReader(
|
|
strings.NewReader(`{"status":"Downloading"}`+"\n"), iotest.ErrReader(io.ErrUnexpectedEOF),
|
|
)), logger.Infof), io.ErrUnexpectedEOF)
|
|
}
|