check / check (push) Canceled after 0s
Takes .golangci.yml, .dockerignore, .gitignore, .editorconfig, the workflow and REPO_POLICIES.md from sneak/prompts 0653579, with this repository's own entries after the shared content. Lint (golangci-lint v2.14.0) and test are Dockerfile phases that script/lint and script/test build alone with a new CACHEBUST value, keeping Go's and golangci-lint's caches; the image build depends on both. make fmt and make fmt-check also format the markdown with prettier, pinned in yarn.lock. The agent guidance moves to AGENTS.md. The Go code is fixed for what the new configuration finds, and the AS and prefix detail reads now return the rows' error after their loops. Model: opus-5-5
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package server_test
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"testing"
|
|
|
|
"git.eeqj.de/sneak/routewatch/internal/config"
|
|
"git.eeqj.de/sneak/routewatch/internal/logger"
|
|
"git.eeqj.de/sneak/routewatch/internal/metrics"
|
|
"git.eeqj.de/sneak/routewatch/internal/server"
|
|
"git.eeqj.de/sneak/routewatch/internal/streamer"
|
|
)
|
|
|
|
// TestStartFailsWhenPortIsHeld holds a port with a listener of its own and
|
|
// checks that Start on that port returns an error. Before the fix Start
|
|
// listened in a goroutine, only logged the failure and returned nil, so the
|
|
// daemon kept running without its web server.
|
|
func TestStartFailsWhenPortIsHeld(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var listenConfig net.ListenConfig
|
|
|
|
held, err := listenConfig.Listen(t.Context(), "tcp", ":0")
|
|
if err != nil {
|
|
t.Fatalf("failed to open the test listener: %v", err)
|
|
}
|
|
defer func() { _ = held.Close() }()
|
|
|
|
addr, ok := held.Addr().(*net.TCPAddr)
|
|
if !ok {
|
|
t.Fatalf("test listener address %v is not a TCP address", held.Addr())
|
|
}
|
|
|
|
port := addr.Port
|
|
log := logger.New()
|
|
s := server.New(nil, streamer.New(log, metrics.New()), log,
|
|
&config.Config{Port: port})
|
|
|
|
defer func() { _ = s.Stop(context.Background()) }()
|
|
|
|
err = s.Start(t.Context())
|
|
if err == nil {
|
|
t.Fatalf("Start returned nil while port %d was held by another listener",
|
|
port)
|
|
}
|
|
}
|