mirror of
https://gitea.com/gitea/runner.git
synced 2026-08-23 04:17:45 +00:00
546eca312e
Remove inherited act APIs, configuration branches, and test seams that neither the daemon nor exec can reach. Constant-fold settings both entry points already enforce and consolidate duplicate runner paths. Major removals: - Unwired custom action-cache and local-repository-cache implementations. - Legacy matrix, platform, input, container-reuse, logging, Git remote, and action-replacement configuration paths. - Unused Docker socket, container network, tar-copy, and platform PTY wrappers. - Single-implementation filesystem, environment, runner, and expression abstractions. - Duplicated step-container, command-logging, credential, reusable-workflow, and execution paths. - Generated client mock boilerplate, obsolete fixtures, test-only seams, stale wrappers, and commented-out code. This removes 2844 net Go lines while retaining Gitea RPC, event, matrix, input, cache, artifact, action, reusable workflow, Docker, host, exec, and release behavior. Assisted by Codex (GPT-5). Reviewed-on: https://gitea.com/gitea/runner/pulls/1179 Reviewed-by: bircni <bircni@icloud.com> Co-authored-by: silverwind <me@silverwind.io>
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
|
|
|
package lookpath
|
|
|
|
import (
|
|
"errors"
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestLookPath2SearchesPathAndEmptyElement(t *testing.T) {
|
|
dir := t.TempDir()
|
|
exe := filepath.Join(dir, "tool")
|
|
if err := os.WriteFile(exe, []byte("#!/bin/sh\n"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
got, err := LookPath2("tool", map[string]string{"PATH": string(filepath.ListSeparator) + dir})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got != exe {
|
|
t.Fatalf("LookPath2() = %q, want %q", got, exe)
|
|
}
|
|
}
|
|
|
|
func TestLookPath2DirectPathDoesNotSearchPath(t *testing.T) {
|
|
dir := t.TempDir()
|
|
exe := filepath.Join(dir, "tool")
|
|
if err := os.WriteFile(exe, []byte("#!/bin/sh\n"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
got, err := LookPath2(exe, map[string]string{"PATH": ""})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got != exe {
|
|
t.Fatalf("LookPath2() = %q, want %q", got, exe)
|
|
}
|
|
}
|
|
|
|
func TestLookPath2ReportsPermissionAndNotFound(t *testing.T) {
|
|
dir := t.TempDir()
|
|
file := filepath.Join(dir, "not-executable")
|
|
if err := os.WriteFile(file, []byte("plain text"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
_, err := LookPath2(file, map[string]string{"PATH": dir})
|
|
var pathErr *Error
|
|
if !errors.As(err, &pathErr) || !errors.Is(pathErr.Err, fs.ErrPermission) {
|
|
t.Fatalf("LookPath2(non-executable) error = %v, want fs.ErrPermission wrapped in *Error", err)
|
|
}
|
|
if pathErr.Error() != fs.ErrPermission.Error() {
|
|
t.Fatalf("Error() = %q, want %q", pathErr.Error(), fs.ErrPermission.Error())
|
|
}
|
|
|
|
_, err = LookPath2("missing", map[string]string{"PATH": dir})
|
|
if !errors.As(err, &pathErr) || !errors.Is(pathErr.Err, ErrNotFound) {
|
|
t.Fatalf("LookPath2(missing) error = %v, want ErrNotFound wrapped in *Error", err)
|
|
}
|
|
}
|