Стабилизировать поиск Docker Desktop в тестах на Windows
This commit is contained in:
@@ -6,6 +6,9 @@ package testenv
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
@@ -22,6 +25,17 @@ const (
|
||||
ValkeyImage = "valkey/valkey:9.1.2-alpine3.24@sha256:48332870af354a799964c0012ae1194a0bf2bf894eb508f945810596dc2d8d11"
|
||||
)
|
||||
|
||||
// useDockerDesktopPipe names the Docker Desktop engine pipe explicitly on
|
||||
// Windows. Without DOCKER_HOST, testcontainers probes the pipe with a file
|
||||
// stat, which fails while the pipe is busy; with several test packages
|
||||
// starting containers at once that probe fails spuriously and the run panics.
|
||||
// Dialling the named host instead waits for a free pipe instance.
|
||||
var useDockerDesktopPipe = sync.OnceFunc(func() {
|
||||
if runtime.GOOS == "windows" && os.Getenv("DOCKER_HOST") == "" {
|
||||
_ = os.Setenv("DOCKER_HOST", "npipe:////./pipe/docker_engine")
|
||||
}
|
||||
})
|
||||
|
||||
// DB is a migrated PostgreSQL instance.
|
||||
type DB struct {
|
||||
Pool *pgxpool.Pool
|
||||
@@ -30,6 +44,7 @@ type DB struct {
|
||||
}
|
||||
|
||||
func StartPostgres(ctx context.Context) (*DB, error) {
|
||||
useDockerDesktopPipe()
|
||||
c, err := tcpostgres.Run(ctx, PostgresImage,
|
||||
tcpostgres.WithDatabase("messenger"),
|
||||
tcpostgres.WithUsername("messenger"),
|
||||
@@ -94,6 +109,7 @@ type KV struct {
|
||||
}
|
||||
|
||||
func StartValkey(ctx context.Context) (*KV, error) {
|
||||
useDockerDesktopPipe()
|
||||
c, err := tcvalkey.Run(ctx, ValkeyImage)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("start valkey: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user