beads/internal/testutil/testdoltcommon.go
Steven Syrek f0057c7828
ci: install dolt binary on Linux and macOS test runners (#3440)
* ci: install dolt binary on Linux and macOS test runners

Install dolt via the official install.sh on Linux and via Homebrew on
macOS so the main test job can exercise the ~24 test gates that
previously silently skipped on every PR when dolt was absent from PATH.

Matches the installation pattern already used by nightly.yml.
Docker-testcontainer gates (testDoltServerPort == 0 skips) remain
skipped — a known GitHub Actions hang documented in
scripts/repro-dolt-hang/INCIDENT-REPORT.md and nightly.yml:37-41
prevents enabling testcontainers here.

* test: require dolt binary under GITHUB_ACTIONS

Add testutil.RequireDoltBinary: skips when the dolt CLI is absent
locally but fails the test under GITHUB_ACTIONS. Replace bare
exec.LookPath("dolt") skip-gates with the helper so ~24 tests that
previously fell through silently in CI now run — and hard-fail if
the CI workflow ever drops the dolt install step.

tests/regression/regression_test.go uses an inline variant because
its gate lives in TestMain, and internal/remotecache/cache_test.go
duplicates the helper inline to avoid an import cycle
(testutil -> doltutil -> remotecache).
2026-04-24 06:58:40 -07:00

54 lines
1.6 KiB
Go

package testutil
import (
"fmt"
"net"
"os"
"os/exec"
"testing"
"time"
)
// DoltDockerImage is the Docker image used for Dolt test containers.
const DoltDockerImage = "dolthub/dolt-sql-server:1.86.0"
// RequireDoltBinary ensures the `dolt` CLI binary is available. The test is
// skipped locally when dolt is missing but fatally fails under GitHub Actions
// (GITHUB_ACTIONS=true). CI is expected to install dolt; a missing binary
// there means the workflow is broken, not that the test should be skipped.
func RequireDoltBinary(t *testing.T) {
t.Helper()
if _, err := exec.LookPath("dolt"); err != nil {
if os.Getenv("GITHUB_ACTIONS") == "true" {
t.Fatalf("dolt binary missing under GITHUB_ACTIONS: %v — the CI workflow must install dolt (see .github/workflows/ci.yml)", err)
}
t.Skipf("dolt binary not found: %v", err)
}
}
// FindFreePort finds an available TCP port by binding to :0.
func FindFreePort() (int, error) {
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return 0, err
}
port := l.Addr().(*net.TCPAddr).Port
_ = l.Close()
return port, nil
}
// WaitForServer polls until the server accepts TCP connections on the given port.
func WaitForServer(port int, timeout time.Duration) bool {
deadline := time.Now().Add(timeout)
addr := fmt.Sprintf("127.0.0.1:%d", port)
for time.Now().Before(deadline) {
// #nosec G704 -- addr is always loopback (127.0.0.1) with a test-selected local port.
conn, err := net.DialTimeout("tcp", addr, 500*time.Millisecond)
if err == nil {
_ = conn.Close()
return true
}
time.Sleep(200 * time.Millisecond)
}
return false
}